From 1d4f20cf4252746f2d549adcf8b7289f708f637f Mon Sep 17 00:00:00 2001 From: benjaminleonard Date: Tue, 24 Nov 2026 11:07:58 +0000 Subject: [PATCH 1/4] Table frame refactor: closed border on overflow, native scrollbar The table's outer border used to be painted by the edge cells, with ::after overlays faking the rounded corners. When a table without a sticky actions column overflowed, its right edge scrolled away and the border was left open. - Draw the border with a frame element pinned to the visible part of the scroller (sticky, sized with 100cqw), so it stays closed at any scroll position. Edge cells keep transparent 1px borders so column widths match. - Replace simplebar-react with a native scrollbar styled to match (::-webkit-scrollbar, scrollbar-color in Firefox), keeping 16px below the table whether or not it overflows. - Remove the corner overlays and !important overrides from table.css. - Draw row selection as one outline per row, merging adjacent rows with :has(), instead of box-shadow hacks on every cell. Removes the cloneElement pass in Table.Body. - Fade sticky column shadows in and out with scroll-state container queries where supported, falling back to the scroll-driven animations. Tables with no actions column get a matching shadow at the right edge while there's more to scroll to. - Table's className now applies to the outer box, so sizing classes like max-w-lg size the frame too. - Add narrow-viewport overflow cases to the visual regression suite. Not pixel-identical to before: two old quirks (no left border on the bottom-left cell, -m-px on last-column cells) skewed column widths, so some columns shift by a fraction of a pixel, and two-column tables are 1px taller. --- app/ui/lib/CardBlock.tsx | 2 +- app/ui/lib/Table.tsx | 54 ++- app/ui/styles/components/table.css | 537 +++++++++++++---------------- app/ui/styles/index.css | 1 - package-lock.json | 36 +- package.json | 1 - test/visual/regression.e2e.ts | 28 ++ 7 files changed, 298 insertions(+), 361 deletions(-) diff --git a/app/ui/lib/CardBlock.tsx b/app/ui/lib/CardBlock.tsx index 71cfa1c122..6abdb2682e 100644 --- a/app/ui/lib/CardBlock.tsx +++ b/app/ui/lib/CardBlock.tsx @@ -60,7 +60,7 @@ CardBlock.Header = ({ title, description, children, titleId }: HeaderProps) => ( ) // If there's a table with a scrollbar we want to avoid it adding extra padding at the bottom -CardBlock.Body = classed.div`px-5 py-4 space-y-4 [&>*:last-child[data-simplebar]]:pb-3 [&>*:last-child[data-simplebar]]:-mb-3` +CardBlock.Body = classed.div`px-5 py-4 space-y-4 [&>.ox-table-scroller:last-child]:pb-1 [&>.ox-table-scroller:last-child]:-mb-3` CardBlock.Footer = classed.footer`flex items-center justify-between px-5 pt-4 text-secondary` diff --git a/app/ui/lib/Table.tsx b/app/ui/lib/Table.tsx index 1c5f2690cf..c7373ce2f2 100644 --- a/app/ui/lib/Table.tsx +++ b/app/ui/lib/Table.tsx @@ -6,20 +6,29 @@ * Copyright Oxide Computer Company */ import cn from 'classnames' -import React, { type JSX, type ReactElement } from 'react' -import SimpleBar from 'simplebar-react' +import type { JSX } from 'react' import { classed } from '~/util/classed' export type TableProps = JSX.IntrinsicElements['table'] +/** + * The outer border is drawn by a frame pinned to the visible part of the + * scroller rather than by the edge cells, so it stays closed on every side + * however far the table is scrolled. See `table.css`. + * + * `className` goes on the scroller, the outermost box, so sizing classes like + * `max-w-lg` size the frame along with the table. + */ export function Table({ className, ...props }: TableProps) { return ( - - - + // pb-2 + the 8px scrollbar is 16px below the table. It's a utility rather + // than in table.css so wrappers like CardBlock.Body can override it. +
+
+
+
+
+ ) } @@ -38,7 +47,7 @@ Table.HeadCell = ({ className, children, ...props }: TableHeadCellProps) => ( ) -type RowElt = ReactElement - export type TableBodyProps = JSX.IntrinsicElements['tbody'] -Table.Body = ({ className, children, ...props }: TableBodyProps) => { - const rows = React.Children.toArray(children).map((c, i, siblings) => { - const child = c as RowElt - const beforeSelected = (siblings[i - 1] as RowElt | undefined)?.props.selected - const afterSelected = (siblings[i + 1] as RowElt | undefined)?.props.selected - const className = - child.props.selected && (beforeSelected || afterSelected) - ? cn( - child.props.className, - 'multi-selection', - !beforeSelected && 'selection-start', - !afterSelected && 'selection-end' - ) - : child.props.className - return React.cloneElement(child, { ...child.props, className }) - }) - return ( - - {rows} - - ) -} +Table.Body = (props: TableBodyProps) => export type TableCellProps = JSX.IntrinsicElements['td'] & { height?: 'small' | 'large' } Table.Cell = ({ height = 'small', className, children, ...props }: TableCellProps) => (
@@ -55,36 +64,13 @@ Table.Row = ({ className, selected, ...props }: TableRowProps) => (
div { - border-bottom-width: 0px; +/* Chrome ignores the ::-webkit-scrollbar rules above if these are set, so + only apply them where those rules aren't supported (Firefox) */ +@supports not selector(::-webkit-scrollbar) { + .ox-table-scroller { + scrollbar-width: thin; + scrollbar-color: var(--content-quaternary) transparent; + } + /* Firefox's overlay scrollbars take no space and are drawn over the bottom + of the scroller's padding, right against the table. A little extra + space keeps them off it. Not the full 8px Chrome reserves: classic + scrollbars ("Always show scrollbars") reserve their own space on top of + this, and CSS can't tell the two apart. On the grid rather than the + scroller so CardBlock's padding override still applies. */ + .ox-table-grid { + padding-bottom: 4px; } +} + +.ox-table-grid { + display: grid; + /* matches how a w-full table sizes itself: fill the scroller, or grow to + the table's min-content width and overflow */ + width: fit-content; + min-width: 100%; +} + +.ox-table-grid > * { + grid-area: 1 / 1; +} + +.ox-table-frame { + position: sticky; + left: 0; + justify-self: start; + width: 100cqw; + border: 1px solid var(--stroke-default); + border-radius: var(--table-border-radius); + pointer-events: none; + /* above the sticky columns, below the selection outline */ + z-index: 20; +} + +table.ox-table { + border-collapse: separate; + border-spacing: 0; & th, & td { @@ -41,346 +111,235 @@ table.ox-table { @apply text-default; } - /* - Adds padding to all cells except from - the action cells since they are a fixed width - */ - & td:not(.action-col) > div { - @apply pr-8; + /* Header rows after the first don't need a top border */ + & thead tr:not(:first-child) th { + @apply border-t-0; } - /* First column is sticky */ - & th:first-of-type, - & td:first-of-type { - @apply bg-default sticky left-0 z-10; + /* Space under the frame */ + & :is(td, th):first-child { + border-left: 1px solid transparent; } - - /* Border between sticky first column and second column: - first column owns the right border, second column drops its left border */ - & td:first-of-type > div, - & th:first-of-type > div { - @apply border-r; + /* The actions header is the exception: its 1px of right padding already + makes the column 41px, the same as the body cells' 40px plus border */ + & td:last-child, + & th:last-child:not(.action-col) { + border-right: 1px solid transparent; } - & td:nth-of-type(2) > div, - & th:nth-of-type(2) > div { - @apply border-l-0; + & tbody tr:last-child td { + border-bottom: 1px solid transparent; } - /* - Last column is sticky if it - is a more actions cell - */ - & th.action-col, - & td.action-col { - @apply bg-default sticky right-0 w-10; - } - & th.action-col { - @apply bg-secondary; - } - & th.action-col > div, - & td.action-col > div { - @apply !m-0 w-10 !p-0; + /* The last row's bottom edge is the frame */ + & tbody tr:last-child td > div { + border-bottom-width: 0px; } - & td:last-of-type > div { - @apply -m-px; + /* Round the backgrounds of the bottom corner cells to sit inside the + frame's curve. Only needed when the table isn't scrolled; the visible + edge mid-scroll is an ordinary cell. */ + & tbody tr:last-child td:first-child { + border-bottom-left-radius: calc(var(--table-border-radius) - 1px); } - - /* - Highlight when hovering over the action-col cell - */ - & td.action-col:hover > div { - @apply bg-raise; + & tbody tr:last-child td:last-child { + border-bottom-right-radius: calc(var(--table-border-radius) - 1px); } /* - We hide the default border and background on the sticky - cells. This is to stop anything underneath it showing through - at the corner. By leaving the cell square, and instead applying - it to the div child which has a rounded-md corner we cover what's - below with a background colour and still keep the styling + Adds padding to all cells except from + the action cells since they are a fixed width */ - & tr:last-of-type td:last-of-type.action-col { - @apply border-r-0 border-b-0 pr-px; - } - - & tr:last-of-type td:last-of-type.action-col > div { - border-bottom-right-radius: var(--table-border-radius); - } - - & tr:last-of-type td:first-of-type > div { - border-bottom-left-radius: var(--table-border-radius); - } - - & tr:last-of-type td:last-of-type.action-col:after { - border-bottom-right-radius: var(--table-border-radius); - @apply border-default pointer-events-none absolute top-0 right-0 bottom-0 left-0 z-0 border-r border-b content-['']; - } - - & tr:last-of-type td:last-of-type:not(.action-col) { - border-bottom-right-radius: var(--table-border-radius); - } - - & tr:last-of-type td:first-of-type { - @apply !border-b-0 !border-l-0; + & td:not(.action-col) > div { + @apply pr-8; } - & tr:last-of-type td:first-of-type:after { - border-bottom-left-radius: var(--table-border-radius); - @apply border-default pointer-events-none absolute top-0 right-0 bottom-0 left-0 border-b border-l content-['']; + /* First column is sticky */ + & th:first-child, + & td:first-child { + @apply sticky left-0 z-10; } - - & th:first-of-type { - @apply !bg-default border-t-0 border-l-0; + & td:first-child { + @apply bg-default; } - & th:first-of-type > div { - border-top-left-radius: var(--table-border-radius); - @apply bg-secondary w-[calc(100%+1px)]; + /* Border between sticky first column and second column: + first column owns the right border, second column drops its left border */ + & td:first-child > div, + & th:first-child > div { + @apply border-r; } - - & th:first-of-type:after { - border-top-left-radius: var(--table-border-radius); - @apply border-default pointer-events-none absolute top-0 right-0 bottom-0 left-0 border-t border-l content-['']; + & td:nth-child(2) > div, + & th:nth-child(2) > div { + @apply border-l-0; } - - & th:last-of-type.action-col { - @apply !bg-default !border-t-0 !border-r-0; + /* header cells have 1px of right padding (which affects column widths), so + stretch the first one's div back over it to line its border up */ + & th:first-child > div { + @apply w-[calc(100%+1px)]; } - & th:last-of-type.action-col > div { - border-top-right-radius: var(--table-border-radius); - @apply bg-secondary; + /* Last column is sticky if it is a more actions cell */ + & .action-col { + @apply sticky right-0 w-10; } - - & th:last-of-type.action-col:after { - border-top-right-radius: var(--table-border-radius); - @apply border-default pointer-events-none absolute top-0 right-0 bottom-0 left-0 border-t border-r content-['']; + & td.action-col { + @apply bg-default; } - - & th:last-of-type:not(.action-col) { - border-top-right-radius: var(--table-border-radius); - @apply border-r; + & .action-col > div { + @apply m-0 w-10 p-0; } - & tr:not(:first-of-type) th { - @apply border-t-0; + /* Highlight when hovering over the action-col cell */ + & td.action-col:hover > div { + @apply bg-raise; } - & tr:not(:first-of-type) th:after, - & tr:not(:first-of-type) th:last-of-type:not(.action-col) { + /* + Selection outline. One box per selected row, drawn above the frame so it + replaces the frame's edge. Adjacent selected rows merge into one box by + dropping the borders and radii where they meet. + */ + & tbody tr { + position: relative; + } + & tbody tr.is-selected::after { + content: ''; + position: absolute; + /* cover the row above's bottom divider. The sides and bottom already line + up with the frame because the edge cells' transparent borders sit + under it. */ + inset: -1px 0 0; + border: 1px solid var(--stroke-accent); + border-radius: 0.1875rem; + pointer-events: none; + z-index: 30; + } + & tbody tr.is-selected:has(+ tr.is-selected)::after { + border-bottom-width: 0; + border-bottom-left-radius: 0; + border-bottom-right-radius: 0; + } + & tbody tr.is-selected + tr.is-selected::after { + top: 0; + border-top-width: 0; border-top-left-radius: 0; border-top-right-radius: 0; - @apply border-t-0; - } - - /* === Begin table selection styles === */ - - /** - * Our table selection styles dictate complex behaviors like rounded-md selection corners, - * grouped selections, and seemless border overlap. To acheive this, `box-shadow` properties - * are used for selection border styles. To make this effect possible, special classes were - * added to the table. Those classes are: - * - * - `.is-selected` -- present on every selected row - * - `.multi-selection` -- present on every selected row that has at least one direct sibling which is also selected - * - `.selection-start` -- the first selected item in a `multi-selection` group - * - `.selection-end` -- the last selected item in a `multi-selection` group - */ - - /* Left-most cell of a single selection */ - & .is-selected:not(.multi-selection) td:first-child > div { - border-top-left-radius: 0.1875rem; - border-bottom-left-radius: 0.1875rem; - box-shadow: - -1px -1px var(--stroke-accent), - -1px 1px var(--stroke-accent); - } - - /* Right-most cell of a single selection */ - & .is-selected:not(.multi-selection) td:last-child > div { - border-top-right-radius: 0.1875rem; - box-shadow: - 1px -1px var(--stroke-accent), - 1px 1px var(--stroke-accent); - border-bottom-right-radius: 0.1875rem; - } - - /* All cells of a single selection */ - & .is-selected:not(.multi-selection) td > div { - box-shadow: - 0px 1px var(--stroke-accent), - 0px -1px var(--stroke-accent); - margin-top: -2px; - border-bottom: 0; - height: calc(100% + 1px); - } - - & .is-selected:not(.multi-selection):last-of-type td > div { - margin-top: -1px; - height: calc(100% + 3px); - } - - /* Defines the top border of a selection */ - & .is-selected td > div { - box-shadow: 0px -1px var(--stroke-accent); - } - - /* Ensures subsequent, interior selected rows don't have a top border */ - & .multi-selection:not(.selection-start):not(.selection-end) td > div { - box-shadow: none; - } - - /* Adds the selected border for the top left corner of a selection */ - & .selection-start td:first-child > div { - border-top-left-radius: 0.1875rem; - box-shadow: -1px -1px var(--stroke-accent); - margin-right: -3px; - } - - /* Ensures subsequent, interior selections have side borders */ - & .multi-selection:not(.selection-start):not(.selection-end) td:first-child > div { - box-shadow: -1px 0px var(--stroke-accent); } +} - & .multi-selection:not(.selection-start):not(.selection-end) td:last-child > div { - box-shadow: 1px 0px var(--stroke-accent); - } +/* +Edge shadows: on a sticky column while content is scrolled under it, and on +the frame's right edge for tables with no actions column to cast one. + +Where scroll-state container queries are supported, each shadow is on while +the scroller can scroll further toward its edge, and fades in and out with a +transition. Elsewhere they fall back to scroll-driven animations that track +the first and last 2rem of scroll. With neither, there are no shadows. When +the table fits, nothing can scroll and no shadow shows either way. +*/ +.ox-table-scroller { + --sticky-col-shadow: light-dark(oklch(0 0 0 / 0.075), oklch(0 0 0 / 0.3)); + --edge-shadow-transition: 250ms ease-out; +} - /* Fills gaps between borders that show up in Safari and Chrome on OSX */ - & .multi-selection:not(.selection-end) td:first-child, - & .multi-selection:not(.selection-end) td:last-child { - @apply border-accent; - } +/* Keep the cell shadows from spilling above and below the cell. Safe to leave + on: nothing in these cells draws outside them (selection is on the row). */ +.ox-table :is(td, th):first-child { + clip-path: inset(0 -40px 0 0); +} +.ox-table .action-col { + clip-path: inset(0 0 0 -40px); +} - /* Adds the selected border for the top right corner of a selection */ - & .selection-start td:last-child > div { - border-top-right-radius: 0.1875rem; - box-shadow: 1px -1px var(--stroke-accent); - } - /* Ensures the top right border and the cell next to it have their box-shadows overlap */ - & .selection-start td:nth-last-child(2) > div { - margin-right: -3px; +/* +The frame's shadow is cast by a box sitting just outside its right edge, with +the same box-shadow as the sticky columns, so the two match exactly. The +frame clips away the box itself and the shadow's ends, leaving just what +falls inside its border, rounded at the corners. +*/ +.ox-table-grid:not(:has(.action-col)) > .ox-table-frame { + /* clip, not hidden: hidden would make the frame a scroll container, and + the fallback's scroll(nearest) timeline would track it instead */ + overflow: clip; + + &::after { + content: ''; + position: absolute; + left: 100%; + width: 1rem; + /* overhang top and bottom so the blur tapers outside the frame, keeping + the shadow full strength down the whole edge */ + top: -1rem; + bottom: -1rem; + box-shadow: -6px 0 8px -2px var(--sticky-col-shadow); + opacity: 0; } +} - & .selection-end td > div { - box-shadow: 0px 1px var(--stroke-accent); +@supports (container-type: scroll-state) { + .ox-table-scroller { + container-type: inline-size scroll-state; } - & .selection-end td > div { - border-bottom: 0; - height: calc(100% + 3px); - margin-top: -5px; - padding-top: 3px; + .ox-table :is(td, th):first-child, + .ox-table .action-col { + transition: box-shadow var(--edge-shadow-transition); } - - /* Account for layout shift at the bottom of the table as best we can */ - & .selection-end:last-of-type td > div { - margin-top: -4px; - height: calc(100% + 8px); - margin-bottom: -1px; + .ox-table-frame::after { + transition: opacity var(--edge-shadow-transition); } - /* Correct for firefox's wider variation in table border spacing */ - @supports (-moz-appearance: none) { - & .selection-end:last-of-type td > div { - margin-top: -2px; - height: calc(100% + 4px); - padding-top: 2px; - padding-bottom: 1px; + @container scroll-state(scrollable: left) { + .ox-table :is(td, th):first-child { + box-shadow: 6px 0 8px -2px var(--sticky-col-shadow); } } - - /* Adds the selected border for the bottom left corner of a selection */ - & .selection-end td:first-child > div { - border-bottom-left-radius: 0.1875rem; - box-shadow: -1px 1px var(--stroke-accent); - margin-right: -4px; - } - - & .selection-end td:last-child > div { - border-bottom-right-radius: 0.1875rem; - box-shadow: 1px 1px var(--stroke-accent); - } - - & .selection-end td:last-child > div, - & .is-selected:not(.multi-selection) td:last-child > div { - @apply before:border-accent-tertiary relative -ml-0.5 border-l-0 before:absolute before:top-0 before:bottom-1 before:left-0.5 before:block before:h-full before:border-l; - /* Avoid layout shift caused by the border being inline with the content */ - padding-left: calc(1rem - 1px); + @container scroll-state(scrollable: right) { + .ox-table .action-col { + box-shadow: -6px 0 8px -2px var(--sticky-col-shadow); + } + /* same selector as the base rule so it wins on specificity */ + .ox-table-grid:not(:has(.action-col)) > .ox-table-frame::after { + opacity: 1; + } } - - /* === End table selection styles === */ -} - -/* -Drop shadow on a sticky column when content is scrolled under it, driven by -the table's horizontal scroll position. When the table fits, the timeline is -inactive and neither shadow shows. The clip-path stops the shadow spilling -above and below the cell; it's only on while there's a shadow so it doesn't -clip the selected-row border. -*/ -.ox-table { - --sticky-col-shadow: light-dark(oklch(0 0 0 / 0.075), oklch(0 0 0 / 0.6)); } -/* Without the guard, browsers lacking scroll timelines would run the animation - with a 0s duration and hold the start shadow's end state on every table */ -@supports (animation-timeline: scroll()) { - .ox-table :is(td, th):first-of-type { +/* Without the animation-timeline guard, browsers lacking scroll timelines + would run these with a 0s duration and hold the end state on every table */ +@supports (animation-timeline: scroll()) and (not (container-type: scroll-state)) { + .ox-table :is(td, th):first-child { animation: sticky-start-shadow linear both; animation-timeline: scroll(nearest inline); animation-range: 0 2rem; } - .ox-table :is(td, th):last-of-type.action-col { + .ox-table .action-col { animation: sticky-end-shadow linear both; animation-timeline: scroll(nearest inline); animation-range: calc(100% - 2rem) 100%; } + .ox-table-frame::after { + animation: table-end-fade linear both; + animation-timeline: scroll(nearest inline); + animation-range: calc(100% - 2rem) 100%; + } } @keyframes sticky-start-shadow { - from { - clip-path: none; - } - 1% { - clip-path: inset(0 -40px 0 0); - } to { - clip-path: inset(0 -40px 0 0); box-shadow: 6px 0 8px -2px var(--sticky-col-shadow); } } @keyframes sticky-end-shadow { from { - clip-path: inset(0 0 0 -40px); box-shadow: -6px 0 8px -2px var(--sticky-col-shadow); } - 99% { - clip-path: inset(0 0 0 -40px); +} +@keyframes table-end-fade { + from { + opacity: 1; } to { - clip-path: none; + opacity: 0; } } - -.simplebar-scrollbar { - top: 0 !important; - height: 8px !important; -} - -.simplebar-scrollbar:before { - background-color: var(--content-quaternary); - left: 0 !important; - top: 0 !important; - right: 0 !important; - border-radius: 8px !important; -} - -.simplebar-hover.simplebar-scrollbar:before { - background-color: var(--content-tertiary); -} - -.simplebar-track.simplebar-horizontal { - height: 8px; -} diff --git a/app/ui/styles/index.css b/app/ui/styles/index.css index 846fcd4140..ba380df4a5 100644 --- a/app/ui/styles/index.css +++ b/app/ui/styles/index.css @@ -31,7 +31,6 @@ @import '@oxide/design-system/styles/dark.css'; @import '@oxide/design-system/styles/light.css'; @import '@oxide/design-system/styles/preflight.css' layer(base); -@import 'simplebar-react/dist/simplebar.min.css' layer(components); @import 'uplot/dist/uPlot.min.css' layer(components); @import '@oxide/design-system/styles/red.css'; diff --git a/package-lock.json b/package-lock.json index c5b44255b3..2fa0e73fa6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -47,7 +47,6 @@ "remeda": "^2.30.0", "semver": "^7.7.3", "shiki": "^4.5.0", - "simplebar-react": "^3.2.6", "ts-pattern": "^5.8.0", "uplot": "^1.6.32", "uplot-react": "^1.2.4", @@ -3723,17 +3722,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@types/lodash": { - "version": "4.17.7", - "license": "MIT" - }, - "node_modules/@types/lodash-es": { - "version": "4.17.12", - "license": "MIT", - "dependencies": { - "@types/lodash": "*" - } - }, "node_modules/@types/md5": { "version": "2.3.5", "dev": true, @@ -5968,10 +5956,7 @@ }, "node_modules/lodash": { "version": "4.18.1", - "license": "MIT" - }, - "node_modules/lodash-es": { - "version": "4.18.1", + "dev": true, "license": "MIT" }, "node_modules/lru-cache": { @@ -7156,25 +7141,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/simplebar-core": { - "version": "1.2.6", - "license": "MIT", - "dependencies": { - "@types/lodash-es": "^4.17.6", - "lodash": "^4.17.21", - "lodash-es": "^4.17.21" - } - }, - "node_modules/simplebar-react": { - "version": "3.2.6", - "license": "MIT", - "dependencies": { - "simplebar-core": "^1.2.6" - }, - "peerDependencies": { - "react": ">=16.8.0" - } - }, "node_modules/sirv": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/sirv/-/sirv-3.0.2.tgz", diff --git a/package.json b/package.json index 7ebefde28a..136628d6c7 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,6 @@ "remeda": "^2.30.0", "semver": "^7.7.3", "shiki": "^4.5.0", - "simplebar-react": "^3.2.6", "ts-pattern": "^5.8.0", "uplot": "^1.6.32", "uplot-react": "^1.2.4", diff --git a/test/visual/regression.e2e.ts b/test/visual/regression.e2e.ts index aa25774140..8c9ddf6d9b 100644 --- a/test/visual/regression.e2e.ts +++ b/test/visual/regression.e2e.ts @@ -259,6 +259,34 @@ test.describe('Visual Regression', { tag: '@visual' }, () => { }) }) + // Tables only overflow horizontally at narrow widths, which none of the + // standard pages hit. Capture each at its scroll start, middle, and end so + // the frame edges and sticky column shadows are covered. + const overflowTables = [ + { name: 'inventory sleds', url: '/system/inventory/sleds', heading: 'Inventory' }, + { name: 'instances list', url: `${p}/instances`, heading: 'Instances' }, + ] + for (const { name, url, heading } of overflowTables) { + test(`${name} overflow`, async ({ page }) => { + await page.setViewportSize({ width: 800, height: 900 }) + await page.goto(url, { waitUntil: 'networkidle' }) + await expect(page.getByRole('heading', { name: heading })).toBeVisible() + const table = page.getByRole('table').first() + const slug = name.replaceAll(' ', '-') + for (const position of ['start', 'middle', 'end'] as const) { + // find the scroller by behavior so this works whatever element scrolls + await table.evaluate((el, position) => { + let node = el.parentElement + while (node && node.scrollWidth <= node.clientWidth) node = node.parentElement + if (!node) return + const max = node.scrollWidth - node.clientWidth + node.scrollLeft = position === 'start' ? 0 : position === 'middle' ? max / 2 : max + }, position) + await expect(page).toHaveScreenshot(`${slug}-overflow-${position}.png`) + } + }) + } + for (const [name, query] of Object.entries(oxqlQueries)) { test(`oxql ${name}`, async ({ page }) => { await page.goto('/system/metrics-explorer', { waitUntil: 'networkidle' }) From e82e207c06e6138ffbffa152cb83b2035da98f2b Mon Sep 17 00:00:00 2001 From: benjaminleonard Date: Tue, 24 Nov 2026 11:09:22 +0000 Subject: [PATCH 2/4] Tune overscroll behavior to feel more native - Set overscroll-behavior-y: none on html as well as body so the app shell never rubber-bands, whichever element the browser treats as the viewport - Use overscroll-contain on side modal, modal and sidebar scrollers so they keep their native end-of-content bounce without chaining to the page - Disable overscroll entirely on menus, dropdowns and popovers, where a bounce on a small floating panel looks broken --- app/components/Sidebar.tsx | 2 +- app/ui/lib/Modal.tsx | 2 +- app/ui/lib/Popover.tsx | 2 +- app/ui/lib/SideModal.tsx | 2 +- app/ui/styles/components/menu-button.css | 2 ++ app/ui/styles/components/menu-list.css | 2 ++ app/ui/styles/index.css | 4 +++- 7 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/components/Sidebar.tsx b/app/components/Sidebar.tsx index 4d88d1ea3f..4ac8f141a0 100644 --- a/app/components/Sidebar.tsx +++ b/app/components/Sidebar.tsx @@ -85,7 +85,7 @@ export function Sidebar({ children }: { children: React.ReactNode }) {
diff --git a/app/ui/lib/Modal.tsx b/app/ui/lib/Modal.tsx index 155e49356e..7974bffd26 100644 --- a/app/ui/lib/Modal.tsx +++ b/app/ui/lib/Modal.tsx @@ -93,7 +93,7 @@ export function Modal({ ) } -Modal.Body = classed.div`py-2 overflow-y-auto overscroll-none` +Modal.Body = classed.div`py-2 overflow-y-auto overscroll-contain` Modal.Section = classed.div`p-4 space-y-4 border-b border-secondary text-default last-of-type:border-none text-sans-md` diff --git a/app/ui/lib/Popover.tsx b/app/ui/lib/Popover.tsx index 42822f511e..8ad8d13f23 100644 --- a/app/ui/lib/Popover.tsx +++ b/app/ui/lib/Popover.tsx @@ -34,7 +34,7 @@ export function Popover(props: PopoverProps) {
{children} diff --git a/app/ui/lib/SideModal.tsx b/app/ui/lib/SideModal.tsx index cf1307b549..e9390a7f2f 100644 --- a/app/ui/lib/SideModal.tsx +++ b/app/ui/lib/SideModal.tsx @@ -141,7 +141,7 @@ export const ResourceLabel = classed.h3`mt-1.5 flex items-center gap-1.5 text-sa SideModal.Body = ({ children }: { children?: ReactNode }) => (
{children} diff --git a/app/ui/styles/components/menu-button.css b/app/ui/styles/components/menu-button.css index 6f71cb19b3..292a106340 100644 --- a/app/ui/styles/components/menu-button.css +++ b/app/ui/styles/components/menu-button.css @@ -46,6 +46,8 @@ .dropdown-menu-content, .popover-panel { animation: slide-down 0.1s var(--ease-out-quad); + /* a small floating panel bouncing reads as broken, not native */ + overscroll-behavior: none; } @media (prefers-reduced-motion) { diff --git a/app/ui/styles/components/menu-list.css b/app/ui/styles/components/menu-list.css index 271131dcd3..9c8fe5e983 100644 --- a/app/ui/styles/components/menu-list.css +++ b/app/ui/styles/components/menu-list.css @@ -8,6 +8,8 @@ .ox-menu { @apply bg-raise light:bg-default !max-h-[17.5rem] rounded-md p-px; + /* a small floating list bouncing reads as broken, not native */ + overscroll-behavior: none; } .ox-menu-item { diff --git a/app/ui/styles/index.css b/app/ui/styles/index.css index ba380df4a5..b361676828 100644 --- a/app/ui/styles/index.css +++ b/app/ui/styles/index.css @@ -192,11 +192,13 @@ html, body { height: 100%; + /* stop the whole app shell rubber-banding; browsers disagree on whether + html or body controls the viewport, so set both */ + overscroll-behavior-y: none; } body { @apply text-default bg-default font-sans; - overscroll-behavior-y: none; } /* https://github.com/tailwindlabs/tailwindcss/blob/v2.2.4/src/plugins/css/preflight.css#L57 */ From 716c4389f3a2c1acc1300e6261e9388a7121c954 Mon Sep 17 00:00:00 2001 From: benjaminleonard Date: Tue, 24 Nov 2026 11:11:32 +0000 Subject: [PATCH 3/4] Trim comments --- app/ui/lib/Table.tsx | 17 +--- app/ui/styles/components/menu-button.css | 1 - app/ui/styles/components/menu-list.css | 1 - app/ui/styles/components/table.css | 101 +++++------------------ test/visual/regression.e2e.ts | 6 +- 5 files changed, 27 insertions(+), 99 deletions(-) diff --git a/app/ui/lib/Table.tsx b/app/ui/lib/Table.tsx index c7373ce2f2..a64ae5af84 100644 --- a/app/ui/lib/Table.tsx +++ b/app/ui/lib/Table.tsx @@ -11,18 +11,10 @@ import type { JSX } from 'react' import { classed } from '~/util/classed' export type TableProps = JSX.IntrinsicElements['table'] -/** - * The outer border is drawn by a frame pinned to the visible part of the - * scroller rather than by the edge cells, so it stays closed on every side - * however far the table is scrolled. See `table.css`. - * - * `className` goes on the scroller, the outermost box, so sizing classes like - * `max-w-lg` size the frame along with the table. - */ +/** `className` goes on the outer box so sizing classes also size the frame */ export function Table({ className, ...props }: TableProps) { return ( - // pb-2 + the 8px scrollbar is 16px below the table. It's a utility rather - // than in table.css so wrappers like CardBlock.Body can override it. + // a utility, not in table.css, so CardBlock.Body can override it
@@ -69,10 +61,7 @@ Table.Body = (props: TableBodyProps) => export type TableCellProps = JSX.IntrinsicElements['td'] & { height?: 'small' | 'large' } Table.Cell = ({ height = 'small', className, children, ...props }: TableCellProps) => ( -
+
div { border-bottom-width: 0px; } - /* Round the backgrounds of the bottom corner cells to sit inside the - frame's curve. Only needed when the table isn't scrolled; the visible - edge mid-scroll is an ordinary cell. */ & tbody tr:last-child td:first-child { border-bottom-left-radius: calc(var(--table-border-radius) - 1px); } @@ -145,15 +118,10 @@ table.ox-table { border-bottom-right-radius: calc(var(--table-border-radius) - 1px); } - /* - Adds padding to all cells except from - the action cells since they are a fixed width - */ & td:not(.action-col) > div { @apply pr-8; } - /* First column is sticky */ & th:first-child, & td:first-child { @apply sticky left-0 z-10; @@ -162,8 +130,6 @@ table.ox-table { @apply bg-default; } - /* Border between sticky first column and second column: - first column owns the right border, second column drops its left border */ & td:first-child > div, & th:first-child > div { @apply border-r; @@ -172,13 +138,11 @@ table.ox-table { & th:nth-child(2) > div { @apply border-l-0; } - /* header cells have 1px of right padding (which affects column widths), so - stretch the first one's div back over it to line its border up */ + /* cover the header's 1px right padding so the border lines up */ & th:first-child > div { @apply w-[calc(100%+1px)]; } - /* Last column is sticky if it is a more actions cell */ & .action-col { @apply sticky right-0 w-10; } @@ -189,25 +153,18 @@ table.ox-table { @apply m-0 w-10 p-0; } - /* Highlight when hovering over the action-col cell */ & td.action-col:hover > div { @apply bg-raise; } - /* - Selection outline. One box per selected row, drawn above the frame so it - replaces the frame's edge. Adjacent selected rows merge into one box by - dropping the borders and radii where they meet. - */ & tbody tr { position: relative; } & tbody tr.is-selected::after { content: ''; position: absolute; - /* cover the row above's bottom divider. The sides and bottom already line - up with the frame because the edge cells' transparent borders sit - under it. */ + /* -1px to cover the row above's divider. The sides and bottom already + line up with the frame. */ inset: -1px 0 0; border: 1px solid var(--stroke-accent); border-radius: 0.1875rem; @@ -228,22 +185,14 @@ table.ox-table { } /* -Edge shadows: on a sticky column while content is scrolled under it, and on -the frame's right edge for tables with no actions column to cast one. - -Where scroll-state container queries are supported, each shadow is on while -the scroller can scroll further toward its edge, and fades in and out with a -transition. Elsewhere they fall back to scroll-driven animations that track -the first and last 2rem of scroll. With neither, there are no shadows. When -the table fits, nothing can scroll and no shadow shows either way. +Edge shadows toggle with a transition where scroll-state queries are +supported, and otherwise track the first and last 2rem of scroll. */ .ox-table-scroller { --sticky-col-shadow: light-dark(oklch(0 0 0 / 0.075), oklch(0 0 0 / 0.3)); --edge-shadow-transition: 250ms ease-out; } -/* Keep the cell shadows from spilling above and below the cell. Safe to leave - on: nothing in these cells draws outside them (selection is on the row). */ .ox-table :is(td, th):first-child { clip-path: inset(0 -40px 0 0); } @@ -251,12 +200,8 @@ the table fits, nothing can scroll and no shadow shows either way. clip-path: inset(0 0 0 -40px); } -/* -The frame's shadow is cast by a box sitting just outside its right edge, with -the same box-shadow as the sticky columns, so the two match exactly. The -frame clips away the box itself and the shadow's ends, leaving just what -falls inside its border, rounded at the corners. -*/ +/* Tables with no actions column get the same shadow at the right edge, cast + from a box just outside the frame so it matches exactly. */ .ox-table-grid:not(:has(.action-col)) > .ox-table-frame { /* clip, not hidden: hidden would make the frame a scroll container, and the fallback's scroll(nearest) timeline would track it instead */ @@ -267,8 +212,6 @@ falls inside its border, rounded at the corners. position: absolute; left: 100%; width: 1rem; - /* overhang top and bottom so the blur tapers outside the frame, keeping - the shadow full strength down the whole edge */ top: -1rem; bottom: -1rem; box-shadow: -6px 0 8px -2px var(--sticky-col-shadow); @@ -305,8 +248,8 @@ falls inside its border, rounded at the corners. } } -/* Without the animation-timeline guard, browsers lacking scroll timelines - would run these with a 0s duration and hold the end state on every table */ +/* without the animation-timeline guard, unsupporting browsers would hold the + end state on every table */ @supports (animation-timeline: scroll()) and (not (container-type: scroll-state)) { .ox-table :is(td, th):first-child { animation: sticky-start-shadow linear both; diff --git a/test/visual/regression.e2e.ts b/test/visual/regression.e2e.ts index 8c9ddf6d9b..fb70b06d0e 100644 --- a/test/visual/regression.e2e.ts +++ b/test/visual/regression.e2e.ts @@ -259,9 +259,7 @@ test.describe('Visual Regression', { tag: '@visual' }, () => { }) }) - // Tables only overflow horizontally at narrow widths, which none of the - // standard pages hit. Capture each at its scroll start, middle, and end so - // the frame edges and sticky column shadows are covered. + // none of the standard pages are narrow enough for a table to overflow const overflowTables = [ { name: 'inventory sleds', url: '/system/inventory/sleds', heading: 'Inventory' }, { name: 'instances list', url: `${p}/instances`, heading: 'Instances' }, @@ -274,7 +272,7 @@ test.describe('Visual Regression', { tag: '@visual' }, () => { const table = page.getByRole('table').first() const slug = name.replaceAll(' ', '-') for (const position of ['start', 'middle', 'end'] as const) { - // find the scroller by behavior so this works whatever element scrolls + // by behavior, not selector, so baselines from older revisions work await table.evaluate((el, position) => { let node = el.parentElement while (node && node.scrollWidth <= node.clientWidth) node = node.parentElement From f28dc53afd663e51d0af9857919d879bef919f64 Mon Sep 17 00:00:00 2001 From: benjaminleonard Date: Tue, 24 Nov 2026 12:20:35 +0000 Subject: [PATCH 4/4] Remove selection css --- app/table/Table.browser.spec.tsx | 71 ------------------------------ app/table/Table.tsx | 61 ++++++------------------- app/table/columns/select-col.tsx | 38 ---------------- app/ui/lib/Table.tsx | 8 ++-- app/ui/styles/components/table.css | 26 ----------- 5 files changed, 16 insertions(+), 188 deletions(-) delete mode 100644 app/table/Table.browser.spec.tsx delete mode 100644 app/table/columns/select-col.tsx diff --git a/app/table/Table.browser.spec.tsx b/app/table/Table.browser.spec.tsx deleted file mode 100644 index 17937bb221..0000000000 --- a/app/table/Table.browser.spec.tsx +++ /dev/null @@ -1,71 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * Copyright Oxide Computer Company - */ -import { getCoreRowModel, useReactTable, type ColumnDef } from '@tanstack/react-table' -import { expect, test } from 'vitest' -import { render } from 'vitest-browser-react' - -import { getMultiSelectCol } from './columns/select-col' -import { Table } from './Table' - -type Item = { id: string; name: string } - -const data: Item[] = [ - { id: '1', name: 'alpha' }, - { id: '2', name: 'beta' }, -] -const columns: ColumnDef[] = [ - getMultiSelectCol(), - { accessorKey: 'name', header: 'Name' }, -] - -function MultiSelectTable() { - const table = useReactTable({ - columns, - data, - enableRowSelection: true, - getCoreRowModel: getCoreRowModel(), - getRowId: (row) => row.id, - }) - return -} - -test('selects a row by clicking its checkbox cell', async () => { - const screen = await render() - const row = screen.getByRole('row', { name: 'alpha' }) - const headerCheckbox = screen.getByRole('checkbox').first() - - await row.getByRole('cell').first().click() - - await expect.element(row.getByRole('checkbox')).toBeChecked() - await expect.element(headerCheckbox).toBePartiallyChecked() - await expect.element(row).toHaveClass('is-selected') -}) - -test('selects and clears every row from the header checkbox', async () => { - const screen = await render() - const checkboxes = screen.getByRole('checkbox') - const headerCheckbox = checkboxes.first() - - await headerCheckbox.click() - await expect.element(checkboxes.nth(1)).toBeChecked() - await expect.element(checkboxes.nth(2)).toBeChecked() - await expect - .element(screen.getByRole('row', { name: 'alpha' })) - .toHaveClass('is-selected') - await expect.element(screen.getByRole('row', { name: 'beta' })).toHaveClass('is-selected') - - await headerCheckbox.click() - await expect.element(checkboxes.nth(1)).not.toBeChecked() - await expect.element(checkboxes.nth(2)).not.toBeChecked() - await expect - .element(screen.getByRole('row', { name: 'alpha' })) - .not.toHaveClass('is-selected') - await expect - .element(screen.getByRole('row', { name: 'beta' })) - .not.toHaveClass('is-selected') -}) diff --git a/app/table/Table.tsx b/app/table/Table.tsx index 17eacccd74..71f763f94e 100644 --- a/app/table/Table.tsx +++ b/app/table/Table.tsx @@ -6,26 +6,19 @@ * Copyright Oxide Computer Company */ import { flexRender, type Table as TableInstance } from '@tanstack/react-table' -import cn from 'classnames' import type { JSX } from 'react' import { Table as UITable } from '~/ui/lib/Table' export type TableProps = JSX.IntrinsicElements['table'] & { - rowClassName?: string rowHeight?: 'small' | 'large' table: TableInstance - singleSelect?: boolean - multiSelect?: boolean } /** Render a React Table table instance */ export const Table = ({ - rowClassName, rowHeight = 'small', table, - singleSelect, - multiSelect, ...tableProps }: TableProps) => ( @@ -53,47 +46,19 @@ export const Table = ({ ))} - {table.getRowModel().rows.map((row) => { - // For single-select, the entire row is clickable - const rowProps = - singleSelect && row.getCanSelect() // this means single-select only - ? { - className: cn(rowClassName, 'cursor-pointer'), - selected: row.getIsSelected(), - // select only this row - onClick: () => table.setRowSelection(() => ({ [row.id]: true })), - } - : { - className: rowClassName, - selected: - multiSelect && row.getCanMultiSelect() ? row.getIsSelected() : undefined, - } - - // For multi-select, assume the first cell is the checkbox and make the - // whole cell clickable - const firstCellProps = - multiSelect && row.getCanMultiSelect() - ? { - className: 'cursor-pointer', - onClick: () => row.toggleSelected(), - } - : {} - - return ( - - {row.getAllCells().map((cell, i) => ( - - {flexRender(cell.column.columnDef.cell, cell.getContext())} - - ))} - - ) - })} + {table.getRowModel().rows.map((row) => ( + + {row.getAllCells().map((cell) => ( + + {flexRender(cell.column.columnDef.cell, cell.getContext())} + + ))} + + ))} ) diff --git a/app/table/columns/select-col.tsx b/app/table/columns/select-col.tsx deleted file mode 100644 index c34a0e7990..0000000000 --- a/app/table/columns/select-col.tsx +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, you can obtain one at https://mozilla.org/MPL/2.0/. - * - * Copyright Oxide Computer Company - */ -import type { Row, Table } from '@tanstack/react-table' - -import { Checkbox } from '~/ui/lib/Checkbox' -import { Radio } from '~/ui/lib/Radio' - -// only needs to be a function because of the generic params -export const getSelectCol = () => ({ - id: 'select', - header: '', - cell: ({ row }: { row: Row }) => { - // `onChange` is empty to suppress react warning. Actual trigger happens in `Table.tsx` - return {}} /> - }, -}) - -export const getMultiSelectCol = () => ({ - id: 'select', - header: ({ table }: { table: Table }) => ( -
- -
- ), - cell: ({ row }: { row: Row }) => ( - // `onChange` is empty to suppress react warning. Actual trigger happens in `Table.tsx` - {}} /> - ), -}) diff --git a/app/ui/lib/Table.tsx b/app/ui/lib/Table.tsx index a64ae5af84..9d26ebe233 100644 --- a/app/ui/lib/Table.tsx +++ b/app/ui/lib/Table.tsx @@ -49,11 +49,9 @@ Table.HeadCell = ({ className, children, ...props }: TableHeadCellProps) => ( ) -export type TableRowProps = JSX.IntrinsicElements['tr'] & { - selected?: boolean -} -Table.Row = ({ className, selected, ...props }: TableRowProps) => ( -
+export type TableRowProps = JSX.IntrinsicElements['tr'] +Table.Row = ({ className, ...props }: TableRowProps) => ( + ) export type TableBodyProps = JSX.IntrinsicElements['tbody'] diff --git a/app/ui/styles/components/table.css b/app/ui/styles/components/table.css index 8544ed2681..1e4be5de79 100644 --- a/app/ui/styles/components/table.css +++ b/app/ui/styles/components/table.css @@ -156,32 +156,6 @@ table.ox-table { & td.action-col:hover > div { @apply bg-raise; } - - & tbody tr { - position: relative; - } - & tbody tr.is-selected::after { - content: ''; - position: absolute; - /* -1px to cover the row above's divider. The sides and bottom already - line up with the frame. */ - inset: -1px 0 0; - border: 1px solid var(--stroke-accent); - border-radius: 0.1875rem; - pointer-events: none; - z-index: 30; - } - & tbody tr.is-selected:has(+ tr.is-selected)::after { - border-bottom-width: 0; - border-bottom-left-radius: 0; - border-bottom-right-radius: 0; - } - & tbody tr.is-selected + tr.is-selected::after { - top: 0; - border-top-width: 0; - border-top-left-radius: 0; - border-top-right-radius: 0; - } } /*