Skip to content

Commit

Permalink
use debounce to fix loosing focus in EuiSuggest component
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp committed Jan 19, 2021
1 parent 8a00a61 commit de91710
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* under the License.
*/
import React, { useEffect, useState, useCallback } from 'react';
import useDebounce from 'react-use/lib/useDebounce';

import { EuiSuggest, EuiSuggestProps } from '@elastic/eui';
import { getDataStart } from '../../services';
import { INDEXES_SEPARATOR } from '../../../common/constants';
Expand Down Expand Up @@ -58,13 +60,17 @@ export const IndexPatternSuggest = ({
fetchIndexes();
}, []);

useEffect(() => {
if (inputValue !== value) {
onChange({
[indexPatternName]: inputValue,
});
}
}, [onChange, inputValue, indexPatternName, value]);
useDebounce(
() => {
if (inputValue !== value) {
onChange({
[indexPatternName]: inputValue,
});
}
},
300,
[onChange, inputValue, indexPatternName, value]
);

const onItemClick: EuiSuggestProps['onItemClick'] = useCallback(
({ label }) => {
Expand Down

0 comments on commit de91710

Please sign in to comment.