Repository navigation
Conversation
Touch browsers keep :hover on the last tapped element, so a Checkbox kept its hover colors after being tapped until something else was tapped. Limit the hover styles to devices that can hover. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Touch browsers keep :hover on the last tapped element, so a tapped Chip kept its hover ring and indicator colors until something else was tapped. Limit the hover styles to devices that can hover. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
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.
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 e361b1c: Changes needed
Since the last review (d43b146), the branch added 1d709d1 (wrap the check in :where()) and then e361b1c (restore the html:not(...) check). The tree of e361b1c is identical to d43b146, so nothing changed in the code. But that also restores the specificity problem that 1d709d1 set out to fix, and for Chip it breaks the pressed state. Tested merged with main at 53fa3bd.
Must fix
- Hover now wins over the pressed state, so a Chip never shows its pressed look with a mouse. The
html:not([data-whatintent='touch'], [data-whatintent='keyboard'])prefix adds 0,1,1 to every Chip hover rule. Onmain, the hover and the pressed rules have the same specificity, and the later pressed rule wins. Now the hover rule wins while the mouse button is down. This affectschipState(':not(:disabled):hover', ...)againstchipState(':not(:disabled):active', ...)(dnb-chip.scss:109and:153), the selected pair (:137and:176), the error button pair (:293and:311) and the error checkbox and radio pair (:429and:439). The Checkbox rules are not affected, because they already use:hover:not(:active).
I pressed every enabled Chip on the demo page with a real mouse (hover, then mouse button down, then release outside the Chip), on themainpreview and on the branch preview382744cb, which is a build of the same tree ase361b1c. Hover looks the same on 81 of 81 Chips in every engine. The pressed look differs on 79 of 81 Chips in Chromium and on 76 of 81 in WebKit. In Firefox it differs on the 5 addable (button) Chips. Firefox does not give the input:activewhen you press its label, so checkbox and radio Chips have no pressed look in Firefox onmaineither. Control: when I remove only thehtml:not(...)prefix from the loaded CSS on the branch preview, the pressed look equalsmainon 81 of 81 Chips in Chromium.
Suggested fix: keep the check at zero specificity, but put it inside the compound selector, so the style scope plugin leaves it alone. For example&:hover:where(html:not([data-whatintent='touch'], [data-whatintent='keyboard']) *). I ran the scope plugin on this form. It produces.eufemia-scope--portal .dnb-chip__button:hover:where(html:not(...) *). In a test page inside.eufemia-scope--portalin Chromium, Firefox and WebKit, that rule matches with the intentmouseor with no intent, and it does not match withtouchorkeyboard. A later:activerule still wins. The:where(html...) &form from1d709d1never matched there, as the commit message says.
Earlier findings
- Still true: the branch carries the Checkbox change from #11008. Its Checkbox and ToggleButton files are identical to the #11008 head
c0f4aca, so merge #11008 first.
Suggestions (non-blocking)
- A tap that is held for more than 200 ms sets the intent to
mouse. The intent helper ignores amousedownonly if it comes within 200 ms of the touch (validateTouchinwhatInput.ts). Browsers send the compatibilitymousedownafter the finger lifts. In Chromium with touch emulation, a tap held for 80 ms leftdata-whatintent="touch", and a tap held for 350 ms leftdata-whatintent="mouse"with the input still in:hover. On a phone this does not matter, because(any-hover: hover)does not match. On a device that also has a mouse or trackpad (a touchscreen laptop, an iPad with a trackpad), a slow tap brings the sticky hover back. I inferred that last step; my emulation cannot makeany-hovermatch together with touch. This lives in the shared helper, so it may fit better in #11053. True but rare.
What I checked
- Range-diff
d43b146..e361b1c: two new commits.git diff d43b146 e361b1cis empty. - Merge with
main53fa3bd: no conflicts,yarn.lockunchanged. The Chip folder,Checkbox.test.tsxandToggleButton.test.tsxpass 149 of 149. Two tests timed out under a load average of 74 and passed on a rerun with a longer timeout. Stylelint and Prettier pass on both style files. - Mouse hover, pressed and rest styles of all 81 enabled demo Chips, compared with
main, in Chromium, Firefox and WebKit (see above). The rest look matchesmain, apart from one Chip in Chromium. That one also differs on the control run without the prefix, so the prefix does not cause it. - CI on
e361b1c: the visual job fails on exactly the 12 Chipactivescreenshots (matches active states,matches error active statesandmatches dark error 'active' states, inui,sbanken,coconutandcarnegie). The other 761 screenshots in the run pass, including every Chip hover screenshot. This is the same defect as must-fix 1.
CI on e361b1c364 when I posted this: 23 checks passed; Run visual-regression tests failure. Run visual-regression tests fails on the 12 Chip active-state screenshots (4 themes x 3 tests). They show the hover look while pressed, which is the must-fix in this review.

Motivation: https://dnb-it.slack.com/archives/CMXABCHEY/p1795427065802309
On iOS Safari, and in other touch browsers, a Chip kept its hover styles (green ring and indicator colors) after being tapped, until something else was tapped. It's the same issue as reported for Switch in #11007.
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.Builds on #11008: the checkbox indicator inside a Chip also gets the Checkbox hover styles, so this branch includes that commit. Merge #11008 first. This diff then only contains the Chip changes.
Use together with #11053 for the shared hover behavior.
Before / after