Skip to content

Commit 89322d9

Browse files
authored
feat: add keyup event to search input (#163)
Optimize the operation path, before it required a mouse click every time to get to the preview page
1 parent a2a4ef1 commit 89322d9

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/components/Search.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ export default function Search() {
3737
},
3838
]);
3939
const name = pkg && pkg.name ? `${pkg.name}@${pkg.version}` : pkgname;
40+
const gotoPreview = () => {
41+
if (value) {
42+
dispatch.global.update({ showSearch: false });
43+
navigate(`/pkg/${value}`);
44+
}
45+
}
4046
return (
4147
<Fragment>
4248
<Input
@@ -47,14 +53,14 @@ export default function Search() {
4753
onChange={(e) => {
4854
setValue(e.target.value);
4955
}}
56+
onKeyUp={(e) => {
57+
if (e.key === "Enter") {
58+
gotoPreview();
59+
}
60+
}}
5061
addonAfter={
5162
<Button
52-
onClick={() => {
53-
if (value) {
54-
dispatch.global.update({ showSearch: false });
55-
navigate(`/pkg/${value}`);
56-
}
57-
}}
63+
onClick={gotoPreview}
5864
icon="arrow-right"
5965
size="small"
6066
basic

0 commit comments

Comments
 (0)