Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: autocomplete select #74

Merged
merged 1 commit into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 32 additions & 18 deletions src/layouts/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,25 @@ const Header: React.FC<{}> = () => {
>
<Autocomplete
disablePortal
blurOnSelect
id='combo-box-demo'
open={openSearch}
autoComplete
onClose={() => setOpenSearch(false)}
onOpen={() => setOpenSearch(true)}
onKeyDown={(event) => {
if (event.key === 'Enter') {
// Prevent's default 'Enter' behavior.
event.defaultMuiPrevented = true;
const tool = allTools.find(
(item) => item.label === (event.target as any)?.value || ''
);
if (tool) {
setOpenSearch(false);
router.push(tool.path);
}
// your handler code
}
}}
filterOptions={(menu, state) =>
menu.filter((item) => {
return (
Expand All @@ -143,30 +157,30 @@ const Header: React.FC<{}> = () => {
})
}
options={allTools}
renderOption={(props: object, option: Tool) => (
<Box
sx={{
borderBottom: '1px solid rgba(0, 0, 0, 0.05)',
'&:hover': {
background: 'rgba(17, 35, 90, 0.05)',
},
}}
>
<Link
href={option.path}
className='custom-link'
renderOption={(props: object, option: Tool, state) => {
return (
<Box
sx={{
borderBottom: '1px solid rgba(0, 0, 0, 0.05)',
'&:hover': {
background: 'rgba(17, 35, 90, 0.05)',
},
}}
onClick={() => setOpenSearch(false)}
{...props}
>
<ToolCard tool={option} showStar={false} />
</Link>
</Box>
)}
<Link href={option.path} className='custom-link'>
<ToolCard tool={option} showStar={false} />
</Link>
</Box>
);
}}
sx={{ height: '100%' }}
autoHighlight
renderInput={(params) => (
<Stack direction='row'>
<SearchIcon sx={{ mt: 1, mx: 1 }} />
<TextField
// autoFocus
{...params}
placeholder='搜索'
sx={{ height: '100%' }}
Expand Down
5 changes: 5 additions & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export default function App({
name='viewport'
content='width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no'
/>
<title>
{currentItem?.label
? currentItem?.label + ' - 百川在线工具箱'
: '百川云常用工具'}
</title>
<meta
name='description'
property='og:description'
Expand Down
7 changes: 0 additions & 7 deletions src/utils/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,6 @@ export const allTools: Tool[] = [
key: [],
subTitle: 'JSON 转 Go 结构体。',
},
{
label: 'CIDR 计算器',
tags: [Tags.OTHER, Tags.HOT],
path: '/cidr',
key: [],
subTitle: '计算 cidr 的小工具',
},
{
label: 'JSON 转 yaml',
tags: [Tags.JSON],
Expand Down