Skip to content

Commit

Permalink
Merge pull request #34712 from tienifr/fix/34002
Browse files Browse the repository at this point in the history
fix Time input for custom time is not auto focused
  • Loading branch information
yuwenmemon authored Jan 23, 2024
2 parents d8fb3f4 + 76a26c4 commit bb86e24
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 bb86e24

Please sign in to comment.