From 7d0989425197992b5c125e8b92f9ff5c3e04d802 Mon Sep 17 00:00:00 2001 From: Anders Langseth Date: Tue, 24 Nov 2026 10:52:07 +0100 Subject: [PATCH 1/8] Prevent sticky List item hover outline after tapping on touch devices Touch browsers keep :hover on the last tapped element, so a tapped action or accordion item kept its green hover outline until something else was tapped. Limit the hover outlines to devices that can hover. The keyboard focus outline excluded hovered items. On touch devices a tapped item keeps :hover, so it showed the hover outline instead of the focus outline when the user returned to it with the keyboard. Show the focus outline there too, also in the fallback for browsers without support for :has(). --- .../list/__tests__/ListTouch.e2e.spec.ts | 131 ++++++++++++++++++ .../src/components/list/style/dnb-list.scss | 77 ++++++++-- 2 files changed, 193 insertions(+), 15 deletions(-) create mode 100644 packages/dnb-eufemia/src/components/list/__tests__/ListTouch.e2e.spec.ts diff --git a/packages/dnb-eufemia/src/components/list/__tests__/ListTouch.e2e.spec.ts b/packages/dnb-eufemia/src/components/list/__tests__/ListTouch.e2e.spec.ts new file mode 100644 index 000000000000..9dba23f5c507 --- /dev/null +++ b/packages/dnb-eufemia/src/components/list/__tests__/ListTouch.e2e.spec.ts @@ -0,0 +1,131 @@ +import { expect, test } from '@playwright/test' + +test.describe('List on touch devices', () => { + test.use({ hasTouch: true }) + + test.beforeEach(async ({ page }) => { + await page.emulateMedia({ reducedMotion: 'reduce' }) + await page.goto('/web/components/list/demos/?data-visual-test') + await expect( + page.locator( + '[data-visual-test="list-action"] .dnb-list__item__action' + ) + ).not.toHaveCount(0) + }) + + const readOutline = (item) => + item.evaluate((element) => { + const outline = getComputedStyle(element, '::after') + + return { + color: outline.borderLeftColor, + width: outline.borderLeftWidth, + } + }) + + test('does not keep the hover outline on an action item after a tap', async ({ + page, + }) => { + for (const example of ['list-action', 'list-card']) { + await test.step(example, async () => { + const item = page + .locator( + `[data-visual-test="${example}"] .dnb-list__item__action` + ) + .first() + const rest = await readOutline(item) + + await item.tap() + + expect( + await item.evaluate((element) => element.matches(':hover')) + ).toBe(true) + await expect.poll(() => readOutline(item)).toEqual(rest) + }) + } + }) + + test('does not keep the hover outline on an accordion item after a tap', async ({ + page, + }) => { + const item = page + .locator( + '[data-visual-test="list-accordion"] .dnb-list__item__accordion' + ) + .first() + const header = item.locator('.dnb-list__item__accordion__header') + const rest = await readOutline(item) + + await header.tap() + await expect(header).toHaveAttribute('aria-expanded', 'true') + await header.tap() + await expect(header).toHaveAttribute('aria-expanded', 'false') + + expect( + await header.evaluate((element) => element.matches(':hover')) + ).toBe(true) + await expect.poll(() => readOutline(item)).toEqual(rest) + }) + + test('shows the keyboard focus outline on a tapped action item', async ({ + page, + }) => { + const items = page.locator( + '[data-visual-test="list-action"] .dnb-list__item__action' + ) + const tapped = items.nth(0) + const next = items.nth(1) + + await tapped.tap() + + // The next item gets focus from the keyboard only, so it shows the + // focus outline that the tapped item should show too + await page.keyboard.press('Tab') + await expect( + next.locator(':scope > .dnb-list__item__action__button, :scope > a') + ).toBeFocused() + const focusOutline = await readOutline(next) + + await page.keyboard.press('Shift+Tab') + await expect( + tapped.locator( + ':scope > .dnb-list__item__action__button, :scope > a' + ) + ).toBeFocused() + + // The tapped item keeps :hover on touch devices + expect( + await tapped.evaluate((element) => element.matches(':hover')) + ).toBe(true) + await expect.poll(() => readOutline(tapped)).toEqual(focusOutline) + }) + + test('shows the keyboard focus outline on a tapped accordion header', async ({ + page, + }) => { + const items = page.locator( + '[data-visual-test="list-accordion"] .dnb-list__item__accordion' + ) + const tapped = items.nth(0) + const next = items.nth(1) + const header = tapped.locator('.dnb-list__item__accordion__header') + + await header.tap() + await header.tap() + await expect(header).toHaveAttribute('aria-expanded', 'false') + + await page.keyboard.press('Tab') + await expect( + next.locator('.dnb-list__item__accordion__header') + ).toBeFocused() + const focusOutline = await readOutline(next) + + await page.keyboard.press('Shift+Tab') + await expect(header).toBeFocused() + + expect( + await header.evaluate((element) => element.matches(':hover')) + ).toBe(true) + await expect.poll(() => readOutline(tapped)).toEqual(focusOutline) + }) +}) diff --git a/packages/dnb-eufemia/src/components/list/style/dnb-list.scss b/packages/dnb-eufemia/src/components/list/style/dnb-list.scss index d20a598c30a5..f00ad9948ead 100644 --- a/packages/dnb-eufemia/src/components/list/style/dnb-list.scss +++ b/packages/dnb-eufemia/src/components/list/style/dnb-list.scss @@ -25,11 +25,24 @@ &:focus-visible:where(:not(:hover):not(:active))::before { @include focusFallbackOutline(); } + + // Touch browsers keep :hover on the last tapped element + @media (hover: none) { + &:focus-visible:where(:not(:active))::before { + @include focusFallbackOutline(); + } + } } @supports (not (selector(:has(*)))) and (not (selector(:focus-visible))) { &:focus:not(:hover):not(:active)::before { @include focusFallbackOutline(); } + + @media (hover: none) { + &:focus:not(:active)::before { + @include focusFallbackOutline(); + } + } } } @@ -574,8 +587,11 @@ // Handle action states. Keep :hover in its own rule, because a // browser without support for :has() or :focus-visible drops the // whole rule. - &:not(.dnb-list__item--disabled):hover { - @include navigationOutline(); + // Touch browsers keep :hover on the last tapped element. + @media (hover: hover) { + &:not(.dnb-list__item--disabled):hover { + @include navigationOutline(); + } } &:not(.dnb-list__item--disabled):where( :not(:hover):not(:active) @@ -585,6 +601,15 @@ ) { @include navigationFocusOutline(); } + // A tapped item keeps :hover, so do not exclude it on touch devices + @media (hover: none) { + &:not(.dnb-list__item--disabled):where(:not(:active)):has( + > a:focus-visible, + > .dnb-list__item__action__button:focus-visible + ) { + @include navigationFocusOutline(); + } + } &:not(.dnb-list__item--disabled) > a, &:not(.dnb-list__item--disabled) > .dnb-list__item__action__button { @include focusFallback(); @@ -639,8 +664,12 @@ } // Handle accordion states (own header only, not nested accordions) - &:not(.dnb-list__item--disabled):has(> #{&}__accordion__header:hover) { - @include navigationOutline(); + @media (hover: hover) { + &:not(.dnb-list__item--disabled):has( + > #{&}__accordion__header:hover + ) { + @include navigationOutline(); + } } &:not(.dnb-list__item--disabled):has( > #{&}__accordion__header:focus-visible:where( @@ -649,6 +678,13 @@ ) { @include navigationFocusOutline(); } + @media (hover: none) { + &:not(.dnb-list__item--disabled):has( + > #{&}__accordion__header:focus-visible:where(:not(:active)) + ) { + @include navigationFocusOutline(); + } + } &__accordion:not(.dnb-list__item--disabled) > #{&}__accordion__header { @include focusFallback(); } @@ -713,6 +749,14 @@ .dnb-list__item:is(:hover, :has(> :focus-visible)) { z-index: 11; } + + // Touch devices show no hover outline, so a tapped header does not + // need to stay above a focused nested row + @media (hover: none) { + > #{&}__content .dnb-list__item:has(> :focus-visible) { + z-index: 11; + } + } } &.dnb-skeleton .dnb-icon { @@ -816,17 +860,20 @@ // shows them only when its header is hovered. // Keep these rules separate, because a browser without support // for :has() or :focus-visible drops the whole rule. - &.dnb-list__item__action:not( - .dnb-list__item--disabled - ):hover::after { - border: var(--list-item-outline-width) solid - var(--list-item-outline-color); - } - &.dnb-list__item__accordion:not(.dnb-list__item--disabled):has( - > .dnb-list__item__accordion__header:hover - )::after { - border: var(--list-item-outline-width) solid - var(--list-item-outline-color); + // Touch browsers keep :hover on the last tapped element. + @media (hover: hover) { + &.dnb-list__item__action:not( + .dnb-list__item--disabled + ):hover::after { + border: var(--list-item-outline-width) solid + var(--list-item-outline-color); + } + &.dnb-list__item__accordion:not(.dnb-list__item--disabled):has( + > .dnb-list__item__accordion__header:hover + )::after { + border: var(--list-item-outline-width) solid + var(--list-item-outline-color); + } } &.dnb-list__item__action:not(.dnb-list__item--disabled):has( > a:focus-visible, From 6ab731691930636846e3358cdda1bc8934900bbf Mon Sep 17 00:00:00 2001 From: Anders Langseth Date: Tue, 24 Nov 2026 11:05:13 +0100 Subject: [PATCH 2/8] Expect the touch focus fallback rules in the List style test The focus fallback for browsers without :has() now has rules for devices that can't hover, so a tapped item shows the focus outline too. List them in the test, with their media query. --- .../list/__tests__/ListStyles.test.ts | 56 ++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/packages/dnb-eufemia/src/components/list/__tests__/ListStyles.test.ts b/packages/dnb-eufemia/src/components/list/__tests__/ListStyles.test.ts index 93e178f20a16..d89fff81ca59 100644 --- a/packages/dnb-eufemia/src/components/list/__tests__/ListStyles.test.ts +++ b/packages/dnb-eufemia/src/components/list/__tests__/ListStyles.test.ts @@ -10,13 +10,27 @@ import { loadScss } from '../../../core/test-utils/testSetup' // tested in ListFocusFallback.e2e.spec.ts. function getFallbackRules() { const css = loadScss(require.resolve('../style/dnb-list.scss')) - const rules: Array<{ condition: string; selector: string }> = [] + const rules: Array<{ + condition: string + selector: string + media?: string + }> = [] postcss.parse(css).walkAtRules('supports', (atRule) => { if (atRule.params.includes('not (selector(:has(*)))')) { atRule.walkRules((rule) => { + const media = + rule.parent.type === 'atrule' && + (rule.parent as postcss.AtRule).name === 'media' + ? (rule.parent as postcss.AtRule).params + : undefined + for (const selector of rule.selectors) { - rules.push({ condition: atRule.params, selector }) + rules.push({ + condition: atRule.params, + selector, + ...(media && { media }), + }) } }) } @@ -38,6 +52,8 @@ const normalize = (value: string) => value.replace(/\s+/g, ' ').replace(/\( /g, '(').replace(/ \)/g, ')') describe('List scss', () => { + // Touch browsers keep :hover on the last tapped element, so the rules in + // (hover: none) show the outline on a tapped item too it('should show the outline of a focused item in browsers without :has()', () => { expect(getFallbackRules()).toEqual([ { @@ -50,6 +66,18 @@ describe('List scss', () => { selector: '.dnb-list__item__action:not(.dnb-list__item--disabled) > .dnb-list__item__action__button:focus-visible:where(:not(:hover):not(:active))::before', }, + { + condition: withFocusVisible, + selector: + '.dnb-list__item__action:not(.dnb-list__item--disabled) > a:focus-visible:where(:not(:active))::before', + media: '(hover: none)', + }, + { + condition: withFocusVisible, + selector: + '.dnb-list__item__action:not(.dnb-list__item--disabled) > .dnb-list__item__action__button:focus-visible:where(:not(:active))::before', + media: '(hover: none)', + }, { condition: withoutFocusVisible, selector: @@ -60,16 +88,40 @@ describe('List scss', () => { selector: '.dnb-list__item__action:not(.dnb-list__item--disabled) > .dnb-list__item__action__button:focus:not(:hover):not(:active)::before', }, + { + condition: withoutFocusVisible, + selector: + '.dnb-list__item__action:not(.dnb-list__item--disabled) > a:focus:not(:active)::before', + media: '(hover: none)', + }, + { + condition: withoutFocusVisible, + selector: + '.dnb-list__item__action:not(.dnb-list__item--disabled) > .dnb-list__item__action__button:focus:not(:active)::before', + media: '(hover: none)', + }, { condition: withFocusVisible, selector: '.dnb-list__item__accordion:not(.dnb-list__item--disabled) > .dnb-list__item__accordion__header:focus-visible:where(:not(:hover):not(:active))::before', }, + { + condition: withFocusVisible, + selector: + '.dnb-list__item__accordion:not(.dnb-list__item--disabled) > .dnb-list__item__accordion__header:focus-visible:where(:not(:active))::before', + media: '(hover: none)', + }, { condition: withoutFocusVisible, selector: '.dnb-list__item__accordion:not(.dnb-list__item--disabled) > .dnb-list__item__accordion__header:focus:not(:hover):not(:active)::before', }, + { + condition: withoutFocusVisible, + selector: + '.dnb-list__item__accordion:not(.dnb-list__item--disabled) > .dnb-list__item__accordion__header:focus:not(:active)::before', + media: '(hover: none)', + }, ]) }) From 30c8a707e1fa598ad6098fe4dc7e8369be0745bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B8egh?= Date: Tue, 24 Nov 2026 13:25:56 +0100 Subject: [PATCH 3/8] Track touch intent for List hover and focus --- .../list/__tests__/ListTouch.e2e.spec.ts | 49 ++++++++++++ .../src/components/list/style/dnb-list.scss | 77 +++++++++---------- 2 files changed, 85 insertions(+), 41 deletions(-) diff --git a/packages/dnb-eufemia/src/components/list/__tests__/ListTouch.e2e.spec.ts b/packages/dnb-eufemia/src/components/list/__tests__/ListTouch.e2e.spec.ts index 9dba23f5c507..4be0d831cf9e 100644 --- a/packages/dnb-eufemia/src/components/list/__tests__/ListTouch.e2e.spec.ts +++ b/packages/dnb-eufemia/src/components/list/__tests__/ListTouch.e2e.spec.ts @@ -128,4 +128,53 @@ test.describe('List on touch devices', () => { ).toBe(true) await expect.poll(() => readOutline(tapped)).toEqual(focusOutline) }) + + test.describe('with a mouse and touchscreen', () => { + test.use({ hasTouch: false }) + + test('switches hover styles with the current input', async ({ + page, + }) => { + const input = page + .locator( + '[data-visual-test="list-action"] .dnb-list__item__action' + ) + .first() + const readColors = () => + page + .locator( + '[data-visual-test="list-action"] .dnb-list__item__action' + ) + .first() + .evaluate( + (element) => + getComputedStyle(element, '::after').borderLeftColor + ) + const rest = await readColors() + + expect( + await page.evaluate(() => matchMedia('(hover: hover)').matches) + ).toBe(true) + await input.hover() + await expect.poll(readColors).not.toEqual(rest) + + // Keep native :hover while changing the input, as hybrid devices can do. + await input.dispatchEvent('pointerdown', { pointerType: 'touch' }) + await expect(page.locator('html')).toHaveAttribute( + 'data-whatintent', + 'touch' + ) + await expect.poll(readColors).toEqual(rest) + + await page.clock.install() + await page.clock.fastForward(250) + await page.mouse.move(0, 0) + await input.hover() + await expect(page.locator('html')).toHaveAttribute( + 'data-whatintent', + 'mouse' + ) + await expect.poll(readColors).not.toEqual(rest) + }) + }) }) diff --git a/packages/dnb-eufemia/src/components/list/style/dnb-list.scss b/packages/dnb-eufemia/src/components/list/style/dnb-list.scss index f00ad9948ead..f9a0e6a3fed2 100644 --- a/packages/dnb-eufemia/src/components/list/style/dnb-list.scss +++ b/packages/dnb-eufemia/src/components/list/style/dnb-list.scss @@ -27,10 +27,9 @@ } // Touch browsers keep :hover on the last tapped element - @media (hover: none) { + html:not([data-whatintent='mouse']) &:focus-visible:where(:not(:active))::before { - @include focusFallbackOutline(); - } + @include focusFallbackOutline(); } } @supports (not (selector(:has(*)))) and (not (selector(:focus-visible))) { @@ -38,10 +37,8 @@ @include focusFallbackOutline(); } - @media (hover: none) { - &:focus:not(:active)::before { - @include focusFallbackOutline(); - } + html:not([data-whatintent='mouse']) &:focus:not(:active)::before { + @include focusFallbackOutline(); } } } @@ -588,10 +585,9 @@ // browser without support for :has() or :focus-visible drops the // whole rule. // Touch browsers keep :hover on the last tapped element. - @media (hover: hover) { + html:not([data-whatintent='touch']) &:not(.dnb-list__item--disabled):hover { - @include navigationOutline(); - } + @include navigationOutline(); } &:not(.dnb-list__item--disabled):where( :not(:hover):not(:active) @@ -602,13 +598,12 @@ @include navigationFocusOutline(); } // A tapped item keeps :hover, so do not exclude it on touch devices - @media (hover: none) { + html:not([data-whatintent='mouse']) &:not(.dnb-list__item--disabled):where(:not(:active)):has( - > a:focus-visible, - > .dnb-list__item__action__button:focus-visible - ) { - @include navigationFocusOutline(); - } + > a:focus-visible, + > .dnb-list__item__action__button:focus-visible + ) { + @include navigationFocusOutline(); } &:not(.dnb-list__item--disabled) > a, &:not(.dnb-list__item--disabled) > .dnb-list__item__action__button { @@ -664,12 +659,11 @@ } // Handle accordion states (own header only, not nested accordions) - @media (hover: hover) { + html:not([data-whatintent='touch']) &:not(.dnb-list__item--disabled):has( - > #{&}__accordion__header:hover - ) { - @include navigationOutline(); - } + > #{&}__accordion__header:hover + ) { + @include navigationOutline(); } &:not(.dnb-list__item--disabled):has( > #{&}__accordion__header:focus-visible:where( @@ -678,12 +672,11 @@ ) { @include navigationFocusOutline(); } - @media (hover: none) { + html:not([data-whatintent='mouse']) &:not(.dnb-list__item--disabled):has( - > #{&}__accordion__header:focus-visible:where(:not(:active)) - ) { - @include navigationFocusOutline(); - } + > #{&}__accordion__header:focus-visible:where(:not(:active)) + ) { + @include navigationFocusOutline(); } &__accordion:not(.dnb-list__item--disabled) > #{&}__accordion__header { @include focusFallback(); @@ -752,10 +745,11 @@ // Touch devices show no hover outline, so a tapped header does not // need to stay above a focused nested row - @media (hover: none) { - > #{&}__content .dnb-list__item:has(> :focus-visible) { - z-index: 11; - } + html:not([data-whatintent='mouse']) + & + > #{&}__content + .dnb-list__item:has(> :focus-visible) { + z-index: 11; } } @@ -861,19 +855,20 @@ // Keep these rules separate, because a browser without support // for :has() or :focus-visible drops the whole rule. // Touch browsers keep :hover on the last tapped element. - @media (hover: hover) { + html:not([data-whatintent='touch']) &.dnb-list__item__action:not( - .dnb-list__item--disabled - ):hover::after { - border: var(--list-item-outline-width) solid - var(--list-item-outline-color); - } + .dnb-list__item--disabled + ):hover::after { + border: var(--list-item-outline-width) solid + var(--list-item-outline-color); + } + + html:not([data-whatintent='touch']) &.dnb-list__item__accordion:not(.dnb-list__item--disabled):has( - > .dnb-list__item__accordion__header:hover - )::after { - border: var(--list-item-outline-width) solid - var(--list-item-outline-color); - } + > .dnb-list__item__accordion__header:hover + )::after { + border: var(--list-item-outline-width) solid + var(--list-item-outline-color); } &.dnb-list__item__action:not(.dnb-list__item--disabled):has( > a:focus-visible, From b180584453dc0648787a704bea2fd4dd922ec822 Mon Sep 17 00:00:00 2001 From: Anders Langseth Date: Tue, 24 Nov 2026 13:35:47 +0100 Subject: [PATCH 4/8] Remove the e2e tests for touch devices --- .../list/__tests__/ListTouch.e2e.spec.ts | 180 ------------------ 1 file changed, 180 deletions(-) delete mode 100644 packages/dnb-eufemia/src/components/list/__tests__/ListTouch.e2e.spec.ts diff --git a/packages/dnb-eufemia/src/components/list/__tests__/ListTouch.e2e.spec.ts b/packages/dnb-eufemia/src/components/list/__tests__/ListTouch.e2e.spec.ts deleted file mode 100644 index 4be0d831cf9e..000000000000 --- a/packages/dnb-eufemia/src/components/list/__tests__/ListTouch.e2e.spec.ts +++ /dev/null @@ -1,180 +0,0 @@ -import { expect, test } from '@playwright/test' - -test.describe('List on touch devices', () => { - test.use({ hasTouch: true }) - - test.beforeEach(async ({ page }) => { - await page.emulateMedia({ reducedMotion: 'reduce' }) - await page.goto('/web/components/list/demos/?data-visual-test') - await expect( - page.locator( - '[data-visual-test="list-action"] .dnb-list__item__action' - ) - ).not.toHaveCount(0) - }) - - const readOutline = (item) => - item.evaluate((element) => { - const outline = getComputedStyle(element, '::after') - - return { - color: outline.borderLeftColor, - width: outline.borderLeftWidth, - } - }) - - test('does not keep the hover outline on an action item after a tap', async ({ - page, - }) => { - for (const example of ['list-action', 'list-card']) { - await test.step(example, async () => { - const item = page - .locator( - `[data-visual-test="${example}"] .dnb-list__item__action` - ) - .first() - const rest = await readOutline(item) - - await item.tap() - - expect( - await item.evaluate((element) => element.matches(':hover')) - ).toBe(true) - await expect.poll(() => readOutline(item)).toEqual(rest) - }) - } - }) - - test('does not keep the hover outline on an accordion item after a tap', async ({ - page, - }) => { - const item = page - .locator( - '[data-visual-test="list-accordion"] .dnb-list__item__accordion' - ) - .first() - const header = item.locator('.dnb-list__item__accordion__header') - const rest = await readOutline(item) - - await header.tap() - await expect(header).toHaveAttribute('aria-expanded', 'true') - await header.tap() - await expect(header).toHaveAttribute('aria-expanded', 'false') - - expect( - await header.evaluate((element) => element.matches(':hover')) - ).toBe(true) - await expect.poll(() => readOutline(item)).toEqual(rest) - }) - - test('shows the keyboard focus outline on a tapped action item', async ({ - page, - }) => { - const items = page.locator( - '[data-visual-test="list-action"] .dnb-list__item__action' - ) - const tapped = items.nth(0) - const next = items.nth(1) - - await tapped.tap() - - // The next item gets focus from the keyboard only, so it shows the - // focus outline that the tapped item should show too - await page.keyboard.press('Tab') - await expect( - next.locator(':scope > .dnb-list__item__action__button, :scope > a') - ).toBeFocused() - const focusOutline = await readOutline(next) - - await page.keyboard.press('Shift+Tab') - await expect( - tapped.locator( - ':scope > .dnb-list__item__action__button, :scope > a' - ) - ).toBeFocused() - - // The tapped item keeps :hover on touch devices - expect( - await tapped.evaluate((element) => element.matches(':hover')) - ).toBe(true) - await expect.poll(() => readOutline(tapped)).toEqual(focusOutline) - }) - - test('shows the keyboard focus outline on a tapped accordion header', async ({ - page, - }) => { - const items = page.locator( - '[data-visual-test="list-accordion"] .dnb-list__item__accordion' - ) - const tapped = items.nth(0) - const next = items.nth(1) - const header = tapped.locator('.dnb-list__item__accordion__header') - - await header.tap() - await header.tap() - await expect(header).toHaveAttribute('aria-expanded', 'false') - - await page.keyboard.press('Tab') - await expect( - next.locator('.dnb-list__item__accordion__header') - ).toBeFocused() - const focusOutline = await readOutline(next) - - await page.keyboard.press('Shift+Tab') - await expect(header).toBeFocused() - - expect( - await header.evaluate((element) => element.matches(':hover')) - ).toBe(true) - await expect.poll(() => readOutline(tapped)).toEqual(focusOutline) - }) - - test.describe('with a mouse and touchscreen', () => { - test.use({ hasTouch: false }) - - test('switches hover styles with the current input', async ({ - page, - }) => { - const input = page - .locator( - '[data-visual-test="list-action"] .dnb-list__item__action' - ) - .first() - const readColors = () => - page - .locator( - '[data-visual-test="list-action"] .dnb-list__item__action' - ) - .first() - .evaluate( - (element) => - getComputedStyle(element, '::after').borderLeftColor - ) - const rest = await readColors() - - expect( - await page.evaluate(() => matchMedia('(hover: hover)').matches) - ).toBe(true) - await input.hover() - await expect.poll(readColors).not.toEqual(rest) - - // Keep native :hover while changing the input, as hybrid devices can do. - await input.dispatchEvent('pointerdown', { pointerType: 'touch' }) - await expect(page.locator('html')).toHaveAttribute( - 'data-whatintent', - 'touch' - ) - await expect.poll(readColors).toEqual(rest) - - await page.clock.install() - await page.clock.fastForward(250) - await page.mouse.move(0, 0) - await input.hover() - await expect(page.locator('html')).toHaveAttribute( - 'data-whatintent', - 'mouse' - ) - await expect.poll(readColors).not.toEqual(rest) - }) - }) -}) From 5dc8f67d65a4eb20a5d66c5ab84024d75c855c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B8egh?= Date: Tue, 24 Nov 2026 14:14:01 +0100 Subject: [PATCH 5/8] Keep hover off after touch and keyboard use --- .../dnb-eufemia/src/components/list/style/dnb-list.scss | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/dnb-eufemia/src/components/list/style/dnb-list.scss b/packages/dnb-eufemia/src/components/list/style/dnb-list.scss index f9a0e6a3fed2..f9c2d3994ef1 100644 --- a/packages/dnb-eufemia/src/components/list/style/dnb-list.scss +++ b/packages/dnb-eufemia/src/components/list/style/dnb-list.scss @@ -585,7 +585,7 @@ // browser without support for :has() or :focus-visible drops the // whole rule. // Touch browsers keep :hover on the last tapped element. - html:not([data-whatintent='touch']) + html[data-whatintent='mouse'] &:not(.dnb-list__item--disabled):hover { @include navigationOutline(); } @@ -659,7 +659,7 @@ } // Handle accordion states (own header only, not nested accordions) - html:not([data-whatintent='touch']) + html[data-whatintent='mouse'] &:not(.dnb-list__item--disabled):has( > #{&}__accordion__header:hover ) { @@ -855,7 +855,7 @@ // Keep these rules separate, because a browser without support // for :has() or :focus-visible drops the whole rule. // Touch browsers keep :hover on the last tapped element. - html:not([data-whatintent='touch']) + html[data-whatintent='mouse'] &.dnb-list__item__action:not( .dnb-list__item--disabled ):hover::after { @@ -863,7 +863,7 @@ var(--list-item-outline-color); } - html:not([data-whatintent='touch']) + html[data-whatintent='mouse'] &.dnb-list__item__accordion:not(.dnb-list__item--disabled):has( > .dnb-list__item__accordion__header:hover )::after { From d61f07c5217fd8ab648d5a15349a2931cc7fb12c Mon Sep 17 00:00:00 2001 From: Anders Langseth Date: Tue, 24 Nov 2026 15:34:37 +0100 Subject: [PATCH 6/8] Base hover styles on the any-hover media query 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. --- .../src/components/list/style/dnb-list.scss | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/packages/dnb-eufemia/src/components/list/style/dnb-list.scss b/packages/dnb-eufemia/src/components/list/style/dnb-list.scss index f9c2d3994ef1..504cadcd97a3 100644 --- a/packages/dnb-eufemia/src/components/list/style/dnb-list.scss +++ b/packages/dnb-eufemia/src/components/list/style/dnb-list.scss @@ -585,9 +585,11 @@ // browser without support for :has() or :focus-visible drops the // whole rule. // Touch browsers keep :hover on the last tapped element. - html[data-whatintent='mouse'] - &:not(.dnb-list__item--disabled):hover { - @include navigationOutline(); + @media (any-hover: hover) { + html:not([data-whatintent='touch'], [data-whatintent='keyboard']) + &:not(.dnb-list__item--disabled):hover { + @include navigationOutline(); + } } &:not(.dnb-list__item--disabled):where( :not(:hover):not(:active) @@ -659,11 +661,13 @@ } // Handle accordion states (own header only, not nested accordions) - html[data-whatintent='mouse'] - &:not(.dnb-list__item--disabled):has( - > #{&}__accordion__header:hover - ) { - @include navigationOutline(); + @media (any-hover: hover) { + html:not([data-whatintent='touch'], [data-whatintent='keyboard']) + &:not(.dnb-list__item--disabled):has( + > #{&}__accordion__header:hover + ) { + @include navigationOutline(); + } } &:not(.dnb-list__item--disabled):has( > #{&}__accordion__header:focus-visible:where( @@ -855,20 +859,24 @@ // Keep these rules separate, because a browser without support // for :has() or :focus-visible drops the whole rule. // Touch browsers keep :hover on the last tapped element. - html[data-whatintent='mouse'] - &.dnb-list__item__action:not( - .dnb-list__item--disabled - ):hover::after { - border: var(--list-item-outline-width) solid - var(--list-item-outline-color); + @media (any-hover: hover) { + html:not([data-whatintent='touch'], [data-whatintent='keyboard']) + &.dnb-list__item__action:not( + .dnb-list__item--disabled + ):hover::after { + border: var(--list-item-outline-width) solid + var(--list-item-outline-color); + } } - html[data-whatintent='mouse'] - &.dnb-list__item__accordion:not(.dnb-list__item--disabled):has( - > .dnb-list__item__accordion__header:hover - )::after { - border: var(--list-item-outline-width) solid - var(--list-item-outline-color); + @media (any-hover: hover) { + html:not([data-whatintent='touch'], [data-whatintent='keyboard']) + &.dnb-list__item__accordion:not(.dnb-list__item--disabled):has( + > .dnb-list__item__accordion__header:hover + )::after { + border: var(--list-item-outline-width) solid + var(--list-item-outline-color); + } } &.dnb-list__item__action:not(.dnb-list__item--disabled):has( > a:focus-visible, From 7dcdcfd8de6e8faec1ba0a717ddd6e72de96608a Mon Sep 17 00:00:00 2001 From: Anders Langseth Date: Tue, 24 Nov 2026 17:13:51 +0100 Subject: [PATCH 7/8] Keep the specificity of hover rules from main 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. --- .../src/components/list/style/dnb-list.scss | 37 ++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/packages/dnb-eufemia/src/components/list/style/dnb-list.scss b/packages/dnb-eufemia/src/components/list/style/dnb-list.scss index 504cadcd97a3..96c63a44472a 100644 --- a/packages/dnb-eufemia/src/components/list/style/dnb-list.scss +++ b/packages/dnb-eufemia/src/components/list/style/dnb-list.scss @@ -586,7 +586,12 @@ // whole rule. // Touch browsers keep :hover on the last tapped element. @media (any-hover: hover) { - html:not([data-whatintent='touch'], [data-whatintent='keyboard']) + :where( + html:not( + [data-whatintent='touch'], + [data-whatintent='keyboard'] + ) + ) &:not(.dnb-list__item--disabled):hover { @include navigationOutline(); } @@ -662,7 +667,9 @@ // Handle accordion states (own header only, not nested accordions) @media (any-hover: hover) { - html:not([data-whatintent='touch'], [data-whatintent='keyboard']) + :where( + html:not([data-whatintent='touch'], [data-whatintent='keyboard']) + ) &:not(.dnb-list__item--disabled):has( > #{&}__accordion__header:hover ) { @@ -749,12 +756,22 @@ // Touch devices show no hover outline, so a tapped header does not // need to stay above a focused nested row - html:not([data-whatintent='mouse']) + html:is([data-whatintent='touch'], [data-whatintent='keyboard']) & > #{&}__content .dnb-list__item:has(> :focus-visible) { z-index: 11; } + + // Devices that cannot hover show no hover styles at all + @media (any-hover: none) { + html:not([data-whatintent='mouse']) + & + > #{&}__content + .dnb-list__item:has(> :focus-visible) { + z-index: 11; + } + } } &.dnb-skeleton .dnb-icon { @@ -860,7 +877,12 @@ // for :has() or :focus-visible drops the whole rule. // Touch browsers keep :hover on the last tapped element. @media (any-hover: hover) { - html:not([data-whatintent='touch'], [data-whatintent='keyboard']) + :where( + html:not( + [data-whatintent='touch'], + [data-whatintent='keyboard'] + ) + ) &.dnb-list__item__action:not( .dnb-list__item--disabled ):hover::after { @@ -870,7 +892,12 @@ } @media (any-hover: hover) { - html:not([data-whatintent='touch'], [data-whatintent='keyboard']) + :where( + html:not( + [data-whatintent='touch'], + [data-whatintent='keyboard'] + ) + ) &.dnb-list__item__accordion:not(.dnb-list__item--disabled):has( > .dnb-list__item__accordion__header:hover )::after { From 5fdea537402caedc66ab68e269a104646b5b222d Mon Sep 17 00:00:00 2001 From: Anders Langseth Date: Tue, 24 Nov 2026 17:29:10 +0100 Subject: [PATCH 8/8] Restore the html hover check 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. --- .../src/components/list/style/dnb-list.scss | 37 +++---------------- 1 file changed, 5 insertions(+), 32 deletions(-) diff --git a/packages/dnb-eufemia/src/components/list/style/dnb-list.scss b/packages/dnb-eufemia/src/components/list/style/dnb-list.scss index 96c63a44472a..504cadcd97a3 100644 --- a/packages/dnb-eufemia/src/components/list/style/dnb-list.scss +++ b/packages/dnb-eufemia/src/components/list/style/dnb-list.scss @@ -586,12 +586,7 @@ // whole rule. // Touch browsers keep :hover on the last tapped element. @media (any-hover: hover) { - :where( - html:not( - [data-whatintent='touch'], - [data-whatintent='keyboard'] - ) - ) + html:not([data-whatintent='touch'], [data-whatintent='keyboard']) &:not(.dnb-list__item--disabled):hover { @include navigationOutline(); } @@ -667,9 +662,7 @@ // Handle accordion states (own header only, not nested accordions) @media (any-hover: hover) { - :where( - html:not([data-whatintent='touch'], [data-whatintent='keyboard']) - ) + html:not([data-whatintent='touch'], [data-whatintent='keyboard']) &:not(.dnb-list__item--disabled):has( > #{&}__accordion__header:hover ) { @@ -756,22 +749,12 @@ // Touch devices show no hover outline, so a tapped header does not // need to stay above a focused nested row - html:is([data-whatintent='touch'], [data-whatintent='keyboard']) + html:not([data-whatintent='mouse']) & > #{&}__content .dnb-list__item:has(> :focus-visible) { z-index: 11; } - - // Devices that cannot hover show no hover styles at all - @media (any-hover: none) { - html:not([data-whatintent='mouse']) - & - > #{&}__content - .dnb-list__item:has(> :focus-visible) { - z-index: 11; - } - } } &.dnb-skeleton .dnb-icon { @@ -877,12 +860,7 @@ // for :has() or :focus-visible drops the whole rule. // Touch browsers keep :hover on the last tapped element. @media (any-hover: hover) { - :where( - html:not( - [data-whatintent='touch'], - [data-whatintent='keyboard'] - ) - ) + html:not([data-whatintent='touch'], [data-whatintent='keyboard']) &.dnb-list__item__action:not( .dnb-list__item--disabled ):hover::after { @@ -892,12 +870,7 @@ } @media (any-hover: hover) { - :where( - html:not( - [data-whatintent='touch'], - [data-whatintent='keyboard'] - ) - ) + html:not([data-whatintent='touch'], [data-whatintent='keyboard']) &.dnb-list__item__accordion:not(.dnb-list__item--disabled):has( > .dnb-list__item__accordion__header:hover )::after {