Skip to content

Commit

Permalink
Merge pull request #145 from Neovici/feat/query-case
Browse files Browse the repository at this point in the history
feat(autocomplete): maintain query case
  • Loading branch information
megheaiulian authored Jun 26, 2023
2 parents c386b18 + c69ea4b commit f65df29
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/autocomplete/use-autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const useAutocomplete = <I>({
),
{ active, focused, onFocus, setClosed } = useFocus(thru),
empty = !text,
query = useMemo(() => text?.trim().toLowerCase(), [text]),
query = useMemo(() => text?.trim(), [text]),
host = useHost(),
onText = useNotify(host, _onText, 'text'),
onChange = useCallback(
Expand Down
3 changes: 2 additions & 1 deletion src/autocomplete/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ export const search = <I>(
query: string,
textual: (i: I) => string
) => {
const qry = query.toLowerCase();
const matches = [];
for (const item of source) {
const index = textual(item).toLowerCase().indexOf(query);
const index = textual(item).toLowerCase().indexOf(qry);
if (index < 0) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions test/use-autocomplete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('use-autocomplete', () => {
.textProperty=${'text'}
/>
`);
expect(result.current.query).to.equal('it');
expect(result.current.query).to.equal('It');
expect(await result.current.items$).to.be.empty;
});

Expand Down Expand Up @@ -123,7 +123,7 @@ describe('use-autocomplete', () => {
.external=${true}
/>
`);
expect(result.current.query).to.equal('la');
expect(result.current.query).to.equal('La');
result.current.onFocus({ currentTarget: { matches: () => true } });
await nextFrame();

Expand Down

0 comments on commit f65df29

Please sign in to comment.