Skip to content

Commit 0560aeb

Browse files
committed
UI: Fix kb nav bug on reset options in Select
1 parent 9e7805b commit 0560aeb

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

code/core/src/components/components/Select/Select.stories.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,47 @@ export const KeyboardSelectionMultiSS = meta.story({
429429
play: kbMultiSelectionTest(' ', ' '),
430430
});
431431

432+
export const FullArrowNavigation = meta.story({
433+
play: async ({ canvas, step }) => {
434+
const selectButton = await canvas.findByRole('button');
435+
await step('Open select', async () => {
436+
selectButton.focus();
437+
await userEvent.keyboard('{ArrowDown}');
438+
expect(selectButton).toHaveTextContent('Tadpole');
439+
});
440+
441+
await step('Navigate to option 2 with ArrowDown', async () => {
442+
await userEvent.keyboard('{ArrowDown}');
443+
expect(selectButton).toHaveTextContent('Pollywog');
444+
});
445+
446+
await step('Navigate to option 3 with ArrowDown', async () => {
447+
await userEvent.keyboard('{ArrowDown}');
448+
expect(selectButton).toHaveTextContent('Frog');
449+
});
450+
451+
await step('Loop back to option 1 with ArrowDown', async () => {
452+
await userEvent.keyboard('{ArrowDown}');
453+
expect(selectButton).toHaveTextContent('Tadpole');
454+
});
455+
456+
await step('Navigate backwards with ArrowUp', async () => {
457+
await userEvent.keyboard('{ArrowUp}');
458+
expect(selectButton).toHaveTextContent('Frog');
459+
});
460+
461+
await step('Navigate backwards with ArrowUp', async () => {
462+
await userEvent.keyboard('{ArrowUp}');
463+
expect(selectButton).toHaveTextContent('Pollywog');
464+
});
465+
466+
await step('Navigate back to option 1 with ArrowUp', async () => {
467+
await userEvent.keyboard('{ArrowUp}');
468+
expect(selectButton).toHaveTextContent('Tadpole');
469+
});
470+
},
471+
});
472+
432473
export const MouseOpenNoAutoselect = meta.story({
433474
name: 'AutoSelect - nothing selected on Mouse open (single)',
434475
play: async ({ canvas, args, step }) => {

code/core/src/components/components/Select/Select.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,10 @@ export const Select = forwardRef<HTMLButtonElement, SelectProps>(
325325
return;
326326
}
327327

328-
const currentIndex = options.findIndex(
329-
(option) => externalToValue(option.value) === activeOption.value
328+
const currentIndex = options.findIndex((option) =>
329+
activeOption.type === 'reset'
330+
? 'type' in option && option.type === 'reset'
331+
: externalToValue(option.value) === activeOption.value
330332
);
331333
const nextIndex = currentIndex + step;
332334

@@ -349,8 +351,11 @@ export const Select = forwardRef<HTMLButtonElement, SelectProps>(
349351
setActiveOption(options[Math.max(0, options.length - step)]);
350352
return;
351353
}
352-
const currentIndex = options.findIndex(
353-
(option) => externalToValue(option.value) === activeOption.value
354+
355+
const currentIndex = options.findIndex((option) =>
356+
activeOption.type === 'reset'
357+
? 'type' in option && option.type === 'reset'
358+
: externalToValue(option.value) === activeOption.value
354359
);
355360
const nextIndex = currentIndex - step;
356361

0 commit comments

Comments
 (0)