From 861489ccc27231b93f71d30a501a9f6f2c3144e2 Mon Sep 17 00:00:00 2001 From: royhansen99 Date: Wed, 21 Feb 2024 12:23:51 +0100 Subject: [PATCH] Fix bug when `autoFocus` is set to `true`, and `value` is empty, the initial value typed into the hour input is cleared as soon as you finish typing and move to the minutes input. Will now use `autoFocus` when setting initial value for `isOpen`, if `isOpenProps` is undefined. Explanation of the bug: The TimePicker input is focused as expected, but the `isOpen` property is not set to `true`. This causes the `isOpen` property to be set to `true` as soon as you land on the second input (minutes), which again leads to the hours being cleared. --- packages/react-time-picker/src/TimePicker.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react-time-picker/src/TimePicker.tsx b/packages/react-time-picker/src/TimePicker.tsx index 8b063a98..8b26eb20 100644 --- a/packages/react-time-picker/src/TimePicker.tsx +++ b/packages/react-time-picker/src/TimePicker.tsx @@ -368,12 +368,12 @@ const TimePicker: React.FC = function TimePicker(props) { ...otherProps } = props; - const [isOpen, setIsOpen] = useState(isOpenProps); + const [isOpen, setIsOpen] = useState(isOpenProps ?? autoFocus ?? null); const wrapper = useRef(null); const clockWrapper = useRef(null); useEffect(() => { - setIsOpen(isOpenProps); + setIsOpen(isOpenProps ?? autoFocus ?? null); }, [isOpenProps]); function openClock({ reason }: { reason: OpenReason }) {