Skip to content

fix(Textarea): prevent sticky hover border after tapping on touch devices - #11040

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

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

Conversation

@langz

@langz langz commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

On iOS Safari, and in other touch browsers, a Textarea 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 and for Input in #11039.

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.

Use together with #11053 for the shared hover behavior.

Before / after

A Textarea on a touch device after a tap, 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
Textarea kept its thick hover border after the user left the field,
until something else was tapped. Limit the hover styles to devices that
can hover. The focus border is unchanged.
langz

This comment was marked as outdated.

@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. Focus keeps the same border width, and mouse hover is unchanged. Two optional nits inline.

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

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.
Use one focus rule and one hover rule. The hover rule stays after the focus rule, so the hover border color still wins over the focus color.
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 9465eaa: Changes needed

The Textarea hover rule now applies only inside @media (any-hover: hover) and while the tracked intent is not touch or keyboard. The touch fix works. On this head, though, an error Textarea loses its red border on mouse hover. Tested merged with main at ecaa2f5 (clean merge).

Must fix

  1. An error Textarea turns green on mouse hover. The guard html:not([data-whatintent='touch'], [data-whatintent='keyboard']) adds (0,1,1) to the hover rule (dnb-textarea.scss:371-378). The hover rule is now (0,6,1). The error rule below it, .dnb-textarea__status--error .dnb-textarea__textarea:not([disabled]):not(.dnb-textarea--disabled) ~ .dnb-textarea__state, is (0,5,0). On main both rules were (0,5,0), so the later error rule kept the red border. Now the hover color wins over the error color. Commit 4d7accc fixed exactly this, and 9465eaa brought it back when it restored the html check. The compiled package CSS has the same order (Textarea.test.tsx.snap:547 and :553), so this is not only a portal effect.
    I verified it on the previews of main (d85af17f) and this head (ae7525ce), in Chromium and Firefox. I used the FormStatus demo with the mouse over the textarea. On main the border is rgb(213, 37, 37) 0 0 0 2px. On this head it is rgb(0, 114, 114) 0 0 0 2px. It is the same while the field has focus and the mouse is over it. As a control, the default Textarea gives identical results on main and this head.
    Suggested fix: add an error rule inside the same media block, after the hover rule, as Input does for __status--error … :hover. I checked that this rule restores the red 2px border on the head preview:
    html:not([data-whatintent='touch'], [data-whatintent='keyboard'])
      &__status--error
      &__textarea:not([disabled]):not(#{&}--disabled):hover
      ~ &__state {
      --textarea-color-border: var(--token-color-stroke-error);
    }

Before (main), after (this PR) and this PR with the suggested rule: the error Textarea under mouse hover. Only "After" has a green border.

Earlier findings

  • Resolved: both nits from the earlier approval on ebd4eee. The comment above the focus rule now says // focus, and the repeated focus and hover rules are merged into one each (77d672f). The hover rule still comes after the focus rule.
  • Still holds: the earlier review said the focus border is unchanged. With focus and the mouse away, the border is rgb(20, 85, 90) 0 0 0 2px on both main and this head.

What I checked

  • Mouse (Chromium, Firefox): the default Textarea shows the same rest, hover, focus + hover and focus colors as main. The error Textarea differs only under hover (see above).
  • Phone (Chromium, isMobile + hasTouch): after a tap and blur, the default and error borders are 1px. On main they keep the 2px hover border.
  • Touchscreen laptop (desktop Chromium, where (any-hover: hover) matches, plus CDP touch input): after a tap, blur and Tab, the border is 1px. Moving the mouse brings the 2px hover border back. On main it stays 2px after the tap.
  • Pressed state: Textarea has no :active rule, so the error rule above is the only one that the higher hover specificity overrides. I compared every rule after the hover rule in dnb-textarea.scss.
  • Unit tests on the merge with main (ecaa2f5): Textarea.test.tsx, 47 of 47 passed. The style snapshot does not catch the error-hover case, because it only records the selectors.
  • Not covered: WebKit and real iOS Safari.

CI on 9465eaaa7c: all 23 checks passed. Rechecked just before posting: the head is still 9465eaa, and a real trial merge with main at 541b379 (which now includes #11052) has no conflicts.

This branch was successfully deployed

2 active deployments
Package preview — 9465eaaa Deployed Nov 24, 2026 by github-actions[bot]
Portal preview — 9465eaaa 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