Skip to content

Commit

Permalink
Components: refactor Autocomplete to pass exhaustive-deps (#41382)
Browse files Browse the repository at this point in the history
* update `AutoCompleterUI` `useLayoutEffect` dependency array to include `onChangeOptions`
* update `AutoCompleterUI` native.js `useLayoutEffect` and `startAnimation` `useCallback` dependency arrays
* update `useAutocomplete` `useEffect` dependency array
* Autocomplete: rebase and fix changelog merge conflict
  • Loading branch information
chad1008 authored May 31, 2022
1 parent 0897b17 commit f3da470
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- `TextareaControl`: Convert to TypeScript ([#41215](https://github.com/WordPress/gutenberg/pull/41215)).
- `BoxControl`: Update unit tests to use `@testing-library/user-event` ([#41422](https://github.com/WordPress/gutenberg/pull/41422)).
- `Surface`: Convert to TypeScript ([#41212](https://github.com/WordPress/gutenberg/pull/41212)).
- `Autocomplete` updated to satisfy `react/exhuastive-deps` eslint rule ([#41382](https://github.com/WordPress/gutenberg/pull/41382))

### Experimental

Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/autocomplete/autocompleter-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function getAutoCompleterUI( autocompleter ) {

useLayoutEffect( () => {
onChangeOptions( items );
}, [ items ] );
}, [ onChangeOptions, items ] );

if ( ! items.length > 0 ) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function getAutoCompleterUI( autocompleter ) {
} else if ( isVisible && text.length === 0 ) {
startAnimation( false );
}
}, [ items, isVisible, text ] );
}, [ onChangeOptions, items, isVisible, text, startAnimation ] );

const activeItemStyles = usePreferredColorSchemeStyle(
styles[ 'components-autocomplete__item-active' ],
Expand Down Expand Up @@ -111,7 +111,7 @@ export function getAutoCompleterUI( autocompleter ) {
}
} );
},
[ isVisible ]
[ animationValue, isVisible, reset ]
);

const contentStyles = {
Expand Down
9 changes: 8 additions & 1 deletion packages/components/src/autocomplete/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,14 @@ function useAutocomplete( {
: AutocompleterUI
);
setFilterValue( query );
}, [ textContent ] );
}, [
textContent,
AutocompleterUI,
autocompleter,
completers,
record,
filteredOptions.length,
] );

const { key: selectedKey = '' } = filteredOptions[ selectedIndex ] || {};
const { className } = autocompleter || {};
Expand Down

0 comments on commit f3da470

Please sign in to comment.