Skip to content

fix(DatePicker): prevent sticky month button hover after tapping on touch devices - #11047

Open
langz wants to merge 7 commits into
mainfrom
fix/date-picker-sticky-hover-touch
Open

langz wants to merge 7 commits into
mainfrom
fix/date-picker-sticky-hover-touch

Conversation

@langz

@langz langz commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

On iOS Safari, and in other touch browsers, the next and previous month buttons in the DatePicker calendar kept a border after being tapped, until something else was tapped. Users often tap these buttons several times in a row, so the border stayed while they changed month. 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.

Use together with #11053 for the shared hover behavior.

Before / after

The DatePicker month navigation on a touch device after one tap on next month. Before: the button keeps the green hover ring. After: it shows the normal arrow button.

…evices

Touch browsers keep :hover on the last tapped element. The month
buttons in the calendar header hide their border while they aren't
hovered, so a tapped button kept its border until something else was
tapped, also while the user kept tapping it to change month. On devices
that can't hover, style a tapped button like one without the mouse over
it, and limit the hover background to devices that can hover. Days
inside a selected range get the same treatment.
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.

@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. Tapped month buttons and selected-range days now look the same as at rest, and mouse hover, the pressed style and the focus ring are unchanged. Matches the mouse-intent hover approach in #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.

Rules that make a tapped element look as at rest now apply exactly
when hover styles are off: on devices that cannot hover, and while the
tracked input is touch or keyboard. Before, they also applied when no
input had been tracked yet, for example without JavaScript, and then
cancelled part of the hover style.
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 4ae163c: Approve (posted as a comment, because GitHub does not let the PR author approve their own PR)

The DatePicker month buttons and the days inside a selected range no longer keep their hover look after a tap. Mouse hover, the pressed style and keyboard focus are unchanged. Unlike #11044, these hover rules raise their specificity without side effects: on main, the day rules already had the html:not(...) prefix, and the month-button rule beats nothing new. Tested merged with main at ecaa2f5.

Earlier findings

  • Resolved: days inside a selected range, which the first review did not test at runtime. With touch intent, a hovered range day is now transparent, the same as at rest. On main it shows a white button. With mouse intent, it keeps main's white button and 2px border.

Suggestions (non-blocking)

  1. Merge this after #11053, or together with it. On its own, this PR turns off the DatePicker's hover rule while the intent is keyboard, but Button's own secondary hover still applies. A month button that still has :hover then shows Button's light green background (rgb(216, 243, 236)) without a border. On main it shows the white hover button with the 2px border. A key press sets keyboard intent: I checked that Tab does this on the main preview. Merged with #11053 (29f8a22), the same state shows the button at rest. This is the "switching to the keyboard" case in the description.
  2. The two reset rules (dnb-date-picker.scss:429 and :562) use html:not([data-whatintent='mouse']), but the hover rules use "not touch and not keyboard". While the intent is initial, or the attribute is missing, a hovered month button gets the hover background but loses its border. 1296ade had aligned the two conditions. This is rare, because the first mouse move sets mouse.

What I checked

  • Real DatePicker markup: I copied an inline range picker (2 months, 4 month buttons, 42 range days) from the main preview. I styled it with CSS that I compiled from origin/main and from 4ae163c with the UI theme. Then I measured rest, hover and pressed states for mouse, touch, keyboard and no intent.
    • Month button: touch removes the sticky 1px ring. Mouse hover is unchanged: white with a 2px border. Pressed is unchanged.
    • Disabled month button: unchanged in every state.
    • Start date, end date, and a plain day outside the range: unchanged.
    • I checked this in Chromium (all cases), and in Firefox and WebKit (month button and range day, mouse and keyboard intent).
  • A keyboard-focused month button that the mouse then hovers: the same computed style as main, in Chromium and Firefox.
  • The higher specificity of the month-button hover rule changes no pressed, disabled or focus result compared with main.
  • Scoped builds: the html:not(...) .dnb-date-picker__header__nav shape keeps html in front of the scope class, so it still matches.
  • Trial merge with ecaa2f5 (a real git merge --no-commit): no conflicts. DatePicker.test.tsx passes on the merge: 326 tests.
  • CI on 4ae163c: the visual job ran 13 screenshot files, including DatePicker.screenshot.test.ts. They pass: 110 tests.
  • stylelint and prettier --check on dnb-date-picker.scss: clean.

CI on 4ae163c736: all 23 checks passed. Rechecked just before posting: the head is still 4ae163c, 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 — 4ae163c7 Deployed Nov 24, 2026 by github-actions[bot]
Portal preview — 4ae163c7 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