Skip to content

fix(Input): prevent sticky hover border after tapping on touch devices - #11039

Open
langz wants to merge 8 commits into
mainfrom
fix/input-sticky-hover-touch
Open

langz wants to merge 8 commits into
mainfrom
fix/input-sticky-hover-touch

Conversation

@langz

@langz langz commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

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-whatintent tracking 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

An Input on a touch device after a tap, with the keyboard closed again. Before: it keeps the hover border. After: it shows the normal border.

An Autocomplete on a touch device after a tap on its label, with the keyboard closed again. Before: it keeps the hover border. After: it shows the normal border.

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.
langz

This comment was marked as outdated.

@langz

langz commented Nov 24, 2026 •

Copy link
Copy Markdown
Member Author

Why @media (hover: hover): touch browsers keep :hover on the last tapped element, so hover styles stay after a tap until the user taps somewhere else. The query tests whether the primary input can hover (MDN, in all browsers since 2018). So mouse and trackpad hover stay as they are, and phones and tablets never get the sticky state.

This is the industry standard: Tailwind CSS v4 applies its hover variant only inside @media (hover: hover) (upgrade guide), and Radix Themes and Mantine wrap their component hover styles the same way.

The :not([data-whatintent='touch']) check alone is not enough: a key press outside a text field, for example Tab or an arrow key, sets the intent to keyboard, so on a tablet with a keyboard the tapped control shows its hover style again (measured on Button, Tag, ToggleButton and Tabs). #11053 now shows hover only while the current input is a mouse (html[data-whatintent='mouse']). That also covers Chromebooks and touchscreen laptops, where (hover: hover) matches even though the user can tap. The trade-off: without Eufemia's JavaScript nothing sets data-whatintent, so these styles show no hover at all.

Both include the Input styles, which now use the touch intent check instead of @media (hover: hover).

@joakbjerk joakbjerk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 langz left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 on a597e03). 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. On main the 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): on 356bd0a the :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 to html:not(…) .eufemia-scope--portal .dnb-input__border:hover, and hover equals main.

Suggestions (non-blocking)

  1. 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) and html: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.
  2. For the planned specificity follow-up: html:where(:not([data-whatintent='touch'], [data-whatintent='keyboard'])) keeps html first. I ran it through postcss-isolated-style-scope, and the scope goes after html (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-action and --token-color-stroke-action-hover are 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 (.hover class from FormLabel), error hover and no-JS hover are identical to main in both engines.
  • Phone (Chromium, isMobile + hasTouch, (any-hover: none)): after a tap and blur, the border is 1px (on main it 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. stylelint and prettier pass 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.

This branch was successfully deployed

2 active deployments
Package preview — dbcfcdde Deployed Nov 24, 2026 by github-actions[bot]
Portal preview — dbcfcdde Deployed Nov 24, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants