From dbe2ee3345be7072574a315a14641faad854b1b0 Mon Sep 17 00:00:00 2001 From: Anders Langseth Date: Mon, 23 Nov 2026 13:28:07 +0100 Subject: [PATCH 1/9] Document how to keep hover styles from sticking on touch devices Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../development-guidelines/for-styling.mdx | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx b/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx index 1020dfb6ffe4..9749b2df9d3f 100644 --- a/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx +++ b/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx @@ -82,6 +82,28 @@ For the "logical" groups we recommend the following rational order principle: You may check out this [Prettier Plugin](https://www.npmjs.com/package/prettier-plugin-rational-order) for handling it automatic with [prettier](https://prettier.io/). +## Hover styles + +Touch browsers keep `:hover` on the last tapped element until something else is tapped. Hover styles then stay visible, and can make a control look checked or selected when it isn't. + +- Put hover styles inside `@media (hover: hover)`, so they only apply on devices that can hover. +- Keep pressed (`:active`) and focus styles outside of it, so touch users still get feedback. +- Add `:not(:active)` to hover selectors, so hover styles don't hide the pressed style. + +```scss +.my-toggle { + @media (hover: hover) { + &:hover:not(:active) { + border-color: var(--token-color-stroke-action-hover); + } + } + + &:active { + border-color: var(--token-color-stroke-action-pressed); + } +} +``` + ## CSS Units Here is a list of what we should use as layout and styling units to embrace the best possible accessibility experience and visual correctness. From d030c8c4d13c735d1bc179dd4b825b73f4a2ea0c Mon Sep 17 00:00:00 2001 From: Anders Langseth Date: Mon, 23 Nov 2026 15:05:39 +0100 Subject: [PATCH 2/9] Separate the reasons for keeping pressed and focus styles outside the hover query Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../src/docs/web/development-guidelines/for-styling.mdx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx b/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx index 9749b2df9d3f..1bf04bb7428a 100644 --- a/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx +++ b/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx @@ -87,7 +87,8 @@ You may check out this [Prettier Plugin](https://www.npmjs.com/package/prettier- Touch browsers keep `:hover` on the last tapped element until something else is tapped. Hover styles then stay visible, and can make a control look checked or selected when it isn't. - Put hover styles inside `@media (hover: hover)`, so they only apply on devices that can hover. -- Keep pressed (`:active`) and focus styles outside of it, so touch users still get feedback. +- Keep pressed (`:active`) styles outside of it, so touch users still get feedback when they tap. +- Keep focus styles outside of it too, so keyboard users see focus on every device. - Add `:not(:active)` to hover selectors, so hover styles don't hide the pressed style. ```scss From 8dee0977994c4933040ce4ede8e13433ba8be644 Mon Sep 17 00:00:00 2001 From: Anders Langseth Date: Tue, 24 Nov 2026 11:26:03 +0100 Subject: [PATCH 3/9] Explain how to keep focus styles that exclude :hover visible on touch devices A tapped element keeps :hover on touch devices, so a focus style with :not(:hover) does not show when the user comes back to it with the keyboard. Add a bullet that tells how to avoid that, as done in #11025, #11042, #11043, #11048 and #11049. --- .../src/docs/web/development-guidelines/for-styling.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx b/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx index 1bf04bb7428a..e57df2a5b563 100644 --- a/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx +++ b/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx @@ -89,6 +89,7 @@ Touch browsers keep `:hover` on the last tapped element until something else is - Put hover styles inside `@media (hover: hover)`, so they only apply on devices that can hover. - Keep pressed (`:active`) styles outside of it, so touch users still get feedback when they tap. - Keep focus styles outside of it too, so keyboard users see focus on every device. +- If a focus style excludes hovered elements with `:not(:hover)`, add the same focus style without `:not(:hover)` inside `@media (hover: none)`. A tapped element keeps `:hover`, so the focus style would not show when the user comes back to it with the keyboard. - Add `:not(:active)` to hover selectors, so hover styles don't hide the pressed style. ```scss From 1f1ba81810d15681d1a9710540f97e0fe9ad59c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B8egh?= Date: Tue, 24 Nov 2026 14:19:13 +0100 Subject: [PATCH 4/9] Explain hover styles using the current input intent --- .../development-guidelines/for-styling.mdx | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx b/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx index e57df2a5b563..188d2dbf7b02 100644 --- a/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx +++ b/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx @@ -84,28 +84,35 @@ You may check out this [Prettier Plugin](https://www.npmjs.com/package/prettier- ## Hover styles -Touch browsers keep `:hover` on the last tapped element until something else is tapped. Hover styles then stay visible, and can make a control look checked or selected when it isn't. +Touch browsers can keep `:hover` on the last tapped element until something else is tapped. Hover styles then stay visible, and can make a control look checked or selected when it isn't. -- Put hover styles inside `@media (hover: hover)`, so they only apply on devices that can hover. -- Keep pressed (`:active`) styles outside of it, so touch users still get feedback when they tap. -- Keep focus styles outside of it too, so keyboard users see focus on every device. -- If a focus style excludes hovered elements with `:not(:hover)`, add the same focus style without `:not(:hover)` inside `@media (hover: none)`. A tapped element keeps `:hover`, so the focus style would not show when the user comes back to it with the keyboard. -- Add `:not(:active)` to hover selectors, so hover styles don't hide the pressed style. +Use the shared `utilities.hover()` mixin, as Button does. It checks `data-whatintent` on `` and shows hover styles when the tracked intent is `mouse`. A tap hides them, a key press keeps them hidden, and using the mouse brings them back. Eufemia sets these attributes through its shared input tracking. Typing in a form field preserves pointer intent so it does not change the surrounding hover styling. + +[`@media (hover: hover)`](https://www.w3.org/TR/mediaqueries-4/#hover) describes whether the primary pointer can hover. On a laptop with a touchscreen and a mouse, it can remain true while the touchscreen is being used. Browsers may update the query when the primary pointer changes, but it does not track every switch between touch, keyboard and mouse. `any-hover` also describes a capability, rather than the current input. + +- Keep pressed (`:active`) styles outside the hover mixin, so touch users still get feedback when they tap. +- Keep focus styles outside it too, so keyboard users see focus on every device. +- If a focus style excludes hovered elements with `:not(:hover)`, also show it when the tracked intent is not `mouse`. A tapped element can keep `:hover` when the user returns with the keyboard. +- Add `:not(:active)` inside the hover mixin when needed to keep hover styles from hiding the pressed style. ```scss +@use '@dnb/eufemia/style/core/utilities.scss' as utilities; + .my-toggle { - @media (hover: hover) { - &:hover:not(:active) { + @include utilities.hover() { + &:not(:active) { border-color: var(--token-color-stroke-action-hover); } } - &:active { + @include utilities.active() { border-color: var(--token-color-stroke-action-pressed); } } ``` +For custom selectors that cannot use the mixin, use `html[data-whatintent='mouse'] &:hover`. Keep this guard beside other input guards instead of nesting them, so they refer to the same `` element. + ## CSS Units Here is a list of what we should use as layout and styling units to embrace the best possible accessibility experience and visual correctness. From 1430d477d6208d287a9316f06dec7522a4159547 Mon Sep 17 00:00:00 2001 From: Anders Langseth Date: Tue, 24 Nov 2026 14:21:24 +0100 Subject: [PATCH 5/9] Describe the mouse intent hover pattern @media (hover: hover) describes the primary pointer, so it doesn't prevent sticky hover on devices with both a touchscreen and a mouse or touchpad. Recommend the hover mixin and the data-whatintent check that the components use, and show how to keep focus styles visible after a tap. --- .../development-guidelines/for-styling.mdx | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx b/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx index 188d2dbf7b02..79321daf593c 100644 --- a/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx +++ b/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx @@ -84,35 +84,42 @@ You may check out this [Prettier Plugin](https://www.npmjs.com/package/prettier- ## Hover styles -Touch browsers can keep `:hover` on the last tapped element until something else is tapped. Hover styles then stay visible, and can make a control look checked or selected when it isn't. +Touch browsers keep `:hover` on the last tapped element until something else is tapped. Hover styles then stay visible, and can make a control look checked or selected when it isn't. `@media (hover: hover)` doesn't prevent this on devices with both a touchscreen and a mouse or touchpad, such as touchscreen laptops and Chromebooks, because it describes the primary pointer. -Use the shared `utilities.hover()` mixin, as Button does. It checks `data-whatintent` on `` and shows hover styles when the tracked intent is `mouse`. A tap hides them, a key press keeps them hidden, and using the mouse brings them back. Eufemia sets these attributes through its shared input tracking. Typing in a form field preserves pointer intent so it does not change the surrounding hover styling. +- Use the `hover` mixin from `utilities.scss`. It applies hover styles only while the user uses a mouse (`html[data-whatintent='mouse']`), so a tap or a key press does not leave them on. +- For a hover selector the mixin can't wrap, prefix it with `html[data-whatintent='mouse']`. +- Keep pressed (`:active`) styles outside of it, so touch users still get feedback when they tap. +- Keep focus styles outside of it too, so keyboard users see focus on every device. +- If a focus style excludes hovered elements with `:not(:hover)`, add the same focus style for `html:where(:not([data-whatintent='mouse']))`. A tapped element keeps `:hover`, so the focus style would not show when the user comes back to it with the keyboard. +- Add `:not(:active)` to hover selectors, so hover styles don't hide the pressed style. -[`@media (hover: hover)`](https://www.w3.org/TR/mediaqueries-4/#hover) describes whether the primary pointer can hover. On a laptop with a touchscreen and a mouse, it can remain true while the touchscreen is being used. Browsers may update the query when the primary pointer changes, but it does not track every switch between touch, keyboard and mouse. `any-hover` also describes a capability, rather than the current input. - -- Keep pressed (`:active`) styles outside the hover mixin, so touch users still get feedback when they tap. -- Keep focus styles outside it too, so keyboard users see focus on every device. -- If a focus style excludes hovered elements with `:not(:hover)`, also show it when the tracked intent is not `mouse`. A tapped element can keep `:hover` when the user returns with the keyboard. -- Add `:not(:active)` inside the hover mixin when needed to keep hover styles from hiding the pressed style. +Eufemia's JavaScript sets `data-whatintent` on the `html` element. Without it, these hover styles don't apply. ```scss @use '@dnb/eufemia/style/core/utilities.scss' as utilities; .my-toggle { - @include utilities.hover() { + @include utilities.hover { &:not(:active) { border-color: var(--token-color-stroke-action-hover); } } - @include utilities.active() { + &:active { border-color: var(--token-color-stroke-action-pressed); } + + &:focus-visible:not(:hover) { + @include utilities.focusOutline(); + } + + // A tapped element keeps :hover + html:where(:not([data-whatintent='mouse'])) &:focus-visible { + @include utilities.focusOutline(); + } } ``` -For custom selectors that cannot use the mixin, use `html[data-whatintent='mouse'] &:hover`. Keep this guard beside other input guards instead of nesting them, so they refer to the same `` element. - ## CSS Units Here is a list of what we should use as layout and styling units to embrace the best possible accessibility experience and visual correctness. From 0445b543bac8c584a2a453f7f6c14c88cd8c4337 Mon Sep 17 00:00:00 2001 From: Anders Langseth Date: Tue, 24 Nov 2026 14:22:52 +0100 Subject: [PATCH 6/9] Restore the hover styles section from the previous commit The previous commit replaced a more complete version of this section. --- .../development-guidelines/for-styling.mdx | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx b/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx index 79321daf593c..188d2dbf7b02 100644 --- a/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx +++ b/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx @@ -84,42 +84,35 @@ You may check out this [Prettier Plugin](https://www.npmjs.com/package/prettier- ## Hover styles -Touch browsers keep `:hover` on the last tapped element until something else is tapped. Hover styles then stay visible, and can make a control look checked or selected when it isn't. `@media (hover: hover)` doesn't prevent this on devices with both a touchscreen and a mouse or touchpad, such as touchscreen laptops and Chromebooks, because it describes the primary pointer. +Touch browsers can keep `:hover` on the last tapped element until something else is tapped. Hover styles then stay visible, and can make a control look checked or selected when it isn't. -- Use the `hover` mixin from `utilities.scss`. It applies hover styles only while the user uses a mouse (`html[data-whatintent='mouse']`), so a tap or a key press does not leave them on. -- For a hover selector the mixin can't wrap, prefix it with `html[data-whatintent='mouse']`. -- Keep pressed (`:active`) styles outside of it, so touch users still get feedback when they tap. -- Keep focus styles outside of it too, so keyboard users see focus on every device. -- If a focus style excludes hovered elements with `:not(:hover)`, add the same focus style for `html:where(:not([data-whatintent='mouse']))`. A tapped element keeps `:hover`, so the focus style would not show when the user comes back to it with the keyboard. -- Add `:not(:active)` to hover selectors, so hover styles don't hide the pressed style. +Use the shared `utilities.hover()` mixin, as Button does. It checks `data-whatintent` on `` and shows hover styles when the tracked intent is `mouse`. A tap hides them, a key press keeps them hidden, and using the mouse brings them back. Eufemia sets these attributes through its shared input tracking. Typing in a form field preserves pointer intent so it does not change the surrounding hover styling. -Eufemia's JavaScript sets `data-whatintent` on the `html` element. Without it, these hover styles don't apply. +[`@media (hover: hover)`](https://www.w3.org/TR/mediaqueries-4/#hover) describes whether the primary pointer can hover. On a laptop with a touchscreen and a mouse, it can remain true while the touchscreen is being used. Browsers may update the query when the primary pointer changes, but it does not track every switch between touch, keyboard and mouse. `any-hover` also describes a capability, rather than the current input. + +- Keep pressed (`:active`) styles outside the hover mixin, so touch users still get feedback when they tap. +- Keep focus styles outside it too, so keyboard users see focus on every device. +- If a focus style excludes hovered elements with `:not(:hover)`, also show it when the tracked intent is not `mouse`. A tapped element can keep `:hover` when the user returns with the keyboard. +- Add `:not(:active)` inside the hover mixin when needed to keep hover styles from hiding the pressed style. ```scss @use '@dnb/eufemia/style/core/utilities.scss' as utilities; .my-toggle { - @include utilities.hover { + @include utilities.hover() { &:not(:active) { border-color: var(--token-color-stroke-action-hover); } } - &:active { + @include utilities.active() { border-color: var(--token-color-stroke-action-pressed); } - - &:focus-visible:not(:hover) { - @include utilities.focusOutline(); - } - - // A tapped element keeps :hover - html:where(:not([data-whatintent='mouse'])) &:focus-visible { - @include utilities.focusOutline(); - } } ``` +For custom selectors that cannot use the mixin, use `html[data-whatintent='mouse'] &:hover`. Keep this guard beside other input guards instead of nesting them, so they refer to the same `` element. + ## CSS Units Here is a list of what we should use as layout and styling units to embrace the best possible accessibility experience and visual correctness. From 3e650857faef0113a6d9d56526bcb33cb31ed893 Mon Sep 17 00:00:00 2001 From: Anders Langseth Date: Tue, 24 Nov 2026 15:27:43 +0100 Subject: [PATCH 7/9] Describe the any-hover base of the hover mixin The mixin now applies hover styles inside @media (any-hover: hover) unless the current input is touch or keyboard. Explain why any-hover is used instead of hover, and what happens before the input tracking starts. --- .../src/docs/web/development-guidelines/for-styling.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx b/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx index 188d2dbf7b02..7a6dad97907f 100644 --- a/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx +++ b/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx @@ -86,9 +86,9 @@ You may check out this [Prettier Plugin](https://www.npmjs.com/package/prettier- Touch browsers can keep `:hover` on the last tapped element until something else is tapped. Hover styles then stay visible, and can make a control look checked or selected when it isn't. -Use the shared `utilities.hover()` mixin, as Button does. It checks `data-whatintent` on `` and shows hover styles when the tracked intent is `mouse`. A tap hides them, a key press keeps them hidden, and using the mouse brings them back. Eufemia sets these attributes through its shared input tracking. Typing in a form field preserves pointer intent so it does not change the surrounding hover styling. +Use the shared `utilities.hover()` mixin, as Button does. It shows hover styles only on devices with a pointer that can hover (`@media (any-hover: hover)`), and not while the current input is touch or keyboard. Eufemia's shared input tracking sets `data-whatintent` on ``: a tap hides hover styles, a key press keeps them hidden, and using the mouse brings them back. Typing in a form field preserves pointer intent so it does not change the surrounding hover styling. Before the input tracking has started, or without Eufemia's JavaScript, the media query alone decides. -[`@media (hover: hover)`](https://www.w3.org/TR/mediaqueries-4/#hover) describes whether the primary pointer can hover. On a laptop with a touchscreen and a mouse, it can remain true while the touchscreen is being used. Browsers may update the query when the primary pointer changes, but it does not track every switch between touch, keyboard and mouse. `any-hover` also describes a capability, rather than the current input. +[`@media (hover: hover)`](https://www.w3.org/TR/mediaqueries-4/#hover) describes whether the primary pointer can hover. On a laptop with a touchscreen and a mouse, it can remain true while the touchscreen is being used. On an iPad with a trackpad, or an Android tablet with a mouse, it is false. `any-hover` is true when any connected pointer can hover, so the mixin uses it. Both describe a capability rather than the current input, so the mixin also checks the tracked input to follow each switch between touch, keyboard and mouse. - Keep pressed (`:active`) styles outside the hover mixin, so touch users still get feedback when they tap. - Keep focus styles outside it too, so keyboard users see focus on every device. @@ -111,7 +111,7 @@ Use the shared `utilities.hover()` mixin, as Button does. It checks `data-whatin } ``` -For custom selectors that cannot use the mixin, use `html[data-whatintent='mouse'] &:hover`. Keep this guard beside other input guards instead of nesting them, so they refer to the same `` element. +For custom selectors that cannot use the mixin, put the rule inside `@media (any-hover: hover)` and use `html:not([data-whatintent='touch'], [data-whatintent='keyboard']) &:hover`. Keep this guard beside other input guards instead of nesting them, so they refer to the same `` element. ## CSS Units From 866f395bc34f543230aa7e3b6041b08321b1142b Mon Sep 17 00:00:00 2001 From: Anders Langseth Date: Tue, 24 Nov 2026 17:04:23 +0100 Subject: [PATCH 8/9] Explain how custom hover rules keep their specificity Recommend :where() around the hover check for custom selectors, so pressed, disabled and error styles still win over hover. Add a bullet for resting styles that exclude :hover: they must apply exactly where hover styles are off. --- .../src/docs/web/development-guidelines/for-styling.mdx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx b/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx index 7a6dad97907f..6513adf32d42 100644 --- a/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx +++ b/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx @@ -93,6 +93,7 @@ Use the shared `utilities.hover()` mixin, as Button does. It shows hover styles - Keep pressed (`:active`) styles outside the hover mixin, so touch users still get feedback when they tap. - Keep focus styles outside it too, so keyboard users see focus on every device. - If a focus style excludes hovered elements with `:not(:hover)`, also show it when the tracked intent is not `mouse`. A tapped element can keep `:hover` when the user returns with the keyboard. +- If a resting style excludes hovered elements with `:not(:hover)`, give a tapped element that style only where hover styles are off: inside `@media (any-hover: none)`, and with `html:is([data-whatintent='touch'], [data-whatintent='keyboard'])`. With `:not([data-whatintent='mouse'])` it would also cancel hover styles before the input tracking has started. - Add `:not(:active)` inside the hover mixin when needed to keep hover styles from hiding the pressed style. ```scss @@ -111,7 +112,7 @@ Use the shared `utilities.hover()` mixin, as Button does. It shows hover styles } ``` -For custom selectors that cannot use the mixin, put the rule inside `@media (any-hover: hover)` and use `html:not([data-whatintent='touch'], [data-whatintent='keyboard']) &:hover`. Keep this guard beside other input guards instead of nesting them, so they refer to the same `` element. +For custom selectors that cannot use the mixin, put the rule inside `@media (any-hover: hover)` and prefix it with `:where(html:not([data-whatintent='touch'], [data-whatintent='keyboard']))`. The `:where()` keeps the specificity of the plain `:hover` rule, so pressed, disabled and error styles still win over it. If the selector already starts with `html`, add the check to that element as `html:where(:not([data-whatintent='touch'], [data-whatintent='keyboard']))`, so all input checks refer to the same `` element. ## CSS Units From fabd9cd2cff2cc38b0279850b7ba34b9ff4bad89 Mon Sep 17 00:00:00 2001 From: Anders Langseth Date: Tue, 24 Nov 2026 17:29:59 +0100 Subject: [PATCH 9/9] Restore the custom hover selector advice The :where(html...) form breaks in scoped builds, where the scope class ends up before the html element. Restore the previous text until a form that keeps the specificity also works with style scoping. --- .../src/docs/web/development-guidelines/for-styling.mdx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx b/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx index 6513adf32d42..7a6dad97907f 100644 --- a/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx +++ b/packages/dnb-design-system-portal/src/docs/web/development-guidelines/for-styling.mdx @@ -93,7 +93,6 @@ Use the shared `utilities.hover()` mixin, as Button does. It shows hover styles - Keep pressed (`:active`) styles outside the hover mixin, so touch users still get feedback when they tap. - Keep focus styles outside it too, so keyboard users see focus on every device. - If a focus style excludes hovered elements with `:not(:hover)`, also show it when the tracked intent is not `mouse`. A tapped element can keep `:hover` when the user returns with the keyboard. -- If a resting style excludes hovered elements with `:not(:hover)`, give a tapped element that style only where hover styles are off: inside `@media (any-hover: none)`, and with `html:is([data-whatintent='touch'], [data-whatintent='keyboard'])`. With `:not([data-whatintent='mouse'])` it would also cancel hover styles before the input tracking has started. - Add `:not(:active)` inside the hover mixin when needed to keep hover styles from hiding the pressed style. ```scss @@ -112,7 +111,7 @@ Use the shared `utilities.hover()` mixin, as Button does. It shows hover styles } ``` -For custom selectors that cannot use the mixin, put the rule inside `@media (any-hover: hover)` and prefix it with `:where(html:not([data-whatintent='touch'], [data-whatintent='keyboard']))`. The `:where()` keeps the specificity of the plain `:hover` rule, so pressed, disabled and error styles still win over it. If the selector already starts with `html`, add the check to that element as `html:where(:not([data-whatintent='touch'], [data-whatintent='keyboard']))`, so all input checks refer to the same `` element. +For custom selectors that cannot use the mixin, put the rule inside `@media (any-hover: hover)` and use `html:not([data-whatintent='touch'], [data-whatintent='keyboard']) &:hover`. Keep this guard beside other input guards instead of nesting them, so they refer to the same `` element. ## CSS Units