Skip to content

Commit

Permalink
feat: remove arrow left/right behavior which is not standard
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Aug 30, 2024
1 parent 17e1ac7 commit f4f8307
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 36 deletions.
11 changes: 0 additions & 11 deletions packages/core/src/useSelect/useSelect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,17 +376,6 @@ describe('keyboard features for a single select', () => {
await flush();
expect(screen.getAllByRole('option')[1]).toHaveAttribute('aria-selected', 'false');
});

test('Pressing ArrowRight and ArrowLeft should toggle the selected option without opening the list', async () => {
await renderSelect();

await fireEvent.keyDown(getSelect(), { code: 'ArrowRight' });
expect(screen.getAllByRole('option')[0]).toHaveAttribute('aria-selected', 'true');
await fireEvent.keyDown(getSelect(), { code: 'ArrowRight' });
expect(screen.getAllByRole('option')[1]).toHaveAttribute('aria-selected', 'true');
await fireEvent.keyDown(getSelect(), { code: 'ArrowLeft' });
expect(screen.getAllByRole('option')[0]).toHaveAttribute('aria-selected', 'true');
});
});

describe('keyboard features for a multi select', () => {
Expand Down
25 changes: 0 additions & 25 deletions packages/core/src/useSelect/useSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ export function useSelect<TOption, TValue = TOption>(
errorMessage,
});

function getSelectedIdx() {
return options.value.findIndex(opt => opt.isSelected());
}

function isSingle() {
const isMultiple = toValue(props.multiple);

Expand Down Expand Up @@ -190,13 +186,6 @@ export function useSelect<TOption, TValue = TOption>(

provide(SelectionContextKey, selectionCtx);

function setSelectedByRelativeIdx(relativeIdx: number) {
// Clamps selection between 0 and the array length
const nextIdx = Math.max(0, Math.min(options.value.length - 1, getSelectedIdx() + relativeIdx));
const option = options.value[nextIdx];
selectionCtx.toggleValue(option.getValue());
}

const handlers = {
onClick() {
isOpen.value = !isOpen.value;
Expand All @@ -207,20 +196,6 @@ export function useSelect<TOption, TValue = TOption>(
isOpen.value = true;
return;
}

if (!selectionCtx.isMultiple() && !isOpen.value) {
if (e.code === 'ArrowLeft') {
e.preventDefault();
setSelectedByRelativeIdx(-1);
return;
}

if (e.code === 'ArrowRight') {
e.preventDefault();
setSelectedByRelativeIdx(1);
return;
}
}
},
};

Expand Down

0 comments on commit f4f8307

Please sign in to comment.