Skip to content

Commit e1766ef

Browse files
authored
Merge pull request Expensify#62631 from nkdengineer/fix/61595
fix: error in time modal picker
2 parents 22709e3 + bbbe423 commit e1766ef

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

src/components/DatePicker/index.tsx

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,49 @@
11
import {format, setYear} from 'date-fns';
22
import React, {forwardRef, useCallback, useEffect, useMemo, useRef, useState} from 'react';
3+
import type {ForwardedRef} from 'react';
34
import {InteractionManager, View} from 'react-native';
45
import * as Expensicons from '@components/Icon/Expensicons';
56
import TextInput from '@components/TextInput';
7+
import type {BaseTextInputRef} from '@components/TextInput/BaseTextInput/types';
68
import useLocalize from '@hooks/useLocalize';
79
import useThemeStyles from '@hooks/useThemeStyles';
810
import useWindowDimensions from '@hooks/useWindowDimensions';
11+
import mergeRefs from '@libs/mergeRefs';
912
import {setDraftValues} from '@userActions/FormActions';
1013
import CONST from '@src/CONST';
1114
import DatePickerModal from './DatePickerModal';
1215
import type {DateInputWithPickerProps} from './types';
1316

1417
const PADDING_MODAL_DATE_PICKER = 8;
1518

16-
function DatePicker({
17-
defaultValue,
18-
disabled,
19-
errorText,
20-
inputID,
21-
label,
22-
minDate = setYear(new Date(), CONST.CALENDAR_PICKER.MIN_YEAR),
23-
maxDate = setYear(new Date(), CONST.CALENDAR_PICKER.MAX_YEAR),
24-
onInputChange,
25-
onTouched = () => {},
26-
placeholder,
27-
value,
28-
shouldSaveDraft = false,
29-
formID,
30-
autoFocus = false,
31-
shouldHideClearButton = false,
32-
}: DateInputWithPickerProps) {
19+
function DatePicker(
20+
{
21+
defaultValue,
22+
disabled,
23+
errorText,
24+
inputID,
25+
label,
26+
minDate = setYear(new Date(), CONST.CALENDAR_PICKER.MIN_YEAR),
27+
maxDate = setYear(new Date(), CONST.CALENDAR_PICKER.MAX_YEAR),
28+
onInputChange,
29+
onTouched = () => {},
30+
placeholder,
31+
value,
32+
shouldSaveDraft = false,
33+
formID,
34+
autoFocus = false,
35+
shouldHideClearButton = false,
36+
}: DateInputWithPickerProps,
37+
ref: ForwardedRef<BaseTextInputRef>,
38+
) {
3339
const styles = useThemeStyles();
3440
const {windowHeight, windowWidth} = useWindowDimensions();
3541
const {translate} = useLocalize();
3642
const [isModalVisible, setIsModalVisible] = useState(false);
3743
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
3844
const [selectedDate, setSelectedDate] = useState(value || defaultValue || undefined);
3945
const [popoverPosition, setPopoverPosition] = useState({horizontal: 0, vertical: 0});
40-
const textInputRef = useRef<HTMLFormElement | null>(null);
46+
const textInputRef = useRef<BaseTextInputRef>(null);
4147
const anchorRef = useRef<View>(null);
4248
const [isInverted, setIsInverted] = useState(false);
4349
const isAutoFocused = useRef(false);
@@ -119,7 +125,7 @@ function DatePicker({
119125
style={styles.mv2}
120126
>
121127
<TextInput
122-
ref={textInputRef}
128+
ref={mergeRefs(ref, textInputRef)}
123129
inputID={inputID}
124130
forceActiveLabel
125131
icon={selectedDate ? null : Expensicons.Calendar}

src/components/TimeModalPicker.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React, {useState} from 'react';
1+
import React, {forwardRef, useState} from 'react';
2+
import type {ForwardedRef} from 'react';
23
import {View} from 'react-native';
34
import useThemeStyles from '@hooks/useThemeStyles';
45
import DateUtils from '@libs/DateUtils';
@@ -23,7 +24,7 @@ type TimeModalPickerProps = {
2324
label: string;
2425
};
2526

26-
function TimeModalPicker({value, errorText, label, onInputChange = () => {}}: TimeModalPickerProps) {
27+
function TimeModalPicker({value, errorText, label, onInputChange = () => {}}: TimeModalPickerProps, ref: ForwardedRef<View>) {
2728
const styles = useThemeStyles();
2829
const [isPickerVisible, setIsPickerVisible] = useState(false);
2930
const currentTime = value ? DateUtils.extractTime12Hour(value) : undefined;
@@ -47,6 +48,7 @@ function TimeModalPicker({value, errorText, label, onInputChange = () => {}}: Ti
4748
onPress={() => setIsPickerVisible(true)}
4849
brickRoadIndicator={errorText ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
4950
errorText={errorText}
51+
ref={ref}
5052
/>
5153
<Modal
5254
type={CONST.MODAL.MODAL_TYPE.RIGHT_DOCKED}
@@ -81,4 +83,4 @@ function TimeModalPicker({value, errorText, label, onInputChange = () => {}}: Ti
8183
}
8284

8385
TimeModalPicker.displayName = 'TimeModalPicker';
84-
export default TimeModalPicker;
86+
export default forwardRef(TimeModalPicker);

0 commit comments

Comments
 (0)