mirror of https://github.com/vuejs/vitepress
The sidebar item row was a `role="button"` wrapping both the group heading and a second `role="button"` caret, which is invalid HTML and nests interactive controls. The caret is now the only control (a native button with `aria-expanded`), the row keeps its click handler as a mouse-only affordance, and groups without a heading render a `div` instead of a `section`. fixes #5366 closes #5371 Co-authored-by: Jibin7Jose <jibinjose884@gmail.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>pull/4532/merge
parent
b18f30680b
commit
ed2bfb266e
@ -0,0 +1,36 @@
|
|||||||
|
describe('sidebar', () => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
await goto('/frontmatter/multiple-levels-outline')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('collapsible group renders a heading and a single toggle button', async () => {
|
||||||
|
const group = page.locator('.VPSidebarItem.level-0.collapsible').first()
|
||||||
|
const caret = group.locator('.caret').first()
|
||||||
|
|
||||||
|
expect(await page.locator('.VPSidebarItem [role="button"]').count()).toBe(0)
|
||||||
|
expect(await caret.evaluate((el) => el.tagName)).toBe('BUTTON')
|
||||||
|
expect(await caret.getAttribute('aria-expanded')).toBe('true')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('group toggles with keyboard, caret and heading', async () => {
|
||||||
|
const group = page.locator('.VPSidebarItem.level-0.collapsible').first()
|
||||||
|
const caret = group.locator('.caret').first()
|
||||||
|
const isCollapsed = () =>
|
||||||
|
group.evaluate((el) => el.classList.contains('collapsed'))
|
||||||
|
|
||||||
|
await caret.focus()
|
||||||
|
await page.keyboard.press('Enter')
|
||||||
|
expect(await isCollapsed()).toBe(true)
|
||||||
|
expect(await caret.getAttribute('aria-expanded')).toBe('false')
|
||||||
|
|
||||||
|
await page.keyboard.press('Space')
|
||||||
|
expect(await isCollapsed()).toBe(false)
|
||||||
|
expect(await caret.getAttribute('aria-expanded')).toBe('true')
|
||||||
|
|
||||||
|
await caret.click()
|
||||||
|
expect(await isCollapsed()).toBe(true)
|
||||||
|
|
||||||
|
await group.locator('.text').first().click()
|
||||||
|
expect(await isCollapsed()).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
Loading…
Reference in new issue