Skip to content

Commit

Permalink
fix: intermittent issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Carol Sachdeva committed Jun 17, 2022
1 parent abfc7b3 commit b7d1352
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/p2p/src/components/search-box/search-box.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ const SearchBox = ({ className, onClear, onSearch, placeholder }) => {
}
};

const onSearchKeyDown = (search, submitForm) => (search ? submitForm() : onClear());

const onSearchKeyUp = submitForm => {
const onSearchKeyUpDown = submitForm => {
clearTimeout(typing_timer);

const typing_timer = setTimeout(() => {
submitForm();
}, 1000);
}, 500);
};

const onSearchSubmit = ({ search }) => {
if (!search.trim()) {
if (typeof onClear === 'function') {
onClear();
}
return;
}

Expand All @@ -46,8 +47,8 @@ const SearchBox = ({ className, onClear, onSearch, placeholder }) => {
type='text'
name='search'
placeholder={placeholder}
onKeyDown={() => onSearchKeyDown(search, submitForm)}
onKeyUp={() => onSearchKeyUp(submitForm)}
onKeyDown={() => onSearchKeyUpDown(submitForm)}
onKeyUp={() => onSearchKeyUpDown(submitForm)}
onFocus={submitForm}
leading_icon={<Icon className='search-box__field-icon' icon='IcSearch' />}
trailing_icon={
Expand Down

0 comments on commit b7d1352

Please sign in to comment.