Skip to content

Commit

Permalink
chore: 🔨 搜索框
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuba-Ahhh committed Oct 15, 2024
1 parent ba22869 commit 10dc64a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 1 addition & 5 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ const Navbar = () => {
</Link>
</li>
<div className="flex-grow flex justify-end items-center space-x-4">
<SearchInput
placeholder="输入关键词..."
onSearch={(event) => console.log(event.target.value)}
className="mr-2"
/>
<SearchInput placeholder="输入关键词..." className="mr-2" />
{[
{ name: '剑来', path: '/' },
{ name: '雪中', path: '/xuezhong' },
Expand Down
6 changes: 3 additions & 3 deletions src/components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { http, truncateString } from 'utils';

export type SearchInputProps = {
placeholder?: string; // 输入框的占位符文本
onSearch: (event: ChangeEvent<HTMLInputElement>) => void; // 用户输入时触发的回调函数
onSearch?: (event: ChangeEvent<HTMLInputElement>) => void; // 用户输入时触发的回调函数
className?: string; // 额外的类名
style?: React.CSSProperties; // 额外的内联样式
};
Expand All @@ -19,7 +19,7 @@ type ResSearchSuggest = {

const SearchInput: React.FC<SearchInputProps> = ({
placeholder = '输入关键词...',
onSearch,
onSearch = () => {},
className = '',
style = {},
}) => {
Expand Down Expand Up @@ -53,7 +53,7 @@ const SearchInput: React.FC<SearchInputProps> = ({
const value = event.target.value;

setInputValue(value);
onSearch(event);
onSearch && onSearch(event);
if (value) {
fetchSearchResults(value);
} else {
Expand Down

0 comments on commit 10dc64a

Please sign in to comment.