Skip to content

fix(Table): keep the selected border and focus outline visible after a tap on touch devices - #11049

Open
langz wants to merge 8 commits into
mainfrom
fix/table-accordion-focus-after-tap
Open

langz wants to merge 8 commits into
mainfrom
fix/table-accordion-focus-after-tap

Conversation

@langz

@langz langz commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

A tapped Table row or cell can keep :hover when the user switches to the keyboard. This can hide its focus outline or selected border and leave the sort button underlined.

Use the tracked input for hover and focus styling, so switching between touch, keyboard and mouse also works on devices that have both a mouse and touchscreen. Use together with #11053 for the shared hover behavior.

Before / after

A Table with accordion rows on a touch device after a tap on Row 1, then Tab away and Shift+Tab back. Before: the row shows no focus outline. After: the blue focus outline shows.

A Table with a selectable cell on a touch device after one tap that selects it. Before: the selected cell has no selected border. After: the selected border shows.

Touch browsers keep :hover on the last tapped element. The hover mixin
hides the row hover outline after a touch, but not after the user
presses a key, and the keyboard focus outline excludes hovered rows. So
when the user opened a row with a tap and came back to it with the
keyboard, the row showed no focus outline.

Limit the row hover styles to devices that can hover. On devices that
can't hover, style a tapped row like one without the mouse over it, so
it shows the focus outline, and an open row keeps its usual border.
langz added a commit that referenced this pull request Nov 24, 2026
… devices

A tapped element keeps :hover on touch devices, so a focus style with :not(:hover) does not show when the user comes back to it with the keyboard. Add a bullet that tells how to avoid that, as done in #11025, #11042, #11043, #11048 and #11049.
langz

This comment was marked as outdated.

…touch devices

Touch browsers keep :hover on the last tapped element. A selectable cell
shows its selected border only while it isn't hovered, so a cell that
was selected with a tap showed no border until something else was
tapped. Its focus outline also excluded hovered cells.

On devices that can't hover, show the selected border and the focus
outline on a tapped cell, and limit the cell hover outline to devices
that can hover. Also hide the underline of the active sort button on a
tapped button, as for one without the mouse over it.

Put all Table touch tests in TableTouch.e2e.spec.ts.
@langz langz changed the title fix(Table): show the accordion row focus outline after a tap on touch devices fix(Table): keep the selected border and focus outline visible after a tap on touch devices Nov 24, 2026
#11053 limits the hover mixin to devices that can hover. Wrapping the mixin calls here as well gave a doubled media query, and the Table style snapshot went stale without a merge conflict when both changes were merged. Keep the wrappers only on the plain :hover rules.
@langz

langz commented Nov 24, 2026 •

Copy link
Copy Markdown
Member Author

Why @media (hover: hover): touch browsers keep :hover on the last tapped element, so hover styles stay after a tap until the user taps somewhere else. The query tests whether the primary input can hover (MDN, in all browsers since 2018). So mouse and trackpad hover stay as they are, and phones and tablets never get the sticky state.

This is the industry standard: Tailwind CSS v4 applies its hover variant only inside @media (hover: hover) (upgrade guide), and Radix Themes and Mantine wrap their component hover styles the same way.

The :not([data-whatintent='touch']) check alone is not enough: a key press outside a text field, for example Tab or an arrow key, sets the intent to keyboard, so on a tablet with a keyboard the tapped control shows its hover style again (measured on Button, Tag, ToggleButton and Tabs). #11053 now shows hover only while the current input is a mouse (html[data-whatintent='mouse']). That also covers Chromebooks and touchscreen laptops, where (hover: hover) matches even though the user can tap. The trade-off: without Eufemia's JavaScript nothing sets data-whatintent, so these styles show no hover at all.

Wrap the hover guard in @media (any-hover: hover) and check that the
current input is not touch or keyboard, instead of requiring mouse intent.

Hover styles now work before Eufemia's input tracking has started and
without it, while a tap or a key press still turns them off. any-hover
keeps hover for a trackpad on iPad and a mouse on Android tablets, where
hover: hover is false. The selector specificity is unchanged.
The inline hover guard raised the specificity of rules that were a
plain :hover on main. Hover then won over pressed, disabled and error
styles: a disabled Anchor turned teal on hover, a pressed Card action
kept its hover outline, and a Textarea with an error lost its red
border on hover. Wrap the guard in :where() so each rule keeps the
specificity it has on main.

Rules that make a tapped element look as at rest now apply exactly
when hover styles are off: on devices that cannot hover, and while the
tracked input is touch or keyboard. Before, they also applied when no
input had been tracked yet, for example without JavaScript, and then
cancelled part of the hover style.
The :where() wrapper put the html element after the style scope class
in scoped builds (.eufemia-scope--portal :where(html...)), so these
hover rules never matched there. Restore the previous check until the
specificity fix also works with style scoping.

@langz langz left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Review of e2abbbd: Changes needed

The PR keeps the focus outline, the selected-cell border and the sort button look right after a tap. Those fixes work. But the last commit (e2abbbd, "Restore the html hover check") makes the expanded-row hover rule win over the pressed rule, so an open accordion row no longer shows its pressed background. Tested merged with main at ecaa2f5.

Must fix

  1. An expanded accordion row loses its pressed background. table-accordion.scss:160-166 prefixes the expanded-row hover rule with html:not([data-whatintent='touch'], [data-whatintent='keyboard']). That raises it from (0,5,0) on main to (0,6,1). The pressed rule at table-accordion.scss:208 (…__tr:not(…--disabled):active .dnb-table__td) is (0,5,0). On main it won because it comes later. Now hover wins while the mouse button is down, so the row keeps the white header background instead of the pressed rgb(188, 232, 220). The rule at :214 is safe, because it has :not(:active).

    CI shows the same failure. The visual job fails "Table with accordion … have to match active state on last row" for ui, sbanken and coconut (about 10% of pixels differ). The row it presses (#accordion-table-2-3) is an expanded row.

    Suggested fix: add :not(:active) to the row in that rule, as :214 does. Or move the guard onto the row with zero specificity, as SidebarMenu does on main: :hover:not(:where(html[data-whatintent='touch'] *, html[data-whatintent='keyboard'] *)). The scope plugin keeps that working in scoped builds.

How I verified this

I copied three tables from the main preview: a sortable table, an accordion table with one expanded row, and a table with cell buttons. I styled them with CSS compiled from origin/main and from e2abbbd with the UI theme, set data-whatintent="mouse", then hovered and pressed with the real mouse. For the control, I removed only that prefix from the head CSS (3 occurrences), and the pressed background came back.

                       expanded row, mouse down       collapsed row, mouse down
main                   td-bg=rgb(188, 232, 220)       td-bg=rgb(188, 232, 220)
e2abbbd                td-bg=rgb(255, 255, 255)       td-bg=rgb(188, 232, 220)
e2abbbd, no prefix     td-bg=rgb(188, 232, 220)       td-bg=rgb(188, 232, 220)

It is the same in Chromium, Firefox and WebKit. The row script adds dnb-table__tr--hover only after a click. Even then, the rule at :160 still matches the pressed row, so both cases are affected.

Suggestions (non-blocking)

  1. With keyboard intent, a tapped sort button and a tapped cell still get the hover mixin's underline and 2px border. On main the hover mixin excludes only touch. #11053 changes that mixin, as the description says, so merge this together with #11053 or after it.

What I checked

  • The touch fixes, with data-whatintent="touch" and the pointer still over the element, compared with main:
    • Selected cell: the 1px selected border stays. On main it is 0px.
    • Active sort button: no underline. On main it is underlined.
    • Expanded row: it keeps its resting top border instead of the hover outline.
    • I checked these in Chromium. Mouse hover and pressed states of cells, collapsed rows and the sort button match main.
  • Focus after a tap: I focused rows and the selected cell with a real Tab, set keyboard input and intent, and kept the pointer over them. Collapsed rows, expanded rows and the selected cell now show the 3px focus outline. On main they show the 2px hover outline. When the mouse moves onto a focused element (mouse intent), the result is unchanged from main. I checked this in Chromium and Firefox, and for rows in WebKit. WebKit does not Tab to buttons by default, so it could not test the cell.
  • Trial merge with ecaa2f5 (a real git merge --no-commit): no conflicts. Table.test.tsx and TableAccordion.test.tsx pass: 58 tests. stylelint on the 3 SCSS files: clean.

Expanded accordion row in Firefox. Before (main): pressing the row shows the green pressed background. After (this PR, e2abbbd): pressing keeps the white hover look.


CI on e2abbbd89d when I posted this: 23 checks passed; Run visual-regression tests failure. The visual job fails 3 Table accordion screenshots ('active state on last row' in ui, sbanken and coconut), because hover now wins over the pressed style on an expanded row (must-fix 1). Rechecked just before posting: the head is still e2abbbd, and a real trial merge with main at 541b379 (which now includes #11052) has no conflicts.

This branch was successfully deployed

2 active deployments
Package preview — e2abbbd8 Deployed Nov 24, 2026 by github-actions[bot]
Portal preview — e2abbbd8 Deployed Nov 24, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants