Skip to content

Commit

Permalink
Passing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
khiga8 committed Oct 24, 2022
1 parent bd444d3 commit 271d1d6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function focusFirstItem(details: Element) {
}

function sibling(details: Element, next: boolean): HTMLElement | null {
const options = Array.from(details.querySelectorAll<HTMLElement>('[role^="menuitem"]:not([hidden])'))
const options = Array.from(details.querySelectorAll<HTMLElement>('[role^="menuitem"]:not([hidden]):not([disabled])'))
const selected = document.activeElement
const index = selected instanceof HTMLElement ? options.indexOf(selected) : -1
const found = next ? options[index + 1] : options[index - 1]
Expand Down
5 changes: 2 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('details-menu element', function () {
summary.dispatchEvent(new KeyboardEvent('keydown', {key: 'ArrowUp', bubbles: true}))
assert(details.open, 'menu is open')

const last = [...details.querySelectorAll('[role="menuitem"]:not([disabled]):not([aria-disabled])')].pop()
const last = [...details.querySelectorAll('[role="menuitem"]:not([disabled])')].pop()
assert.equal(last, document.activeElement, 'arrow focuses last item')
})

Expand Down Expand Up @@ -219,7 +219,7 @@ describe('details-menu element', function () {
summary.dispatchEvent(new MouseEvent('click', {bubbles: true}))
details.dispatchEvent(new KeyboardEvent('keydown', {key: 'ArrowUp', bubbles: true}))

const notDisabled = details.querySelectorAll('[role="menuitem"]')[2]
const notDisabled = details.querySelectorAll('[role="menuitem"]')[3]
assert.equal(notDisabled, document.activeElement, 'arrow focuses on the last non-disabled item')

const disabled = details.querySelector('[aria-disabled="true"]')
Expand Down Expand Up @@ -423,7 +423,6 @@ describe('details-menu element', function () {
<details>
<summary>Click</summary>
<details-menu>
<button type="button" role="menuitem" aria-disabled="true">Hubot</button>
<button type="button" role="menuitem" disabled>Bender</button>
</details-menu>
</details>
Expand Down

0 comments on commit 271d1d6

Please sign in to comment.