Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): remove onInput option #437

Merged
merged 1 commit into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions packages/autocomplete-core/src/__tests__/getInputProps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1068,9 +1068,14 @@ describe('getInputProps', () => {
});
});

test('calls onInput and onSelect without item URL', async () => {
test('calls getSources and onSelect without item URL', async () => {
const onSelect = jest.fn();
const onInput = jest.fn();
const getSources = jest.fn(() => [
createSource({
onSelect,
getItems: () => [{ label: '1' }, { label: '2' }],
}),
]);
const navigator = createNavigator();
const {
inputElement,
Expand All @@ -1082,30 +1087,26 @@ describe('getInputProps', () => {
setActiveItemId,
setStatus,
} = createPlayground(createAutocomplete, {
onInput,
navigator,
defaultActiveItemId: 0,
initialState: {
isOpen: true,
collections: [
createCollection({
source: { onSelect },
items: [{ label: '1' }, { label: '2' }],
}),
],
},
getSources,
});

inputElement.focus();
userEvent.type(inputElement, '{enter}');
userEvent.type(inputElement, 'a');
await runAllMicroTasks();

expect(getSources).toHaveBeenCalledTimes(1);

expect(onInput).toHaveBeenCalledTimes(1);
userEvent.type(inputElement, '{enter}');
await runAllMicroTasks();

expect(getSources).toHaveBeenCalledTimes(2);
expect(onSelect).toHaveBeenCalledTimes(1);
expect(onSelect).toHaveBeenCalledWith({
event: expect.any(KeyboardEvent),
item: { label: '1' },
itemInputValue: '',
item: expect.objectContaining({ label: '1' }),
itemInputValue: 'a',
itemUrl: undefined,
refresh,
setCollections,
Expand All @@ -1118,14 +1119,17 @@ describe('getInputProps', () => {
state: {
collections: [
{
items: [{ label: '1' }, { label: '2' }],
items: [
expect.objectContaining({ label: '1' }),
expect.objectContaining({ label: '2' }),
],
source: expect.any(Object),
},
],
completion: null,
context: {},
isOpen: false,
query: '',
query: 'a',
activeItemId: 0,
status: 'idle',
},
Expand Down
11 changes: 0 additions & 11 deletions packages/autocomplete-core/src/onInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@ export function onInput<TItem extends BaseItem>({
store,
...setters
}: OnInputParams<TItem>): Promise<void> {
if (props.onInput) {
return Promise.resolve(
props.onInput({
query,
refresh,
state: store.getState(),
...setters,
})
);
}

if (lastStalledId) {
props.environment.clearTimeout(lastStalledId);
}
Expand Down
7 changes: 0 additions & 7 deletions packages/autocomplete-core/src/types/AutocompleteOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,6 @@ export interface AutocompleteOptions<TItem extends BaseItem> {
* The function called when the Autocomplete form is reset.
*/
onReset?(params: OnResetParams<TItem>): void;
/**
* The function called when the input changes.
*
* This turns the experience in controlled mode, leaving you in charge of
* updating the state.
*/
onInput?(params: OnInputParams<TItem>): void;
/**
* The array of plugins.
*/
Expand Down
8 changes: 0 additions & 8 deletions packages/website/docs/partials/createAutocomplete-props.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,6 @@ The function called when the Autocomplete form is submitted.

The function called when the Autocomplete form is reset.

### `onInput`

> `(params: { query: string, state: AutocompleteState, ...setters }) => void`

The function called when the input changes.

This turns the experience in controlled mode, leaving you in charge of updating the state.

### `debug`

> `boolean` | defaults to `false`
Expand Down