Skip to content

Commit 4876d0e

Browse files
Merge pull request #256 from web-ridge/disable-datepickermodal-field
Disable datepickermodal field
2 parents 01af029 + a0246e8 commit 4876d0e

11 files changed

+48
-1
lines changed

docusaurus/docs/date-picker/input-date-picker.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,8 @@ The start year when the component is rendered. Defaults to `1800`.
9999
`Type: number | undefined`
100100
The end year when the component is rendered. Defaults to `2200`.
101101

102+
**inputEnabled**
103+
`Type: boolean | undefined`
104+
Flag indicating if the component should be enabled or not. Behavior similarly to `disabled`. Defaults to `true`.
105+
102106
* Other [react-native TextInput props](https://reactnative.dev/docs/textinput#props).*

docusaurus/docs/date-picker/range-date-picker.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,7 @@ The edit icon used to toggle between calendar and input. Defaults to `pencil`. Y
145145
**calendarIcon**
146146
`Type: string | undefined`
147147
The edit icon used to toggle between input and calendar. Defaults to `calendar`. You can pass the name of an icon from [MaterialCommunityIcons](https://materialdesignicons.com/).
148+
149+
**inputEnabled**
150+
`Type: boolean | undefined`
151+
Flag indicating if the component should be enabled or not. Defaults to `true`.

docusaurus/docs/date-picker/single-date-picker.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,7 @@ The edit icon used to toggle between calendar and input. Defaults to `pencil`. Y
132132
**calendarIcon**
133133
`Type: string | undefined`
134134
The edit icon used to toggle between input and calendar. Defaults to `calendar`. You can pass the name of an icon from [MaterialCommunityIcons](https://materialdesignicons.com/).
135+
136+
**inputEnabled**
137+
`Type: boolean | undefined`
138+
Flag indicating if the component should be enabled or not. Defaults to `true`.

src/Date/CalendarEdit.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function CalendarEdit({
2121
onChange,
2222
validRange,
2323
locale,
24+
inputEnabled,
2425
}: {
2526
mode: ModeType
2627
label?: string
@@ -31,6 +32,7 @@ function CalendarEdit({
3132
onChange: (s: LocalState) => any
3233
validRange: ValidRangeType | undefined
3334
locale: string
35+
inputEnabled?: boolean
3436
}) {
3537
const dateInput = React.useRef<TextInputNative | null>(null)
3638
const startInput = React.useRef<TextInputNative | null>(null)
@@ -88,6 +90,7 @@ function CalendarEdit({
8890
locale={locale}
8991
withModal={false}
9092
autoComplete={'off'}
93+
inputEnabled={inputEnabled}
9194
/>
9295
) : null}
9396
{mode === 'range' ? (
@@ -104,6 +107,7 @@ function CalendarEdit({
104107
locale={locale}
105108
withModal={false}
106109
autoComplete={'off'}
110+
inputEnabled={inputEnabled}
107111
/>
108112
<View style={styles.separator} />
109113
<DatePickerInputWithoutModal
@@ -117,6 +121,7 @@ function CalendarEdit({
117121
locale={locale}
118122
withModal={false}
119123
autoComplete="off"
124+
inputEnabled={inputEnabled}
120125
/>
121126
</View>
122127
) : null}

src/Date/DatePickerInput.shared.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type DatePickerInputProps = {
2020
startYear?: number
2121
endYear?: number
2222
onChangeText?: (text: string | undefined) => void
23+
inputEnabled?: boolean
2324
} & Omit<
2425
React.ComponentProps<typeof TextInput>,
2526
'value' | 'onChange' | 'onChangeText'

src/Date/DatePickerInput.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function DatePickerInput(
5454
uppercase,
5555
startYear,
5656
endYear,
57+
inputEnabled,
5758
}) =>
5859
withModal ? (
5960
<DatePickerModal
@@ -70,6 +71,7 @@ function DatePickerInput(
7071
uppercase={uppercase ?? true}
7172
startYear={startYear ?? 1800}
7273
endYear={endYear ?? 2200}
74+
inputEnabled={inputEnabled}
7375
/>
7476
) : null
7577
}

src/Date/DatePickerInputWithoutModal.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function DatePickerInputWithoutModal(
2727
startYear,
2828
endYear,
2929
onChangeText,
30+
inputEnabled,
3031
...rest
3132
}: DatePickerInputProps & {
3233
modal?: (params: {
@@ -39,6 +40,7 @@ function DatePickerInputWithoutModal(
3940
uppercase: DatePickerInputProps['uppercase']
4041
startYear: DatePickerInputProps['startYear']
4142
endYear: DatePickerInputProps['endYear']
43+
inputEnabled: DatePickerInputProps['inputEnabled']
4244
}) => any
4345
inputButtons?: any
4446
},
@@ -59,6 +61,16 @@ function DatePickerInputWithoutModal(
5961
onValidationError,
6062
})
6163

64+
let disabled
65+
66+
if (inputEnabled !== undefined) {
67+
disabled = !inputEnabled
68+
}
69+
70+
if (rest.disabled) {
71+
disabled = rest.disabled
72+
}
73+
6274
return (
6375
<>
6476
<View style={styles.root}>
@@ -75,6 +87,7 @@ function DatePickerInputWithoutModal(
7587
value={formattedValue}
7688
keyboardType={rest.keyboardType ?? 'number-pad'}
7789
mask={inputFormat}
90+
disabled={disabled}
7891
onChangeText={onDateInputChangeText}
7992
onChange={(e) => onChangeText && onChangeText(e.nativeEvent.text)}
8093
keyboardAppearance={theme.dark ? 'dark' : 'default'}
@@ -99,6 +112,7 @@ function DatePickerInputWithoutModal(
99112
uppercase,
100113
startYear,
101114
endYear,
115+
inputEnabled,
102116
})}
103117
</>
104118
)

src/Date/DatePickerModal.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ interface DatePickerModalProps {
2222
animationType?: 'slide' | 'fade' | 'none'
2323
disableStatusBar?: boolean
2424
disableStatusBarPadding?: boolean
25+
inputEnabled?: boolean
2526
}
2627

2728
export interface DatePickerModalSingleProps
@@ -49,6 +50,7 @@ export function DatePickerModal(
4950
animationType,
5051
disableStatusBar,
5152
disableStatusBarPadding,
53+
inputEnabled,
5254
...rest
5355
} = props
5456
const animationTypeCalculated =
@@ -112,6 +114,7 @@ export function DatePickerModal(
112114
)}
113115
<DatePickerModalContent
114116
{...rest}
117+
inputEnabled={inputEnabled}
115118
disableSafeTop={disableStatusBar}
116119
/>
117120
</View>

src/Date/DatePickerModalContent.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ interface DatePickerModalContentBaseProps {
3232
disableSafeTop?: boolean
3333
saveLabelDisabled?: boolean
3434
uppercase?: boolean
35+
inputEnabled?: boolean
3536
}
3637

3738
export interface DatePickerModalContentRangeProps
@@ -195,6 +196,7 @@ export function DatePickerModalContent(
195196
onChange={onInnerChange}
196197
validRange={validRange}
197198
locale={locale}
199+
inputEnabled={props.inputEnabled}
198200
/>
199201
}
200202
/>

src/Date/DatePickerModalContentHeader.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface HeaderContentProps extends HeaderPickProps {
2727
collapsed: boolean
2828
onToggle: () => any
2929
locale: string | undefined
30+
inputDate?: boolean
3031
}
3132

3233
function getLabel(
@@ -60,13 +61,18 @@ export default function DatePickerModalContentHeader(
6061
uppercase,
6162
editIcon,
6263
calendarIcon,
64+
inputDate,
6365
} = props
6466
const theme = useTheme()
6567
const label = getLabel(props.locale, props.mode, props.label)
6668

6769
const color = useHeaderTextColor()
6870
const supportingTextColor = theme.isV3 ? theme.colors.onSurfaceVariant : color
69-
const allowEditing = mode !== 'multiple'
71+
let allowEditing = mode !== 'multiple'
72+
73+
if (inputDate !== undefined) {
74+
allowEditing = inputDate
75+
}
7076

7177
let textFont = theme?.isV3
7278
? theme.fonts.labelMedium

0 commit comments

Comments
 (0)