Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
firestar300 committed Oct 10, 2024
2 parents 8f013e3 + c915abf commit 252ef7f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ node_modules/
## Build
dist/

## test
test-results/

## Use yarn instead
package-lock.json
22 changes: 13 additions & 9 deletions src/classes/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,21 +248,12 @@ class Dropdown extends AbstractDomElement {

this.button.setAttribute('aria-expanded', 'true')

const nodeListItems = el.querySelectorAll('li')
const nodeListSelectedItems = el.querySelectorAll('li[aria-selected="true"]')

if (nodeListSelectedItems.length === 1) {
this.updateFocusedListItem(el.querySelector('li[aria-selected="true"]'))
}

if (nodeListSelectedItems.length === 0 && nodeListItems.length >= 1) {
this.focusedElement = el.querySelector('li:first-child')
}

if (this.focusedElement && nodeListSelectedItems.length === 0 && nodeListItems.length > 1) {
this.focusedElement.setAttribute('aria-selected', 'true')
}

if (onOpen) {
onOpen.bind(this)()
}
Expand Down Expand Up @@ -433,6 +424,19 @@ function focusPreviousElement() {
* @author Milan Ricoul
*/
function focusNextElement() {
const el = this._element

if (!this.focusedElement) {
const nodeListItems = el.querySelectorAll('li')
const nodeListSelectedItems = el.querySelectorAll('li[aria-selected="true"]')

if (nodeListSelectedItems.length === 0 && nodeListItems.length >= 1) {
this.updateFocusedListItem(el.querySelector('li:first-child'))
}

return
}

if (this.focusedElement && this.focusedElement.nextElementSibling) {
this.updateFocusedListItem(this.focusedElement.nextElementSibling)

Expand Down
17 changes: 2 additions & 15 deletions src/classes/Dropdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,7 @@ test.describe('Dropdown', () => {
expect(display).toBe('block')
})

test('Click on the dropdown button, expect first list item has aria-selected attribute set to true.', async ({
page,
}) => {
await page.click('#dropdown-1 button')
const hasValidAriaSelected = await page.$eval(
'#dropdown-1 li:first-child',
(firstListItem) =>
firstListItem.hasAttribute('aria-selected') && firstListItem.getAttribute('aria-selected') === 'true'
)

expect(hasValidAriaSelected).toBe(true)
})

test('Focus the dropdown button, press Enter key once, press ArrowDown key twice, expect the third list item has aria-selected attribute set to true.', async ({
test('Focus the dropdown button, press Enter key once, press ArrowDown key twice, expect the second list item has aria-selected attribute set to true.', async ({
page,
}) => {
await page.focus('#dropdown-1 button')
Expand All @@ -34,7 +21,7 @@ test.describe('Dropdown', () => {
await page.keyboard.down('ArrowDown')

const hasValidAriaSelected = await page.$eval(
'#dropdown-1 li:nth-child(3)',
'#dropdown-1 li:nth-child(2)',
(thirdListItem) =>
thirdListItem.hasAttribute('aria-selected') && thirdListItem.getAttribute('aria-selected') === 'true'
)
Expand Down

0 comments on commit 252ef7f

Please sign in to comment.