Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions src/components/DatePicker/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {format, setYear} from 'date-fns';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import type {GestureResponderEvent} from 'react-native';
import {InteractionManager, View} from 'react-native';
import TextInput from '@components/TextInput';
import type {BaseTextInputRef} from '@components/TextInput/BaseTextInput/types';
Expand Down Expand Up @@ -71,15 +70,10 @@ function DatePicker({
});
}, [windowHeight]);

const handlePress = useCallback(
(event?: GestureResponderEvent | KeyboardEvent) => {
// This makes sure that cursor does not appear in the TextInput when we open the DatePicker
event?.preventDefault();
calculatePopoverPosition();
setIsModalVisible(true);
},
[calculatePopoverPosition],
);
const handlePress = useCallback(() => {
calculatePopoverPosition();
setIsModalVisible(true);
}, [calculatePopoverPosition]);

const closeDatePicker = useCallback(() => {
textInputRef.current?.blur();
Expand Down Expand Up @@ -139,7 +133,7 @@ function DatePicker({
iconContainerStyle={styles.pr0}
label={label}
accessibilityLabel={label}
role={CONST.ROLE.PRESENTATION}
role={CONST.ROLE.COMBOBOX}
value={selectedDate}
placeholder={placeholder ?? translate('common.dateFormat')}
errorText={errorText}
Expand All @@ -151,7 +145,7 @@ function DatePicker({
onClearInput={handleClear}
forwardedFSClass={forwardedFSClass}
autoComplete={autoComplete}
disableKeyboard
readOnly
/>
</View>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,16 @@ function BaseTextInput({
setIsFocused(false);
};

const isReadOnly = inputProps.readOnly ?? inputProps.disabled;

const onPress = (event?: GestureResponderEvent | KeyboardEvent) => {
if (!!inputProps.disabled || !event) {
return;
}

inputProps.onPress?.(event);

if ('isDefaultPrevented' in event && !event?.isDefaultPrevented()) {
if ('isDefaultPrevented' in event && !event?.isDefaultPrevented() && !isReadOnly) {
input.current?.focus();
}
};
Expand Down Expand Up @@ -256,7 +258,6 @@ function BaseTextInput({
}, []);

const shouldAddPaddingBottom = isMultiline || (autoGrowHeight && !isAutoGrowHeightMarkdown && textInputHeight > variables.componentSizeLarge);
const isReadOnly = inputProps.readOnly ?? inputProps.disabled;
// Disabling this line for safeness as nullish coalescing works only if the value is undefined or null, and errorText can be an empty string
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const inputHelpText = errorText || hint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,16 @@ function BaseTextInput({
setIsFocused(false);
};

const isReadOnly = inputProps.readOnly ?? inputProps.disabled;

const onPress = (event?: GestureResponderEvent | KeyboardEvent) => {
if (!!inputProps.disabled || !event) {
return;
}

inputProps.onPress?.(event);

if ('isDefaultPrevented' in event && !event?.isDefaultPrevented()) {
if ('isDefaultPrevented' in event && !event?.isDefaultPrevented() && !isReadOnly) {
input.current?.focus();
}
};
Expand Down Expand Up @@ -293,7 +295,6 @@ function BaseTextInput({

const shouldAddPaddingBottom = isMultiline || (autoGrowHeight && !isAutoGrowHeightMarkdown && textInputHeight > variables.componentSizeLarge);
const hasLabel = !!label?.length;
const isReadOnly = inputProps.readOnly ?? inputProps.disabled;
// Disabling this line for safeness as nullish coalescing works only if the value is undefined or null, and errorText can be an empty string
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const inputHelpText = errorText || hint;
Expand Down
Loading