mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-24 17:43:45 +03:00
fix: Add debounce for 300 ms when searching (#1089)
Co-authored-by: Roman Hotsiy <gotsijroman@gmail.com>
This commit is contained in:
parent
af415e89e8
commit
373f018d0c
|
@ -27,6 +27,8 @@ describe('Search', () => {
|
|||
it('should support arrow navigation', () => {
|
||||
getSearchInput().type('int', { force: true });
|
||||
|
||||
cy.wait(500);
|
||||
|
||||
getSearchInput().type('{downarrow}', { force: true });
|
||||
getResult(0).should('have.class', 'active');
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import { MenuItem } from '../SideMenu/MenuItem';
|
|||
import { MarkerService } from '../../services/MarkerService';
|
||||
import { SearchResult } from '../../services/SearchWorker.worker';
|
||||
|
||||
import { bind, debounce } from 'decko';
|
||||
import { PerfectScrollbarWrap } from '../../common-elements/perfect-scrollbar';
|
||||
import {
|
||||
ClearIcon,
|
||||
|
@ -94,11 +95,18 @@ export class SearchBox extends React.PureComponent<SearchBoxProps, SearchBoxStat
|
|||
setResults(results: SearchResult[], term: string) {
|
||||
this.setState({
|
||||
results,
|
||||
term,
|
||||
});
|
||||
this.props.marker.mark(term);
|
||||
}
|
||||
|
||||
@bind
|
||||
@debounce(400)
|
||||
searchCallback(searchTerm: string) {
|
||||
this.props.search.search(searchTerm).then(res => {
|
||||
this.setResults(res, searchTerm);
|
||||
});
|
||||
}
|
||||
|
||||
search = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const q = event.target.value;
|
||||
if (q.length < 3) {
|
||||
|
@ -106,13 +114,12 @@ export class SearchBox extends React.PureComponent<SearchBoxProps, SearchBoxStat
|
|||
return;
|
||||
}
|
||||
|
||||
this.setState({
|
||||
term: q,
|
||||
});
|
||||
|
||||
this.props.search.search(event.target.value).then(res => {
|
||||
this.setResults(res, q);
|
||||
});
|
||||
this.setState(
|
||||
{
|
||||
term: q,
|
||||
},
|
||||
() => this.searchCallback(this.state.term),
|
||||
);
|
||||
};
|
||||
|
||||
render() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user