Skip to content

Commit

Permalink
fix(react): focus search field on clear
Browse files Browse the repository at this point in the history
  • Loading branch information
dackmin committed Jan 2, 2023
1 parent d8f5206 commit d8e5b24
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/react/lib/SelectField/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ const SelectField = forwardRef(({
dispatch({ placeholderSize: Math.max(10, placeholder?.length ?? 0) });
}, [placeholder]);

useEffect(() => {
if ((multiple || !state.value) && state.dirty && searchable) {
searchInputRef.current?.focus?.();
}
}, [state.value]);

useTimeout(() => {
if (state.search.length >= searchMinCharacters) {
onSearchResults();
Expand Down
2 changes: 1 addition & 1 deletion packages/react/lib/SelectField/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ exports[`<SelectField /> should allow to clear a single value 1`] = `
exports[`<SelectField /> should allow to clear a single value 2`] = `
<div>
<div
class="junipero dropdown select-field dirty valid searchable empty"
class="junipero dropdown select-field dirty valid searchable empty focused"
>
<div
class="field dropdown-toggle"
Expand Down

0 comments on commit d8e5b24

Please sign in to comment.