From 31260375b7d44254ff48dc1a7b38b362b3d0cce2 Mon Sep 17 00:00:00 2001 From: Mohammer5 Date: Mon, 4 Nov 2024 15:43:08 +0800 Subject: [PATCH] fix(select a11y): handle focussed option index separately when filtering --- .../__stories__/InfiniteLoading.js | 2 - .../keyboard-interactions.test.e2e.js | 7 +- .../single-select-a11y/menu/menu-filter.js | 4 + .../src/single-select-a11y/menu/menu.js | 26 +++-- .../src/single-select-a11y/menu/option.js | 2 +- .../single-select-a11y/single-select-a11y.js | 51 +++++++++- .../single-select-a11y.test.js | 14 ++- .../use-highlight-last-option-on-next-page.js | 99 +++++++++---------- .../use-handle-key-press/use-page-down.js | 2 +- 9 files changed, 127 insertions(+), 80 deletions(-) diff --git a/components/select/src/single-select-a11y/__stories__/InfiniteLoading.js b/components/select/src/single-select-a11y/__stories__/InfiniteLoading.js index 6b3750097..6744436fa 100644 --- a/components/select/src/single-select-a11y/__stories__/InfiniteLoading.js +++ b/components/select/src/single-select-a11y/__stories__/InfiniteLoading.js @@ -33,7 +33,6 @@ export const InfiniteLoading = () => { const loadNextOptions = useCallback(() => { const nextPage = curLoadedPage + 1 - console.log('>', { nextPage, loading }) if ( // We're already loading a page @@ -41,7 +40,6 @@ export const InfiniteLoading = () => { // No need to load anything when already loaded everything nextPage >= optionChunks.length ) { - console.log('> do nothing') return } diff --git a/components/select/src/single-select-a11y/features/keyboard-interactions.test.e2e.js b/components/select/src/single-select-a11y/features/keyboard-interactions.test.e2e.js index 4df11efd4..bfc6b396b 100644 --- a/components/select/src/single-select-a11y/features/keyboard-interactions.test.e2e.js +++ b/components/select/src/single-select-a11y/features/keyboard-interactions.test.e2e.js @@ -23,7 +23,6 @@ describe('', () => { cy.findByRole('option', { selected: true }) .invoke('parent') // listbox - .invoke('parent') // .listbox-container .invoke('parent') // scrollable div .then((listBoxParent) => { listBoxParent.get(0).scrollTop = optionOffset @@ -71,7 +70,6 @@ describe('', () => { cy.findByRole('option', { selected: true }) .invoke('parent') // listbox - .invoke('parent') // .listbox-container .invoke('parent') // scrollable div .then((listBoxParent) => { listBoxParent.get(0).scrollTop = optionOffset @@ -183,7 +181,6 @@ describe('', () => { cy.findByRole('option', { selected: true }) .invoke('parent') // listbox - .invoke('parent') // .listbox-container .invoke('parent') // scrollable div .then((listBoxParent) => { listBoxParent.get(0).scrollTop = optionOffset @@ -228,7 +225,6 @@ describe('', () => { cy.findByRole('option', { selected: true }) .invoke('parent') // listbox - .invoke('parent') // .listbox-container .invoke('parent') // scrollable div .then((listBoxParent) => { listBoxParent.get(0).scrollTop = optionOffset @@ -408,7 +404,6 @@ describe('', () => { cy .findByRole('option', { selected: true }) .invoke('parent') - .invoke('parent') // .listbox-container .invoke('parent') ).then(([nextTopOption, listBoxParent]) => { const { offsetTop } = nextTopOption.get(0) @@ -528,7 +523,7 @@ describe('', () => { ) cy.all( () => cy.findAllByRole('option').eq(89), - () => cy.findByRole('listbox').invoke('parent').invoke('parent') // scrollable div + () => cy.findByRole('listbox').invoke('parent') // scrollable div ).then(([nextTopOption, listBoxParent]) => { const { offsetTop } = nextTopOption.get(0) listBoxParent.get(0).scrollTop = offsetTop diff --git a/components/select/src/single-select-a11y/menu/menu-filter.js b/components/select/src/single-select-a11y/menu/menu-filter.js index c90ec1cec..8d6aee173 100644 --- a/components/select/src/single-select-a11y/menu/menu-filter.js +++ b/components/select/src/single-select-a11y/menu/menu-filter.js @@ -5,6 +5,7 @@ import React from 'react' import i18n from '../../locales/index.js' export function MenuFilter({ + idPrefix, value, onChange, dataTest, @@ -16,6 +17,8 @@ export function MenuFilter({
{filterable && ( - - {loading && ( -
- -
- )}
+ {loading && ( +
+ +
+ )} +