Skip to content

Commit

Permalink
fix(behaviour): clear completion on "reset"
Browse files Browse the repository at this point in the history
  • Loading branch information
Haroenv committed Oct 27, 2023
1 parent c82e594 commit 9f07965
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/autocomplete-core/src/__tests__/completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,35 @@ describe('completion', () => {
})
);
});

test('clears completion on "reset"', () => {
const { inputElement, resetElement } = createPlayground(
createAutocomplete,
{
openOnFocus: true,
initialState: {
collections: [
createCollection({
source: {
getItemInputValue({ item }) {
return item.label;
},
},
items: [{ label: '1' }, { label: '2' }],
}),
],
},
}
);
inputElement.focus();

userEvent.type(inputElement, 'Some text to make sure reset shows');
expect(inputElement).toHaveValue('Some text to make sure reset shows');

userEvent.type(inputElement, '{arrowdown}');
expect(inputElement).toHaveValue('1');

resetElement.click();
expect(inputElement).toHaveValue('');
});
});
1 change: 1 addition & 0 deletions packages/autocomplete-core/src/stateReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export const stateReducer: Reducer = (state, action) => {
? action.props.defaultActiveItemId
: null,
status: 'idle',
completion: null,
query: '',
};
}
Expand Down

0 comments on commit 9f07965

Please sign in to comment.