Repository navigation
Conversation
Touch browsers keep :hover on the last tapped element, so a tapped Input kept its thick hover border after the user left the field, until something else was tapped. A tap on the label did the same, because FormLabel adds the hover class to the field. The Autocomplete label hover rule had the same issue. Limit these hover styles to devices that can hover.
|
Why This is the industry standard: Tailwind CSS v4 applies its The |
Both include the Input styles, which now use the touch intent check instead of @media (hover: hover).
joakbjerk
left a comment
There was a problem hiding this comment.
Looks good. The DatePicker and InputMasked style snapshots now match the new selectors (the style snapshot tests pass locally at this commit). Hover on the field, label and file button now follows mouse intent, the same approach as #11053.
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 dbcfcdd: Approve (posted as a comment, because GitHub does not let the PR author approve their own PR)
The Input and Autocomplete-label hover rules now apply only inside @media (any-hover: hover) and while the tracked intent is not touch or keyboard. I found no defects on the current head. Tested merged with main at ecaa2f5 (clean merge).
Earlier findings
- Resolved: touchscreen laptops behaved as on
main(earlier review ona597e03). In desktop Chromium, where(any-hover: hover)matches, a real touch tap (CDP touch events) now leaves the normal 1px border after blur and after Tab. Moving the mouse brings hover back. Onmainthe 2px hover border stays. - Resolved: the error state was not tested at runtime. Mouse hover on the error Input is 2px red on head and on
main, in Chromium and Firefox. - Resolved (by
dbcfcdd): on356bd0athe:where(html…)guard compiled to.eufemia-scope--portal :where(html…)in scoped builds. That selector can never match. On that preview (2e130791) mouse hover showed no hover border at all (default, error, label and no-JS cases). On the current preview (94f87825) the guard compiles tohtml:not(…) .eufemia-scope--portal .dnb-input__border:hover, and hover equalsmain.
Suggestions (non-blocking)
- The PR comment "Why
@media (hover: hover)" no longer matches the code. It describes(hover: hover),html[data-whatintent='mouse']and "without Eufemia's JavaScript … no hover at all". The code uses(any-hover: hover)andhtml:not([data-whatintent='touch'], [data-whatintent='keyboard']). With JavaScript turned off I measured the normal 2px hover border. Readers of the PR get the wrong picture, so I suggest updating or hiding that comment. - For the planned specificity follow-up:
html:where(:not([data-whatintent='touch'], [data-whatintent='keyboard']))keepshtmlfirst. I ran it throughpostcss-isolated-style-scope, and the scope goes afterhtml(html:where(…) .eufemia-scope--portal .dnb-input__border:hover). It adds only (0,0,1) to each rule instead of (0,1,1). Today the extra specificity makes the hover rule outrank.dnb-input__border:has(.dnb-input__input:autofill). That causes no visible change, because--token-color-stroke-actionand--token-color-stroke-action-hoverare equal in ui, sbanken, eiendom and carnegie (measured with a cloned autofill rule).
What I checked
- Real browsers on the previews of
main(d85af17f) and this head (94f87825). I tested Chromium and Firefox for mouse use, and Chromium for touch. WebKit timed out while loading the portal on this machine. - Mouse: rest, hover, label hover (
.hoverclass from FormLabel), error hover and no-JS hover are identical tomainin both engines. - Phone (Chromium,
isMobile+hasTouch,(any-hover: none)): after a tap and blur, the border is 1px (onmainit is 2px). While focused it shows the active border, not the hover border. - Touchscreen laptop (desktop Chromium plus CDP touch input): the result is under "Earlier findings". With keyboard focus after Shift+Tab, the focus border shows.
- Trade-off, by design: on a desktop, a key press while focus is outside a form field (for example Escape) hides the hover border until the mouse moves. Typing inside a field does not change the intent.
- Autocomplete: mouse hover on the label gives the 2px border on head and on
main. - Unit tests on the merge with
main(53fa3bd): Input, Autocomplete, DatePicker and InputMasked, 720 tests. Two style tests timed out at 10 s under a load average of 56. They pass when rerun alone. The changed style snapshots only add the media query and the intent guard. - Real trial merge with
ecaa2f5: clean. Main's new commits do not touch Input.stylelintandprettierpass on both changed SCSS files. - Not covered: the file input button hover (there is no demo of it), Safari on a real iPad, and an iPad with a trackpad.
CI on dbcfcdde15 when I posted this: 22 checks passed; Run visual-regression tests cancelled. Run visual-regression tests never ran on this head: GitHub did not assign a runner, and it was cancelled after 84 minutes with no steps. It needs a re-run before merge. Rechecked just before posting: the head is still dbcfcdd, and a real trial merge with main at 541b379 (which now includes #11052) has no conflicts. I also checked the pressed state, because the same prefix breaks it in #11010, #11025, #11044 and #11049. In Input, the only :active rule that the hover rule now outranks is the file button's (dnb-input.scss:136). In Chromium, its rest, hover and pressed colors are the same on main and on this PR, so I see no visible change.
On iOS Safari, and in other touch browsers, an Input kept its thick hover border after being tapped, even after the user left the field, 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.The DatePicker and InputMasked style snapshots change too, because they include the Input styles.
Use together with #11053 for the shared hover behavior.
Before / after