Repository navigation
Conversation
…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.
|
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. 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
left a comment
There was a problem hiding this comment.
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)
- 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:hoverthen 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 setskeyboardintent: 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. - The two reset rules (
dnb-date-picker.scss:429and:562) usehtml:not([data-whatintent='mouse']), but the hover rules use "not touch and not keyboard". While the intent isinitial, or the attribute is missing, a hovered month button gets the hover background but loses its border.1296adehad aligned the two conditions. This is rare, because the first mouse move setsmouse.
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/mainand from4ae163cwith the UI theme. Then I measured rest, hover and pressed states formouse,touch,keyboardand 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__navshape keepshtmlin front of the scope class, so it still matches. - Trial merge with
ecaa2f5(a realgit merge --no-commit): no conflicts.DatePicker.test.tsxpasses on the merge: 326 tests. - CI on
4ae163c: the visual job ran 13 screenshot files, includingDatePicker.screenshot.test.ts. They pass: 110 tests. stylelintandprettier --checkondnb-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.
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-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