fix: search autofocus

This commit is contained in:
ner committed 2024-04-04 18:30:11 +03:00
1 parent a64866fdf5
commit b2eef6c494
3 files changed
+25 -15

No files matched your search

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