Skip to content

fix(Field.MultiSelection): prevent sticky row hover after tapping on touch devices - #11025

Open
langz wants to merge 8 commits into
mainfrom
fix/multi-selection-sticky-hover-touch
Open

langz wants to merge 8 commits into
mainfrom
fix/multi-selection-sticky-hover-touch

Conversation

@langz

@langz langz commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Motivation: https://dnb-it.slack.com/archives/CMXABCHEY/p1795427065802309

On iOS Safari, and in other touch browsers, a Field.MultiSelection row kept its green hover frame after being tapped, until something else was tapped. It's the same issue as reported for Switch in #11007, and the last remaining one in the Forms selection fields.

Hover now follows the current input, using the same data-whatintent tracking as Button. A tap hides hover styling, it stays hidden when switching to the keyboard, and using the mouse brings it back. This also works on devices with both a touchscreen and a mouse.

@media (hover: hover) only describes the primary pointer's capabilities. It can stay true while the touchscreen is being used, so it does not provide the same switching.

A tapped row still matches :hover on touch devices, so the keyboard focus frame now also shows on it there.

Use together with #11053 for the shared hover behavior.

Before / after

A MultiSelection list on a touch device after a tap on the Oslo row. Before: the tapped row keeps a green hover frame. After: the row has no hover frame.

…devices

Touch browsers keep :hover on the last tapped element, so a tapped
MultiSelection row kept its hover frame until something else was
tapped. Limit the row hover styles to devices that can hover.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
langz

This comment was marked as outdated.

langz

This comment was marked as outdated.

langz

This comment was marked as outdated.

langz

This comment was marked as outdated.

langz

This comment was marked as outdated.

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

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.
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 65fc529: Changes needed

Since the last review (952f8c1), the row hover rule moved from @media (hover: hover) to @media (any-hover: hover) with an html:not([data-whatintent='touch'], [data-whatintent='keyboard']) check, the touch e2e tests were removed, and the touch focus rule now checks the intent instead of (hover: none). 65fc529 reverts the :where() wrapper from a5fe28a, so the tree equals cf5be28. The touch fix works, but the check raises the specificity of the hover rule, and the pressed frame no longer shows. Tested merged with main at ecaa2f5.

Must fix

  1. Hover now wins over the pressed state, so a row never shows its pressed frame with a mouse. On main, &:hover:not(&--disabled) and &:active:not(&--disabled) (dnb-multi-selection.scss:160 and :169) have the same specificity, and the later :active rule wins. The html:not(...) prefix adds 0,1,1 to the hover rule, so it now wins while the mouse button is down.
    I pressed each of the 27 enabled demo rows with a real mouse (hover, mouse button down, release outside the row), on the main preview and on https://pr-11025.eufemia-e25.pages.dev, which serves this tree (its CSS has the html:not(...) check without :where()). Hover looks the same on 27 of 27 rows. Pressed: on main the row frame is 1px rgb(20, 85, 90) (pressed). On this PR it stays 2px rgb(0, 114, 114) (hover), on 27 of 27 rows in Chromium and in WebKit. In Firefox, main shows a pressed frame on only 1 row, and that row differs too. Control: when I remove only the html:not(...) prefix from the loaded CSS on the PR preview, the pressed frame equals main on 27 of 27 rows.
    CI confirms it: Run visual-regression tests on 65fc529 fails MultiSelection > should match active state of item.
    Suggested fix: keep the check, but at zero specificity and inside the compound selector, so the style scope plugin leaves it alone. For example &:hover:not(&--disabled):where(html:not([data-whatintent='touch'], [data-whatintent='keyboard']) *). I checked this form on #11010: it survives the scope plugin, it matches only with the intent mouse or with no intent, and a later :active rule still wins, in Chromium, Firefox and WebKit.

Earlier findings

  • Resolved: a tapped row had no focus frame when the user returned to it with the keyboard. With touch emulation I tapped row 2, pressed Tab, then Shift+Tab (Alt+Tab in WebKit). The tapped row now shows the 3px rgb(39, 106, 206) focus frame in Chromium, Firefox and WebKit. On main it shows the 2px hover frame instead. The new rule html:not([data-whatintent='mouse'])[data-whatinput='keyboard'] &:not(:active):has(...) (dnb-multi-selection.scss:185) does this without (hover: none).

What I checked

  • Range-diff 952f8c1..65fc529: five new commits. The net change to the style file is the hover wrapper and the new focus rule. MultiSelection.e2e.spec.ts is back to the main version.
  • Real trial merge with main ecaa2f5 (git merge --no-commit): no conflicts, yarn.lock unchanged. MultiSelection.test.tsx passes 106 of 106. Stylelint and Prettier pass on the style file.
  • Touch emulation in all three engines: after a tap, the row has no hover frame (1px transparent). On main it keeps the 2px hover frame.
  • Shipped CSS on the PR preview: the hover rule has the check in all 6 theme bundles, and the scope class comes after html.
  • CI: the visual job on this head fails exactly one screenshot, MultiSelection > should match active state of item, which is this must-fix. The other 119 screenshot files pass.

MultiSelection row "Oslo" with a mouse, Before (main) and After (this PR), in desktop Chromium. After, the hover frame stays while the mouse button is down


CI on 65fc529cd1 when I posted this: 23 checks passed; Run visual-regression tests failure. Run visual-regression tests fails MultiSelection > should match active state of item: this is must-fix 1. Rechecked just before posting: the head is still 65fc529.

This branch was successfully deployed

2 active deployments
Package preview — 65fc529c Deployed Nov 24, 2026 by github-actions[bot]
Portal preview — 65fc529c 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