Skip to content

Commit e305a2d

Browse files
SW-1519 Dropdown menu doesn't disappear when you tab to the next field (#532)
1 parent bbe879f commit e305a2d

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/components/Select/SelectT.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -197,18 +197,22 @@ export default function SelectT<T>(props: SelectTProps<T>): JSX.Element {
197197
};
198198

199199
const onKeyDownHandler = (e: KeyboardEvent<HTMLInputElement>) => {
200-
const pressedLetter = e.key.toUpperCase();
201-
const items = dropdownRef.current?.getElementsByTagName('li');
202-
if (items) {
203-
const arrayOfItems = Array.from(items);
204-
for (const item of arrayOfItems) {
205-
if (item.dataset.key === pressedLetter) {
206-
item.scrollIntoView({
207-
behavior: 'smooth',
208-
block: 'start',
209-
});
200+
if (e.key === 'Tab') {
201+
toggleOptions();
202+
} else {
203+
const pressedLetter = e.key.toUpperCase();
204+
const items = dropdownRef.current?.getElementsByTagName('li');
205+
if (items) {
206+
const arrayOfItems = Array.from(items);
207+
for (const item of arrayOfItems) {
208+
if (item.dataset.key === pressedLetter) {
209+
item.scrollIntoView({
210+
behavior: 'smooth',
211+
block: 'start',
212+
});
210213

211-
return;
214+
return;
215+
}
212216
}
213217
}
214218
}

src/stories/Select.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const EditableTemplate: Story<SelectProps> = (args) => {
3434
<Box height='1000px'>
3535
<Box width='200px' margin='0 auto'>
3636
<Select {...args} onChange={handleChange} selectedValue={value} options={options} />
37+
<input />
3738
</Box>
3839
</Box>
3940
</Box>

0 commit comments

Comments
 (0)