Skip to content

Commit

Permalink
feat: remove throttle for keydown handler (#132)
Browse files Browse the repository at this point in the history
* feat: remove throttle for keydown handler

* Create tough-cooks-remain.md

Co-authored-by: yangxingyuan <39261479+sanyuan0704@users.noreply.github.com>
  • Loading branch information
younggglcy and sanyuan0704 committed Oct 31, 2022
1 parent ba87fe4 commit 5c1be07
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changeset/tough-cooks-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@islandjs/plugin-search": patch
"@islandjs/plugin-backtop": patch
"islandjs": patch
---

feat: remove throttle for keydown handler
5 changes: 2 additions & 3 deletions packages/plugin-search/src/component/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ChangeEvent, useCallback, useEffect, useRef, useState } from 'react';
import type { MatchResultItem, PageSearcher } from '../logic/search';
import SearchSvg from '../assets/search.svg';
import LoadingSvg from '../assets/loading.svg';
import { throttle } from 'lodash-es';
import { SuggestionContent } from './Suggestion';

const KEY_CODE = {
Expand Down Expand Up @@ -59,7 +58,7 @@ export function Search(
);

useEffect(() => {
const onKeyDown = throttle((e: KeyboardEvent) => {
const onKeyDown = (e: KeyboardEvent) => {
switch (e.code) {
case KEY_CODE.SEARCH:
if ((e.ctrlKey || e.metaKey) && searchInputRef.current) {
Expand Down Expand Up @@ -95,7 +94,7 @@ export function Search(
default:
break;
}
}, 200);
};
document.addEventListener('keydown', onKeyDown);
return () => {
document.removeEventListener('keydown', onKeyDown);
Expand Down

1 comment on commit 5c1be07

@vercel
Copy link

@vercel vercel bot commented on 5c1be07 Oct 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.