Skip to content

Commit

Permalink
fix Time input for custom time is not auto focused
Browse files Browse the repository at this point in the history
  • Loading branch information
tienifr committed Jan 18, 2024
1 parent 4da7fda commit 76a26c4
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/components/TimePicker/TimePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Button from '@components/Button';
import FormHelpMessage from '@components/FormHelpMessage';
import refPropTypes from '@components/refPropTypes';
import Text from '@components/Text';
import useAutoFocusInput from '@hooks/useAutoFocusInput';
import useKeyboardShortcut from '@hooks/useKeyboardShortcut';
import useLocalize from '@hooks/useLocalize';
import useStyleUtils from '@hooks/useStyleUtils';
Expand Down Expand Up @@ -127,6 +128,8 @@ function TimePicker({forwardedRef, defaultValue, onSubmit, onInputChange}) {
const hourInputRef = useRef(null);
const minuteInputRef = useRef(null);

const {inputCallbackRef} = useAutoFocusInput();

const focusMinuteInputOnFirstCharacter = useCallback(() => setCursorPosition(0, minuteInputRef, setSelectionMinute), []);
const focusHourInputOnLastCharacter = useCallback(() => setCursorPosition(2, hourInputRef, setSelectionHour), []);

Expand Down Expand Up @@ -492,6 +495,7 @@ function TimePicker({forwardedRef, defaultValue, onSubmit, onInputChange}) {
minuteInputRef.current = {hourRef: hourInputRef.current, minuteInputRef: ref};
}
minuteInputRef.current = ref;
inputCallbackRef(ref);
}}
onSelectionChange={(e) => {
setSelectionMinute(e.nativeEvent.selection);
Expand Down

0 comments on commit 76a26c4

Please sign in to comment.