Repository navigation
Conversation
Touch browsers keep :hover on the last tapped element, so a tapped Radio kept its hover colors and looked different from other checked radios 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 578330b: Approve (posted as a comment, because GitHub does not let the PR author approve their own PR)
578330b reverts 7d2d575, so the tree is identical to bffa29e, the head of the last review. I checked the specificity question this leaves, and touch, mouse and pressed behavior in real browsers. I found no defects. Tested merged with main at 541b379: the merge is clean.
Earlier findings
- Still deferred, as agreed: with a mouse, the pressed state of a Radio never shows. On this head and on
mainthe pressed look equals the hover look in 40 of 40 presses (Chromium). #11028 fixes it.
Suggestions (non-blocking)
- A mouse click on a form field, then a tap, can still leave the hover look (touchscreen laptops). The same
whatInput.tslimitation as in #11007: while a form input has focus, a tap does not updatedata-whatintent. In Chromium with a pointer that can hover and real touch taps, a Radio tapped after a mouse click on another Radio kept the hover look (intent: "mouse").mainis sticky in all cases, so this is not a regression.
What I checked
git diff bffa29e 578330bis empty, so the delta since the last review is zero.- Specificity: the hover rules go from (0,4,0) on
mainto (0,5,1). In all 6 shipped theme bundles, 4 of the 54 other rules on.dnb-radio__buttonand__dotchange winner. All 4 are disabled rules, which cannot match together with:not([disabled]). - Touch emulation, all 20 enabled Radios tapped twice each, in Chromium, Firefox and WebKit, at 390 px (mobile) and 1280 px (touch enabled):
mainkeeps the hover look on 40 of 40 taps, this PR on 0 of 40. A Tab press after a tap keeps the hover look off; onmainit stays. The touchscreen-laptop model in Chromium also gives 0 of 40. - Mouse hover in the same three browsers: the hover look of all 20 Radios, and hover after a click, are identical to
main. With JavaScript off, mouse hover still shows (Chromium, Firefox). Pressed looks equalmainin Chromium and Firefox (120 of 120 states). - Merge with
main(ecaa2f5, then541b379, which adds thewhatInput.tschange from #11052): main + #11007 + #11008 + #11028 (which contains the #11009 changes) together pass the Switch, Checkbox, Radio, ToggleButton andwhatInputtests, 198 of 198. Onecaa2f5alone: the Radio and ToggleButton tests pass 104 of 104. Stylelint and Prettier pass. CI's visual job ran 13 impacted screenshot files on this head, and they passed.
CI on 578330beab: all 23 checks passed. Rechecked just before posting: the head is still 578330b.
Motivation: https://dnb-it.slack.com/archives/CMXABCHEY/p1795427065802309
On iOS Safari, and in other touch browsers, a Radio kept its hover styles after being tapped, until something else was tapped. The tapped Radio then looked different from other checked radios (light green background and a different dot color). 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.Use together with #11053 for the shared hover behavior.
Before / after