Skip to content

Commit c0c6de5

Browse files
committed
chore: Implement the same for multiselect
1 parent 5d6a4cc commit c0c6de5

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/multiselect/__tests__/multiselect.test.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { warnOnce } from '@cloudscape-design/component-toolkit/internal';
77
import { KeyCode } from '@cloudscape-design/test-utils-core/utils';
88

99
import '../../__a11y__/to-validate-a11y';
10+
import TestI18nProvider from '../../../lib/components/i18n/testing';
1011
import Multiselect, { MultiselectProps } from '../../../lib/components/multiselect';
1112
import createWrapper from '../../../lib/components/test-utils/dom';
1213

@@ -534,6 +535,25 @@ describe.each([true, false])('footer live announcements [expandToViewport=%s]',
534535
});
535536
});
536537

538+
test('Shifts focus to the filter on retry failed request', () => {
539+
const { wrapper } = renderMultiselect(
540+
<TestI18nProvider messages={{ select: { recoveryText: 'Custom recovery text' } }}>
541+
<Multiselect
542+
selectedOptions={[]}
543+
options={defaultOptions}
544+
onChange={() => {}}
545+
onLoadItems={() => {}}
546+
errorText="Error fetching items"
547+
statusType="error"
548+
filteringType="auto"
549+
/>
550+
</TestI18nProvider>
551+
);
552+
wrapper.openDropdown();
553+
wrapper.findErrorRecoveryButton()!.click();
554+
expect(wrapper.findFilteringInput()!.findNativeInput()!.getElement()).toHaveFocus();
555+
});
556+
537557
test('fires a change event when user selects a group option from the dropdown', () => {
538558
const onChange = jest.fn();
539559
const { wrapper } = renderMultiselect(

src/multiselect/use-multiselect.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ export function useMultiselect({
190190
getOptionProps,
191191
highlightOption,
192192
announceSelected,
193+
focusActiveRef,
193194
} = useSelect({
194195
selectedOptions,
195196
updateSelectedOption,
@@ -233,7 +234,10 @@ export function useMultiselect({
233234
isNoMatch,
234235
noMatch,
235236
filteringResultsText: filteredText,
236-
onRecoveryClick: handleRecoveryClick,
237+
onRecoveryClick: () => {
238+
handleRecoveryClick();
239+
focusActiveRef();
240+
},
237241
errorIconAriaLabel: errorIconAriaLabel,
238242
hasRecoveryCallback: !!onLoadItems,
239243
});

0 commit comments

Comments
 (0)