Skip to content

Commit

Permalink
feat: allow typeable space on all v9 comboboxes, not only freeform (#…
Browse files Browse the repository at this point in the history
…30295)

Co-authored-by: Oleksandr Fediashov <[email protected]>
  • Loading branch information
smhigley and layershifter authored Jan 12, 2024
1 parent f2a9a69 commit 38b6a76
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat: allow typeable space on all comboboxes, not only freeform",
"packageName": "@fluentui/react-combobox",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -497,12 +497,49 @@ describe('Combobox', () => {

expect((getByRole('combobox') as HTMLInputElement).value).toEqual('Red');

// arrow down + space
// space should select after an arrow down
userEvent.keyboard('{ArrowDown} ');

expect((getByRole('combobox') as HTMLInputElement).value).toEqual('Green');
});

it('allows to input space', () => {
const { getByRole, getByText } = render(
<Combobox open>
<Option>Slice of pizza</Option>
<Option>Slice of cake</Option>
<Option>Slice of pie</Option>
</Combobox>,
);

const combobox = getByRole('combobox');

userEvent.type(combobox, 'Slice of pie');
userEvent.type(combobox, '{Enter}');

expect(getByText('Slice of pie').getAttribute('aria-selected')).toEqual('true');
expect((combobox as HTMLInputElement).value).toEqual('Slice of pie');
});

it('does not select with space while typing', () => {
const onSelect = jest.fn();

const { getByTestId, getByRole } = render(
<Combobox open data-testid="combobox" onOptionSelect={onSelect}>
<Option>Red</Option>
<Option>Green</Option>
<Option>Blue</Option>
</Combobox>,
);

const combobox = getByTestId('combobox');

userEvent.type(combobox, 'abc def');

expect((getByRole('combobox') as HTMLInputElement).value).toEqual('abc def');
expect(onSelect).not.toHaveBeenCalled();
});

it('does not select a disabled option with the keyboard', () => {
const { getByTestId, getByRole } = render(
<Combobox open data-testid="combobox">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export function useInputTriggerSlot(
}

// allow space to insert a character if freeform & the last action was typing, or if the popup is closed
if (freeform && (isTyping.current || !open) && ev.key === ' ') {
if ((isTyping.current || !open) && ev.key === ' ') {
triggerFromProps?.onKeyDown?.(ev);
return;
}
Expand Down

0 comments on commit 38b6a76

Please sign in to comment.