Skip to content

Commit

Permalink
fix: autocomplete select
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomeYG committed Dec 29, 2023
1 parent b090748 commit d8f06ea
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
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

0 comments on commit d8f06ea

Please sign in to comment.