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>
|
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 c0f4aca: Approve (posted as a comment, because GitHub does not let the PR author approve their own PR)
c0f4aca reverts ffd2ef7, so the tree is identical to 785e50d, the head of the last review. I checked the one open question this leaves: the guard raises the hover rules from (0,5,0) to (0,6,1), and I found no state where that changes the look. Tested merged with main at 541b379: the merge is clean.
Earlier findings
- Still deferred, as agreed: the Chip ring after a tap in
Field.Togglecomes from the Chip styles and is handled in #11010.
Suggestions (non-blocking)
- A mouse click on a form field, then a tap, can still leave the hover look (touchscreen laptops). This is the same
whatInput.tslimitation as in #11007: while a form input has focus, a tap updatesdata-whatinputbut notdata-whatintent. In Chromium with a pointer that can hover and real touch taps, a Checkbox tapped after a mouse click on another Checkbox kept the hover look (intent: "mouse"). A tap after a click on the page background was correct.mainis sticky in all cases, so this is not a regression.
What I checked
git diff 785e50d c0f4acais empty, so the delta since the last review is zero.- Specificity. I listed every rule in all 6 shipped theme bundles that targets
.dnb-checkbox__button,__gfxor__indeterminateand sets a property that a hover rule also sets: 92 rules against 7 hover rules. 17 pairs change winner because of the higher specificity. In 15 of them, the two rules cannot match at the same time (:activeagainst:not(:active), disabled against:not([disabled]), or ToggleButton, whose inner input haspointer-events: none). The other 2 need an indeterminate Chip that has keyboard focus while the mouse hovers it and the tracked intent is not keyboard. I did not test that combination in a browser, and I consider it negligible. - Pressed look with a real mouse, on all 18 enabled Checkbox demos, pressing on the box and on the label, in Chromium and Firefox: identical to
main(108 of 108 states). Control: when I remove only:not(:active)from the loaded hover rules, the pressed look becomes the hover look in 36 of 36 presses, and the check reports all of them. - Touch emulation, every enabled Checkbox tapped twice, in Chromium, Firefox and WebKit, at 390 px (mobile) and 1280 px (touch enabled):
mainkeeps the hover look on 36 of 36 taps, this PR on 0 of 36. A Tab press after a tap keeps the hover look off; onmainit stays. The touchscreen-laptop model in Chromium gives 0 of 36 as well. - Mouse hover in the same three browsers: the hover look of all 18 Checkboxes, and hover after a click, are identical to
main. With JavaScript off, mouse hover still shows (Chromium, Firefox). - CI gap: the visual-regression job has not run on this tree. It was cancelled in the queue, with no runner and no steps, on
785e50d,ffd2ef7andc0f4aca. So CI has not compared the Checkbox hover screenshots for the new guard. My browser checks above cover the computed hover look, but a re-run of that job should pass before merge. - Merge with
main(ecaa2f5, then541b379, which adds thewhatInput.tschange from #11052): main + #11007 + #11008 + #11028 together pass the Switch, Checkbox, Radio, ToggleButton andwhatInputtests, 198 of 198. Onecaa2f5alone:Checkbox.test.tsx,ToggleButton.test.tsxand the Checkbox style tests pass 94 of 94. Stylelint and Prettier pass. The shipped CSS keepshtmlin front of the scope class (html:not(...) .eufemia-scope--portal .dnb-checkbox__input...), so the hover rules match in scoped builds.
CI on c0f4aca2a6 when I posted this: 22 checks passed; Run visual-regression tests cancelled. The visual-regression job was cancelled while queued (no runner, no steps) on this head and on the two earlier heads with the same Checkbox styles, so it never compared the Checkbox screenshots. It needs a re-run; it is not a failure of this change. Rechecked just before posting: the head is still c0f4aca.
Motivation: https://dnb-it.slack.com/archives/CMXABCHEY/p1795427065802309
On iOS Safari, and in other touch browsers, a Checkbox kept its hover styles (green border and background) after being tapped, until something else was tapped. It's the same issue as reported for Switch in #11007, so the tapped Checkbox looked different from the others in the same state.
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