Skip to content

Commit

Permalink
Merge pull request #357 from pulibrary/i355-aria-expanded-for-first-menu
Browse files Browse the repository at this point in the history
[LuxMenuBar] fix bugs in leftmost menu
  • Loading branch information
ishasinha1 authored Oct 4, 2024
2 parents 7e1c73e + 57525dd commit 19b5a4e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/components/LuxMenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@
<template v-if="item.children">
<button
aria-haspopup="true"
:aria-expanded="activeItem ? 'true' : 'false'"
:aria-expanded="activeItem === '' ? 'false' : 'true'"
class="lux-submenu-toggle"
:data-method="item.method"
@click="setActiveItem(index)"
@keydown.esc="activeItem ? setActiveItem(index) : 'false'"
@keydown.esc="setActiveItem(index)"
>
<lux-menu-bar-label :item="item"></lux-menu-bar-label>
</button>
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/specs/components/luxMenuBar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,35 @@ describe("LuxMenuBar.vue", () => {
expect(wrapper.element.innerHTML).not.toContain('role="presentation"')
})

it("should start with aria-expanded false", async () => {
wrapper.setProps({ type: "main-menu" })
await nextTick()
expect(wrapper.find(".lux-submenu-toggle").attributes("aria-expanded")).toEqual("false")
})

it("should be aria-expanded true after a user opens the menu", async () => {
wrapper.setProps({ type: "main-menu" })
await nextTick()

wrapper.find("button.lux-submenu-toggle").trigger("click")
await nextTick()

expect(wrapper.find(".lux-submenu-toggle").attributes("aria-expanded")).toEqual("true")
})

it("should close the menu when the user presses the Esc key", async () => {
wrapper.setProps({ type: "main-menu" })
await nextTick()
wrapper.find("button.lux-submenu-toggle").trigger("click")
await nextTick()
expect(wrapper.find(".lux-submenu-toggle").attributes("aria-expanded")).toEqual("true")

wrapper.find("button.lux-submenu-toggle").trigger("keydown.esc")

await nextTick()
expect(wrapper.find(".lux-submenu-toggle").attributes("aria-expanded")).toEqual("false")
})

it("should be a nav element if the type prop value is 'links'", async () => {
expect(wrapper.find("nav").exists()).toBe(true)
expect(wrapper.find("div").exists()).toBe(false)
Expand Down

0 comments on commit 19b5a4e

Please sign in to comment.