Skip to content

fix(List): prevent sticky hover outline after tapping on touch devices - #11042

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

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

Conversation

@langz

@langz langz commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

On iOS Safari, and in other touch browsers, a List action item or accordion item kept its green hover outline after being tapped, until something else was tapped. It's the same issue as reported for Field.MultiSelection in #11025.

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.

The keyboard focus outline excludes hovered items. A tapped item keeps :hover on touch devices, so when the user came back to it with the keyboard (for example on a tablet with a keyboard), it showed the green hover outline instead of the blue focus outline. When the current intent is keyboard, the focus outline now shows on a tapped item too. This also covers the fallback for browsers without :has(), and the stacking of focused rows inside an open accordion.

Use together with #11053 for the shared hover behavior.

Before / after

A List action item on a touch device after one tap. Before: the item keeps the green hover outline. After: it shows the normal look.

A List accordion on a touch device after one tap on the header. Before: it keeps the green hover outline. After: it shows the normal open look.

Touch browsers keep :hover on the last tapped element, so a tapped
action or accordion item kept its green hover outline until something
else was tapped. Limit the hover outlines to devices that can hover.

The keyboard focus outline excluded hovered items. On touch devices a
tapped item keeps :hover, so it showed the hover outline instead of the
focus outline when the user returned to it with the keyboard. Show the
focus outline there too, also in the fallback for browsers without
support for :has().
The focus fallback for browsers without :has() now has rules for devices that can't hover, so a tapped item shows the focus outline too. List them in the test, with their media query.
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.

@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 5fdea53: Changes needed

The List hover outlines now apply only inside @media (any-hover: hover) and while the tracked intent is not touch or keyboard. A tapped item now shows the keyboard focus outline when focus comes back to it. The touch fix works. The restored html:not(…) prefix breaks two mouse states, and two required checks are red. Tested merged with main at ecaa2f5 (clean merge).

Must fix

  1. The pressed look is gone while the mouse button is down. The prefix adds (0,1,1) to the hover rules at dnb-list.scss:588-593 (action row) and :664-671 (accordion header). On main, the later :active rules (:614-623, :688-698) had the same specificity and won while the button was down. Now hover wins, so a pressed row keeps the 2px hover outline instead of the 1px pressed outline.
    I verified it on the previews of main (d85af17f) and this head (8e8c408d). I pressed the mouse on each of the first 12 action rows and accordion headers of the List demos. On main, 0 of 12 kept the hover outline while pressed (1px rgb(20, 85, 90)). On this head, 12 of 12 did in Chromium (2px rgb(0, 114, 114)), and 6 of 6 in Firefox. Control: when I remove only the prefix from the loaded CSS of the head preview, 0 of 12 do. This is the same cause W06b reported for Chip and MultiSelection today.
  2. The hover outline of a nested row loses its outer pixel, and Run e2e tests fails. The hover mixin sets z-index: 2 on the row. On main that rule lost to … > .dnb-list__item__accordion__content .dnb-list__item:is(:hover, :has(> :focus-visible)) { z-index: 11 } (:743-748), which is (0,4,0). With the prefix, the hover rule is (0,4,1) and wins. So a hovered nested row stays at z-index: 2, and its neighbours cover the outer pixel of its outline on the sides and the bottom.
    CI fails List.e2e.spec.ts:389 ("paints the full nested side and bottom hover and focus outline") in Firefox at 400px and 1024px. I ran that test against the previews: 2 of 2 passed on main, and 2 of 2 failed on this head. With my own copy of its steps, both action rows report rowZ=2 and gray edge pixels (235,235,235) on this head in Firefox and Chromium. On main they report rowZ=11 and green edge pixels. With the prefix removed from the loaded CSS, the head passes again. Focus states and the accordion header pass in all runs.
  3. ListStyles.test.ts fails, and Run tests is red. "should show the outline of a focused item in browsers without :has()" still expects the six fallback rules inside @media (hover: none), without a prefix (ListStyles.test.ts:56-123). Since 30c8a70 the CSS has them as html:not([data-whatintent=mouse]) …, without that media query. The test file was last changed in 6ab7316. It fails the same way in CI and locally on the merge with main (an assertion error, not a timeout). The expectations need to match the current rules.

A direction for 1 and 2 (not verified by me): keep the old specificity. Either fix the scope plugin so that :where(html…) gets the scope after html (that was the 7dcdcfd approach), or exclude the pressed state and the nested z-index case from the hover rules (for example :hover:not(:active), plus the same prefix on the z-index: 11 rule).

Before (main) and after (this PR): a List action row while the mouse button is down, and the bottom-right corner of a hovered nested row at 6x

Earlier findings

  • Still holds: the earlier review on 6ab7316 said that after a tap, Tab and Shift+Tab the item shows the blue focus outline. On this head, the action row shows 3px rgb(39, 106, 206), both on a phone and on a touchscreen laptop. On main it shows the 2px green hover outline.
  • Outdated: that review also said that ListStyles.test.ts lists the six (hover: none) fallback rules. The test still does, but the CSS no longer matches it (see must-fix 3).

What I checked

  • Phone (Chromium, isMobile + hasTouch): after a tap on an action row, the outline is the rest outline (1px rgb(235, 235, 235)). On main it stays 2px rgb(0, 114, 114).
  • Mouse hover and keyboard focus on action rows and accordion headers: the same as main, except for the nested z-index case above.
  • Run tests and Run e2e tests logs on 5fdea53. The Portal SidebarMenu e2e failure in the same job was flaky (it passed on retry), and it does not touch List.
  • The tree of 5fdea53 is identical to d61f07c. The last commit only undid 7dcdcfd.
  • Not covered: browsers without :has(), WebKit and real iOS Safari.

CI on 5fdea53740 when I posted this: 21 checks passed; Run e2e tests failure, Run tests failure. Run tests fails in ListStyles.test.ts, because the test still expects the old (hover: none) fallback rules. Run e2e tests fails List.e2e.spec.ts:389 (nested hover outline), a real regression from the raised hover specificity; the Portal SidebarMenu failure in the same job was flaky and passed on retry. Rechecked just before posting: the head is still 5fdea53, 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 — 5fdea537 Deployed Nov 24, 2026 by github-actions[bot]
Portal preview — 5fdea537 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