Skip to content

Responsive / overflowing tables - #1310

Merged
benjaminleonard merged 47 commits into
mainfrom
sticky-table-cols
Dec 14, 2022
Merged

benjaminleonard merged 47 commits into
mainfrom
sticky-table-cols

Conversation

@benjaminleonard

@benjaminleonard benjaminleonard commented Nov 23, 2022 •

Copy link
Copy Markdown
Contributor

Draft proof of concept:
CleanShot 2022-11-23 at 15 41 02

If this approach makes sense I can work it up into something a little neater. I'm doing most of this using css selectors, not sure if it's worth moving more of it into tailwind.

There's a hook that checks if the table overflows and applies the overflow indicator on both ends unless you are scrolled all the way in either direction.

It's also worth using elevation to better show that the first and last cell are sitting on top of the others.

Known issues:

  • Last row should not have a border-bottom as it overlaps with the corner radius
  • Assumes the last cell is a actions cell
  • Need to add a max width, to avoid long content extending the cells too much. Though I think this should be defined by cell and content type

@vercel

vercel Bot commented Nov 23, 2022 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
console-ui-storybook ✅ Ready (Inspect) Visit Preview Dec 14, 2022 at 6:10PM (UTC)

@benjaminleonard
benjaminleonard marked this pull request as ready for review December 5, 2022 11:50
Base automatically changed from update-design-system to main December 6, 2022 16:56
@benjaminleonard

Copy link
Copy Markdown
Contributor Author

One edge case I was unable to resolve is the lack of a border if a table is overflowing without a sticky final cell.

image

I can think of a potential solution, but it's fairly involved and has ramifications for selected rows. Based on the complexity, for now I think we can omit and see if it crops up.

Fixed the conflicts with main, and ready for review and merging whenever you find time to peruse through the PR.

@david-crespo

david-crespo commented Dec 12, 2022 •

Copy link
Copy Markdown
Collaborator

I think the no border problem is fine, I agree it's better to do nothing. If anything it subtly indicates there's more. Reviewing now.

I noticed two bugs just now, trying to investigate.

Bug 1: Gradient visible outside table in scroll bar area

The gradient one only appears when I reload the window at a size that makes the table already squished at page load time. If I reload the window with it wide and then shrink it down, the errant gradient does not appear (it also does not appear in the cells, where it is supposed to). I figured out this is due to the throttling and the fact that the event listener that toggles overflowing state is only on scroll, not on window resize. Adding it on resize gets the bug to show up on resize in addition to new pageload, though the throttling seems to introduce subtle bugs, for example if you resize the window slowly enough it seems to somehow get through without making the grading thing show up.

Firefox

Extra bit of border + black gradient is visible in the corner outside the table. It's very hard to see, I have to really squint.

image

Safari

Extra bit of border, but no black gradient thing.

image

Bug 2: extra bit of border

The pesky border belongs to the date cell. Was hoping for a z-index fix but it seems like that won't work. One hack would be to round the corner in question, but only when the table is .overflowing.

2022-12-12-cell-border-bug

@benjaminleonard

Copy link
Copy Markdown
Contributor Author

The simplest things are always the hardest...pushed fixes for both.

Comment thread app/hooks/use-is-overflow.ts Outdated

const { current } = ref
current.addEventListener('scroll', handleScroll)
return () => current.removeEventListener('scroll', handleScroll)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you add a resize listener too, you only get the gradient showing up if the table is already overflowing at pageload. Seems ok? When I try it, I don't see any jankiness — seems like throttle is doing its job.

    current.addEventListener('scroll', handleScroll)
    window.addEventListener('resize', handleScroll)
    return () => {
      current.removeEventListener('scroll', handleScroll)
      window.removeEventListener('resize', handleScroll)
    }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot!

@david-crespo david-crespo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Really difficult stuff. Good to merge pending reply/uptake on my resize event comment.

@benjaminleonard
benjaminleonard merged commit c154a3e into main Dec 14, 2022
@benjaminleonard
benjaminleonard deleted the sticky-table-cols branch December 14, 2022 18:14
david-crespo added a commit that referenced this pull request Nov 13, 2026
These came out of a scan I did of the console with Chrome's [Modern Web
Guidance](https://developer.chrome.com/docs/modern-web-guidance) skill,
which gives an agent a set of guides on current web platform features to
check a codebase against. Each change is its own commit.

- **Set `color-scheme` from the chosen theme.** Our `<meta
name="color-scheme" content="dark light">` tag tells the browser to pick
a scheme from the OS preference, and the theme toggle only set
`data-theme` on `<html>`. So browser-drawn UI (native scrollbars, date
pickers, autofill) followed the OS and not the chosen theme. With a
light OS and the default dark theme, the side modal's scrollbar was
drawn for a light page: a white track with classic scrollbars, or a dark
thumb on the dark background with macOS overlay scrollbars. Now
`data-theme` also sets the `color-scheme` CSS property.
- **Add `autoComplete="current-password"` to the login form's password
field.** Password managers use it to tell a login form from a signup
form. The username field already had `autoComplete="username"`.
- **Drive table scroll shadows with a CSS scroll timeline.** The shadows
on the sticky first column and the actions column were toggled by a
`useIsOverflow` hook that listened to scroll and resize events,
throttled with `lodash.throttle`. They are now an animation tied to the
table's horizontal scroll position with `animation-timeline:
scroll(nearest inline)`, so the hook and `lodash.throttle` are gone. The
shadow fades in over the first 2rem of scroll instead of snapping on.
Scroll timelines need Chrome 115 (July 2023), Safari 26 (September 2025)
or Firefox 159 (October 2026), which is only two weeks old. The rules
are inside `@supports`, so older Firefox and Safari lose the shadows and
nothing else. I think that is fine: the scrollbar is still always
visible. The shadows were also very hard to see, especially in the dark
theme, so I made them stronger.
- **Use a theme color for the table scrollbar thumb.** The SimpleBar
thumb was hard-coded white at 28% opacity, which is nearly invisible in
the light theme. It is now `--content-quaternary`, and
`--content-tertiary` on hover.
- **Drop the `uuid` package.** This one is not from the scan. The mock
API now uses `crypto.randomUUID()`, which needs a secure context (HTTPS
or localhost), as MSW's service worker already does. Toast IDs were the
only use in the app itself, and I replaced those with a simple counter
because the console is occasionally served over plain HTTP, e.g., from
Nexus on a remote dev machine. `uuid.validate` in the mock API is
replaced by a regex that matches any UUID version, [as Nexus
does](https://github.com/oxidecomputer/omicron/blob/aa28c9c/common/src/api/external/mod.rs#L357-L367).

I also tried replacing SimpleBar with native `scrollbar-color` and
`scrollbar-width`, which one of the guides recommends, and dropped it.
SimpleBar was added in #1310 to keep the table's horizontal scrollbar
visible so it's clear the table overflows. Firefox on macOS can't do
that natively: overlay scrollbars hide until you scroll.

I checked the shadows and the scrollbar thumb in Chromium in both
themes, and that Firefox 151, which has no scroll timelines, shows no
shadows.

### `color-scheme`: light OS, dark theme

Before, the overlay scrollbar thumb on the right is dark on a dark
background.

<img width="2144" height="1298" alt="color-scheme"
src="https://github.com/user-attachments/assets/a7ca8062-c0e1-4f59-aed9-06d1ed7b9589"
/>

### Scroll shadows

<img width="1488" height="1336" alt="shadows"
src="https://github.com/user-attachments/assets/addb6073-ae4e-412b-bc46-a0577238d79f"
/>

### Table scrollbar thumb in light theme

<img width="1488" height="804" alt="thumb"
src="https://github.com/user-attachments/assets/44fb4cd2-6db9-4a3a-9628-6bcd0efe4047"
/>

This branch was successfully deployed

1 active deployment
Preview — bb6523c1 Deployed Dec 14, 2022 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants