mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-21 00:01:22 +02:00
Fix autoSelect for PlainInput.tsx
This commit is contained in:
@@ -32,6 +32,7 @@ export const PlainInput = forwardRef<HTMLInputElement, PlainInputProps>(function
|
|||||||
size = 'md',
|
size = 'md',
|
||||||
type = 'text',
|
type = 'text',
|
||||||
validate,
|
validate,
|
||||||
|
autoSelect,
|
||||||
...props
|
...props
|
||||||
}: PlainInputProps,
|
}: PlainInputProps,
|
||||||
ref,
|
ref,
|
||||||
@@ -39,11 +40,15 @@ export const PlainInput = forwardRef<HTMLInputElement, PlainInputProps>(function
|
|||||||
const [obscured, setObscured] = useStateWithDeps(type === 'password', [type]);
|
const [obscured, setObscured] = useStateWithDeps(type === 'password', [type]);
|
||||||
const [currentValue, setCurrentValue] = useState(defaultValue ?? '');
|
const [currentValue, setCurrentValue] = useState(defaultValue ?? '');
|
||||||
const [focused, setFocused] = useState(false);
|
const [focused, setFocused] = useState(false);
|
||||||
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
const handleFocus = useCallback(() => {
|
const handleFocus = useCallback(() => {
|
||||||
setFocused(true);
|
setFocused(true);
|
||||||
|
if (autoSelect) {
|
||||||
|
inputRef.current?.select();
|
||||||
|
}
|
||||||
onFocus?.();
|
onFocus?.();
|
||||||
}, [onFocus]);
|
}, [autoSelect, onFocus]);
|
||||||
|
|
||||||
const handleBlur = useCallback(() => {
|
const handleBlur = useCallback(() => {
|
||||||
setFocused(false);
|
setFocused(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user