Skip to content

Commit

Permalink
[LuxMenuBar] fix bugs in leftmost menu
Browse files Browse the repository at this point in the history
* aria-expanded was always false before this commit,
  now it changes based on whether or not the menu is open.
* before this commit, the Esc key did not close the
  leftmost menu.  With this commit, the Esc key can close
  any menu.

Co-authored-by: Isha Sinha <[email protected]>
  • Loading branch information
sandbergja and ishasinha1 committed Oct 4, 2024
1 parent 7e1c73e commit 57525dd
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 57525dd

Please sign in to comment.