Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date input improvements #7639

Merged
merged 4 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
16 changes: 6 additions & 10 deletions src/components/dialogs/BirthDateSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import {
usePreferencesSetBirthDateMutation,
} from '#/state/queries/preferences'
import {ErrorMessage} from '#/view/com/util/error/ErrorMessage'
import {DateInput} from '#/view/com/util/forms/DateInput'
import {atoms as a, useTheme} from '#/alf'
import * as Dialog from '#/components/Dialog'
import {DateField} from '#/components/forms/DateField'
import {Loader} from '#/components/Loader'
import {Text} from '#/components/Typography'
import {Button, ButtonIcon, ButtonText} from '../Button'
import {Text} from '../Typography'

export function BirthDateSettingsDialog({
control,
Expand Down Expand Up @@ -95,17 +95,13 @@ function BirthdayInner({
return (
<View style={a.gap_lg} testID="birthDateSettingsDialog">
<View style={isIOS && [a.w_full, a.align_center]}>
<DateInput
handleAsUTC
<DateField
testID="birthdayInput"
value={date}
onChange={setDate}
buttonType="default-light"
buttonStyle={[a.rounded_sm]}
buttonLabelType="lg"
accessibilityLabel={_(msg`Birthday`)}
onChangeDate={newDate => setDate(new Date(newDate))}
label={_(msg`Birthday`)}
accessibilityHint={_(msg`Enter your birth date`)}
accessibilityLabelledBy="birthDate"
maximumDate={new Date()}
/>
</View>

Expand Down
4 changes: 4 additions & 0 deletions src/components/forms/DateField/index.android.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function DateField({
isInvalid,
testID,
accessibilityHint,
maximumDate,
}: DateFieldProps) {
const t = useTheme()
const [open, setOpen] = React.useState(false)
Expand Down Expand Up @@ -67,6 +68,9 @@ export function DateField({
aria-label={label}
accessibilityLabel={label}
accessibilityHint={accessibilityHint}
maximumDate={
maximumDate ? new Date(toSimpleDateString(maximumDate)) : undefined
}
/>
)}
</>
Expand Down
2 changes: 1 addition & 1 deletion src/components/forms/DateField/index.shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function DateFieldButton({
accessibilityHint,
}: {
label: string
value: string
value: string | Date
onPress: () => void
isInvalid?: boolean
accessibilityHint?: string
Expand Down
17 changes: 13 additions & 4 deletions src/components/forms/DateField/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export function DateField({
label,
isInvalid,
accessibilityHint,
maximumDate,
}: DateFieldProps) {
const {_} = useLingui()
const t = useTheme()
Expand Down Expand Up @@ -56,21 +57,29 @@ export function DateField({
isInvalid={isInvalid}
accessibilityHint={accessibilityHint}
/>
<Dialog.Outer control={control} testID={testID}>
<Dialog.Outer
control={control}
testID={testID}
nativeOptions={{preventExpansion: true}}>
<Dialog.Handle />
<Dialog.Inner label={label}>
<Dialog.ScrollableInner label={label}>
<View style={a.gap_lg}>
<View style={[a.relative, a.w_full, a.align_center]}>
<DatePicker
timeZoneOffsetInMinutes={0}
theme={t.name === 'light' ? 'light' : 'dark'}
date={new Date(value)}
date={new Date(toSimpleDateString(value))}
onDateChange={onChangeInternal}
mode="date"
testID={`${testID}-datepicker`}
aria-label={label}
accessibilityLabel={label}
accessibilityHint={accessibilityHint}
maximumDate={
maximumDate
? new Date(toSimpleDateString(maximumDate))
: undefined
}
/>
</View>
<Button
Expand All @@ -84,7 +93,7 @@ export function DateField({
</ButtonText>
</Button>
</View>
</Dialog.Inner>
</Dialog.ScrollableInner>
</Dialog.Outer>
</>
)
Expand Down
7 changes: 5 additions & 2 deletions src/components/forms/DateField/index.web.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import {StyleSheet, TextInput, TextInputProps} from 'react-native'
// @ts-ignore
// @ts-expect-error untyped
import {unstable_createElement} from 'react-native-web'

import {DateFieldProps} from '#/components/forms/DateField/types'
Expand Down Expand Up @@ -39,6 +39,7 @@ export function DateField({
isInvalid,
testID,
accessibilityHint,
maximumDate,
}: DateFieldProps) {
const handleOnChange = React.useCallback(
(e: any) => {
Expand All @@ -56,12 +57,14 @@ export function DateField({
<TextField.Root isInvalid={isInvalid}>
<TextField.Icon icon={CalendarDays} />
<Input
value={value}
value={toSimpleDateString(value)}
label={label}
onChange={handleOnChange}
onChangeText={() => {}}
testID={testID}
accessibilityHint={accessibilityHint}
// @ts-expect-error not typed as <input type="date"> even though it is one
max={maximumDate ? toSimpleDateString(maximumDate) : undefined}
/>
</TextField.Root>
)
Expand Down
3 changes: 2 additions & 1 deletion src/components/forms/DateField/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export type DateFieldProps = {
value: string
value: string | Date
onChangeDate: (date: string) => void
label: string
isInvalid?: boolean
testID?: string
accessibilityHint?: string
maximumDate?: string | Date
}
3 changes: 2 additions & 1 deletion src/screens/Signup/StepInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export function StepInfo({
</DateField.LabelText>
<DateField.DateField
testID="date"
value={DateField.utils.toSimpleDateString(state.dateOfBirth)}
value={state.dateOfBirth}
onChangeDate={date => {
dispatch({
type: 'setDateOfBirth',
Expand All @@ -215,6 +215,7 @@ export function StepInfo({
}}
label={_(msg`Date of birth`)}
accessibilityHint={_(msg`Select your date of birth`)}
maximumDate={new Date()}
/>
</View>
<Policies
Expand Down
105 changes: 0 additions & 105 deletions src/view/com/util/forms/DateInput.tsx

This file was deleted.

76 changes: 0 additions & 76 deletions src/view/com/util/forms/DateInput.web.tsx

This file was deleted.

Loading