Skip to content

Commit 8eb6b88

Browse files
committed
Add more props to date picker input.
1 parent f75b001 commit 8eb6b88

File tree

9 files changed

+79
-9
lines changed

9 files changed

+79
-9
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ The value used to populate the component.
5353

5454
**onChange**
5555
`Type: Function`
56-
Event handler when the component changes.
56+
Callback event when the component date mask length matches the text input length.
57+
58+
**onChangeText**
59+
`Type: Function`
60+
Callback event when the component text input changes.
5761

5862
**inputMode (Required)**
5963
`Type: String`
@@ -79,4 +83,20 @@ Flag indicating if the the component should hide error styles along with the `he
7983
`Type: Function | undefined`
8084
Callback used to return any error messages from the components validation.
8185

86+
**saveLabelDisabled**
87+
`Type: boolean | undefined`
88+
Flag indicating if the save label should be disabled and unable to receive events. Defaults to `false`.
89+
90+
**uppercase**
91+
`Type: boolean | undefined`
92+
Flag indicating if the text in the component should be uppercase. Defaults to `true`.
93+
94+
**startYear**
95+
`Type: number | undefined`
96+
The start year when the component is rendered. Defaults to `1800`.
97+
98+
**endYear**
99+
`Type: number | undefined`
100+
The end year when the component is rendered. Defaults to `2200`.
101+
82102
* Other [react-native TextInput props](https://reactnative.dev/docs/textinput#props).*

src/Date/DatePickerInput.shared.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export type DatePickerInputProps = {
1515
onValidationError?: ((error: string | null) => void) | undefined
1616
calendarIcon?: string
1717
saveLabel?: string
18+
saveLabelDisabled?: boolean
19+
uppercase?: boolean
20+
startYear?: number
21+
endYear?: number
22+
onChangeText?: (text: string | undefined) => void
1823
} & Omit<
1924
React.ComponentProps<typeof TextInput>,
2025
'value' | 'onChange' | 'onChangeText'

src/Date/DatePickerInput.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,18 @@ function DatePickerInput(
4242
/>
4343
) : null
4444
}
45-
modal={({ value, locale, inputMode, validRange, saveLabel }) =>
45+
// eslint-disable-next-line react/no-unstable-nested-components
46+
modal={({
47+
value,
48+
locale,
49+
inputMode,
50+
validRange,
51+
saveLabel,
52+
saveLabelDisabled,
53+
uppercase,
54+
startYear,
55+
endYear,
56+
}) =>
4657
withModal ? (
4758
<DatePickerModal
4859
date={value}
@@ -54,6 +65,10 @@ function DatePickerInput(
5465
dateMode={inputMode}
5566
validRange={validRange}
5667
saveLabel={saveLabel}
68+
saveLabelDisabled={saveLabelDisabled || false}
69+
uppercase={uppercase || true}
70+
startYear={startYear || 1800}
71+
endYear={endYear || 2200}
5772
/>
5873
) : null
5974
}

src/Date/DatePickerInputWithoutModal.tsx

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ function DatePickerInputWithoutModal(
2222
modal,
2323
inputButtons,
2424
saveLabel,
25+
saveLabelDisabled,
26+
uppercase,
27+
startYear,
28+
endYear,
29+
onChangeText,
2530
...rest
2631
}: DatePickerInputProps & {
2732
modal?: (params: {
@@ -30,13 +35,22 @@ function DatePickerInputWithoutModal(
3035
inputMode: DatePickerInputProps['inputMode']
3136
validRange: DatePickerInputProps['validRange']
3237
saveLabel: DatePickerInputProps['saveLabel']
38+
saveLabelDisabled: DatePickerInputProps['saveLabelDisabled']
39+
uppercase: DatePickerInputProps['uppercase']
40+
startYear: DatePickerInputProps['startYear']
41+
endYear: DatePickerInputProps['endYear']
3342
}) => any
3443
inputButtons?: any
3544
},
3645
ref: any
3746
) {
3847
const theme = useTheme()
39-
const { formattedValue, inputFormat, onChangeText, error } = useDateInput({
48+
const {
49+
formattedValue,
50+
inputFormat,
51+
onChangeText: onDateInputChangeText,
52+
error,
53+
} = useDateInput({
4054
locale,
4155
value,
4256
validRange,
@@ -61,20 +75,31 @@ function DatePickerInputWithoutModal(
6175
value={formattedValue}
6276
keyboardType={'number-pad'}
6377
mask={inputFormat}
64-
onChangeText={onChangeText}
78+
onChangeText={onDateInputChangeText}
79+
onChange={(e) => onChangeText && onChangeText(e.nativeEvent.text)}
6580
keyboardAppearance={theme.dark ? 'dark' : 'default'}
6681
error={(!!error && !hideValidationErrors) || !!hasError}
6782
style={[styles.input, style]}
6883
/>
6984
{inputButtons}
7085
</View>
7186
{error && !hideValidationErrors ? (
72-
<HelperText style={styles.helperText} type="error" visible={!!error}>
87+
<HelperText type="error" visible={!!error}>
7388
{error}
7489
</HelperText>
7590
) : null}
7691
</View>
77-
{modal?.({ value, locale, inputMode, validRange, saveLabel })}
92+
{modal?.({
93+
value,
94+
locale,
95+
inputMode,
96+
validRange,
97+
saveLabel,
98+
saveLabelDisabled,
99+
uppercase,
100+
startYear,
101+
endYear,
102+
})}
78103
</>
79104
)
80105
}
@@ -107,8 +132,5 @@ const styles = StyleSheet.create({
107132
input: {
108133
flexGrow: 1,
109134
},
110-
helperText: {
111-
// flex: 1,
112-
},
113135
})
114136
export default React.forwardRef(DatePickerInputWithoutModal)

src/TextInputMask.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ function enhanceTextWithMask(
6969
function TextInputWithMask(
7070
{
7171
onChangeText,
72+
onChange,
7273
value,
7374
mask,
7475
...rest
@@ -101,6 +102,9 @@ function TextInputWithMask(
101102
{...rest}
102103
value={controlledValue}
103104
onChangeText={onInnerChange}
105+
onChange={(e) => {
106+
onChange && onChange(e)
107+
}}
104108
onBlur={onInnerBlur}
105109
/>
106110
)

src/__tests__/Date/__snapshots__/AnimatedCrossView.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3593,6 +3593,7 @@ exports[`renders collapsed AnimatedCrossView 1`] = `
35933593
maxFontSizeMultiplier={1.5}
35943594
multiline={false}
35953595
onBlur={[Function]}
3596+
onChange={[Function]}
35963597
onChangeText={[Function]}
35973598
onFocus={[Function]}
35983599
onSubmitEditing={[Function]}

src/__tests__/Date/__snapshots__/CalendarEdit.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ exports[`renders CalendarEdit 1`] = `
176176
maxFontSizeMultiplier={1.5}
177177
multiline={false}
178178
onBlur={[Function]}
179+
onChange={[Function]}
179180
onChangeText={[Function]}
180181
onFocus={[Function]}
181182
onSubmitEditing={[Function]}

src/__tests__/Date/__snapshots__/DatePickerInput.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ exports[`renders DatePickerInput 1`] = `
170170
maxFontSizeMultiplier={1.5}
171171
multiline={false}
172172
onBlur={[Function]}
173+
onChange={[Function]}
173174
onChangeText={[Function]}
174175
onFocus={[Function]}
175176
placeholder=" "

src/__tests__/Date/__snapshots__/DatePickerInputWithoutModal.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ exports[`renders DatePickerInput 1`] = `
169169
maxFontSizeMultiplier={1.5}
170170
multiline={false}
171171
onBlur={[Function]}
172+
onChange={[Function]}
172173
onChangeText={[Function]}
173174
onFocus={[Function]}
174175
placeholder=" "

0 commit comments

Comments
 (0)