Repository navigation
Conversation
Touch browsers keep :hover on the last tapped element, so a tapped link kept its hover background until something else was tapped. That shows on links that keep the user on the page, such as TableOfContent links and the TermDefinition trigger. Limit the Anchor and TableOfContent hover styles to devices that can hover. The TermDefinition trigger shows its dotted underline and the text color only while it isn't hovered. On touch devices, style a tapped trigger like one without the mouse over it.
|
Why This is the industry standard: Tailwind CSS v4 applies its The |
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
left a comment
There was a problem hiding this comment.
Review of d67e30c: Changes needed
The PR hides Anchor, TableOfContent and TermDefinition hover styles after a tap or a key press. The touch fix works. But the last commit (d67e30c, "Restore the html hover check") brings back the specificity problem that da0bb4a had fixed, so pressed and disabled styles now lose to hover for mouse users. Tested merged with main at ecaa2f5.
Must fix
-
Hover now wins over pressed, disabled and the sidebar look for mouse users.
anchor-mixins.scss:159-161anddnb-table-of-content.scss:113,:166and:202prefix the hover rules withhtml:not([data-whatintent='touch'], [data-whatintent='keyboard']). That raises the hover rule from (0,2,0) on main to (0,3,1). It now beats every same-element rule of (0,2,0) to (0,4,0) that used to win by coming later:- A pressed Anchor keeps its hover look.
:activeno longer changes the text color or background. This also hits the TermDefinition trigger. - A hovered disabled Anchor (
.dnb-anchor--disabled,aria-disabled,disabled) turns teal instead of staying grey. - A sidebar TableOfContent link gets an underline on hover and press. On main,
--sidebarsetstext-decoration: nonefor it. - A pressed sidebar TableOfContent link keeps the darker hover color instead of the pressed
neutral-alternativecolor.
I measured computed styles with real mouse hover and press in Chromium, Firefox and WebKit. I used CSS compiled from each commit with the UI theme. Every case above matches main on
origin/mainand onda0bb4a, and is wrong ond67e30c. The commit message ofda0bb4alists the same symptoms. CI agrees: the e2e job failstableOfContent.spec.ts:724("matches the compact desktop rows and plain hover styling") in Firefox, where it expectstext-decoration-line: noneon a hovered sidebar link and getsunderline.The
:where()wrapper inda0bb4acannot come back as it was. I ran the repo'spostcss-isolated-style-scopeplugin on it, and it puts the scope class first (.eufemia-scope--portal :where(html…) .dnb-anchor:hover). So that rule never matches, asd67e30csays. On theda0bb4apreview, mouse hover on an Anchor shows no background at all.Suggested fix: put the guard on the element, with zero specificity. SidebarMenu already does this on main (
dnb-sidebar-menu.scss:215):&:hover:not(:where(html[data-whatintent='touch'] *, html[data-whatintent='keyboard'] *)). The scope plugin leaves it working (.eufemia-scope--portal .dnb-anchor:hover:not(:where(html[…] *))). I built that variant for the Anchor. Pressed and disabled then match main in all three engines, and touch and keyboard intent still hide hover. The three TableOfContent rules need the same change. - A pressed Anchor keeps its hover look.
How I verified this
I compiled dnb-ui-core, ui-theme-components, ui-theme-extensions and ui-theme-basis from the package source at each commit, and served them on a test page with the DNB fonts (I checked that the fonts loaded). A Playwright script sets data-whatintent, then reads the computed styles at rest, on page.hover() and after mouse.down().
Firefox, data-whatintent="mouse":
css-main a-text ACTIVE color=rgb(20, 85, 90) shadow=rgb(188, 232, 220) (pressed)
css-d67e30 a-text ACTIVE color=rgb(0, 114, 114) shadow=rgb(216, 243, 236) (still hover)
css-main a-disabled HOVER color=rgb(204, 204, 204)
css-d67e30 a-disabled HOVER color=rgb(0, 114, 114)
css-da0bb4 a-text ACTIVE color=rgb(20, 85, 90) (control: the :where() version was right)
Sidebar TableOfContent link, the same in all three engines:
css-main HOVER deco=none ACTIVE color=rgb(112, 112, 112) deco=none
css-d67e30 HOVER deco=underline ACTIVE color=rgb(51, 51, 51) deco=underline
With the zero-specificity variant, pressed is rgb(20, 85, 90), and disabled on hover stays rgb(204, 204, 204). With touch and keyboard intent, hover shows shadow=none.
Scope plugin output for the three selector shapes:
html:not([data-whatintent=touch], [data-whatintent=keyboard]) .eufemia-scope--portal .dnb-anchor:hover
.eufemia-scope--portal :where(html:not([data-whatintent=touch], [data-whatintent=keyboard])) .dnb-anchor:hover
.eufemia-scope--portal .dnb-anchor:hover:not(:where(html[data-whatintent=touch] *, html[data-whatintent=keyboard] *))
Suggestions (non-blocking)
- The TermDefinition reset (
dnb-term-definition.scss:27and:31) useshtml:not([data-whatintent='mouse']), but the Anchor guard usesnot touch, not keyboard. While the intent isinitial, or before input tracking starts, a hovered trigger gets the Anchor hover background together with the at-rest color and the dotted underline.da0bb4ahad aligned the two. The same zero-specificity pattern on the element would align them again. This is rare in practice, because the first mouse move setsmouse. - The
@supports not (selector(*:where(*)))fallback insidenotNoHoveris now nested under a selector that needs:not()with a selector list. Browsers without:where()also lack that, so the fallback rule cannot match any more. It is harmless, but it is now dead code inside this rule.
What I checked
- Touch: with
hasTouchin Chromium and WebKit, a tap setsdata-whatintent="touch"on theda0bb4apreview. The tapped Anchor shows no hover background there, while main keeps it. The touch path is the same ind67e30c. Locally, touch and keyboard intent remove the hover background ond67e30cfor text, disabled, dark-surface,button.dnb-anchorand--no-hoverAnchors in Chromium. - Dark surface: the hover and pressed backgrounds on main and on the PR use the right
ondarktokens. Pressed has the same specificity problem as above. - Trial merge with
ecaa2f5(a realgit merge --no-commit): no conflicts. On the merge with53fa3bd,Anchor.test.tsx,TermDefinition.test.tsx,TableOfContent.test.tsxandTableOfContent.style.test.tspass: 133 tests. One style test timed out at a load average of 83, then passed alone. stylelintandprettier --checkon the 3 SCSS files: clean.
CI on d67e30ce2c when I posted this: 21 checks passed; Run e2e tests failure; 1 still running (Run visual-regression tests). The e2e job fails the TableOfContent test "matches the compact desktop rows and plain hover styling" in Firefox: a hovered sidebar link is underlined, because the new hover prefix outranks the sidebar's text-decoration: none (must-fix 1). Rechecked just before posting: the head is still d67e30c, and a real trial merge with main at 541b379 (which now includes #11052) has no conflicts.

On iOS Safari, and in other touch browsers, a tapped link kept its hover style until something else was tapped. It's the same issue as reported for Switch in #11007. It shows mostly on links that keep the user on the page:
Hover now follows the current input, using the same
data-whatintenttracking 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.Use together with #11053 for the shared hover behavior.
Before / after