fix: search autofocus
This commit is contained in:
1 parent
a64866fdf5
commit
b2eef6c494
3 files changed
+29
-19
No files matched your search
@@ -11,7 +11,7 @@ import { Input } from '@/components/ui/input';
|
|||||||
|
|
||||||
import useSearch from './useSearch';
|
import useSearch from './useSearch';
|
||||||
|
|
||||||
const Search: FC<InstanceProps<void>> = ({ onResolve }) => {
|
export const showSearchModal = create(({ onResolve }) => {
|
||||||
const [title, setTitle] = useState('');
|
const [title, setTitle] = useState('');
|
||||||
const [query, setQuery] = useState('');
|
const [query, setQuery] = useState('');
|
||||||
const timeout = useRef<NodeJS.Timeout>();
|
const timeout = useRef<NodeJS.Timeout>();
|
||||||
@@ -38,28 +38,30 @@ const Search: FC<InstanceProps<void>> = ({ onResolve }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal className='block p-3 max-w-[950px]' onClose={handleClose}>
|
<Modal className='block p-0 max-w-[940px]' onClose={handleClose}>
|
||||||
<div className='relative'>
|
<div className='relative p-2'>
|
||||||
<Input
|
<Input
|
||||||
|
autoFocus
|
||||||
ref={inputRef}
|
ref={inputRef}
|
||||||
placeholder='Start entering title...'
|
placeholder='Start entering title...'
|
||||||
value={title}
|
value={title}
|
||||||
onChange={handleChangeTitle}
|
onChange={handleChangeTitle}
|
||||||
className='pr-10'
|
className='pr-10 focus-visible:ring-0'
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
|
base
|
||||||
variant='outline'
|
variant='outline'
|
||||||
type='button'
|
type='button'
|
||||||
size='icon'
|
size='icon'
|
||||||
onClick={handleReset}
|
onClick={handleReset}
|
||||||
disabled={!query.length}
|
disabled={!query.length}
|
||||||
className='absolute right-0 top-0'
|
className='absolute right-2 top-2'
|
||||||
>
|
>
|
||||||
<XCircle />
|
<XCircle />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
{Boolean(results?.pages.length && results?.pages?.[0]?.results?.length) && (
|
{Boolean(results?.pages.length && results?.pages?.[0]?.results?.length) && (
|
||||||
<div className='mt-3'>
|
<div className='px-2'>
|
||||||
<List
|
<List
|
||||||
pages={results!.pages as unknown as MovieDBResponse[]}
|
pages={results!.pages as unknown as MovieDBResponse[]}
|
||||||
fetchNextPage={fetchNextPage}
|
fetchNextPage={fetchNextPage}
|
||||||
@@ -71,13 +73,11 @@ const Search: FC<InstanceProps<void>> = ({ onResolve }) => {
|
|||||||
)}
|
)}
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
};
|
});
|
||||||
|
|
||||||
export const showSearchModal = create(Search);
|
|
||||||
|
|
||||||
export default function ToggleSearch() {
|
export default function ToggleSearch() {
|
||||||
return (
|
return (
|
||||||
<Button variant='ghost' size='icon' onClick={() => showSearchModal()}>
|
<Button base variant='ghost' size='icon' onClick={() => showSearchModal()}>
|
||||||
<SearchIcon size={19} />
|
<SearchIcon size={19} />
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -54,11 +54,12 @@ const hostAtom = atomWithStorage<string>('magnet-host', '');
|
|||||||
const showHostManagerModal = create(({ onResolve }) => {
|
const showHostManagerModal = create(({ onResolve }) => {
|
||||||
const [host, setHost] = useAtom(hostAtom);
|
const [host, setHost] = useAtom(hostAtom);
|
||||||
return (
|
return (
|
||||||
<Modal className='p-3 max-w-[200px] m-auto' onClose={onResolve}>
|
<Modal className='p-2 max-w-[200px] m-auto' onClose={onResolve}>
|
||||||
<Input
|
<Input
|
||||||
autoFocus
|
autoFocus
|
||||||
placeholder='Enter host of Elementum'
|
placeholder='Enter host of Elementum'
|
||||||
value={host}
|
value={host}
|
||||||
|
className='focus-visible:ring-0'
|
||||||
onChange={({ target: { value } }) => setHost(value)}
|
onChange={({ target: { value } }) => setHost(value)}
|
||||||
onKeyDown={({ key }) => key === 'Enter' && onResolve()}
|
onKeyDown={({ key }) => key === 'Enter' && onResolve()}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -37,19 +37,28 @@ export interface ButtonProps
|
|||||||
asChild?: boolean;
|
asChild?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Button = React.forwardRef<HTMLButtonElement, HTMLMotionProps<'button'> & Pick<ButtonProps, 'size' | 'variant'>>(
|
const Button = React.forwardRef<
|
||||||
({ className, variant, size, ...props }, ref) => {
|
HTMLButtonElement,
|
||||||
|
HTMLMotionProps<'button'> & Pick<ButtonProps, 'size' | 'variant'> & { base?: boolean }
|
||||||
|
>(({ className, variant, size, base, ...props }, ref) => {
|
||||||
|
if (base)
|
||||||
return (
|
return (
|
||||||
<motion.button
|
<button
|
||||||
className={cn(buttonVariants({ variant, size, className }))}
|
className={cn(buttonVariants({ variant, size, className }))}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
{...props}
|
{...(props as unknown as ButtonProps)}
|
||||||
onClick={undefined}
|
|
||||||
onTap={(e) => props.onClick?.(e as unknown as React.MouseEvent<HTMLButtonElement, MouseEvent>)}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
return (
|
||||||
);
|
<motion.button
|
||||||
|
className={cn(buttonVariants({ variant, size, className }))}
|
||||||
|
ref={ref}
|
||||||
|
{...props}
|
||||||
|
onClick={undefined}
|
||||||
|
onTap={(e) => props.onClick?.(e as unknown as React.MouseEvent<HTMLButtonElement, MouseEvent>)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
Button.displayName = 'Button';
|
Button.displayName = 'Button';
|
||||||
|
|
||||||
export { Button, buttonVariants };
|
export { Button, buttonVariants };
|
||||||
Reference in new issue
Block a user