Skip to content

Conversation

devongovett
Copy link
Member

Closes #4668

This adds a shouldForceLeadingZeros prop to DatePicker, DateRangePicker, DateField, and TimeField which forces leading zeros to always show in the month, day, and hour fields, regardless of the locale preference. This was also requested in #4247. We would discourage overriding this across all locales, but it can be useful to configure in some scenarios.

@devongovett devongovett changed the title Add shouldForceLeadingZeros leading zeros prop to DatePicker Add shouldForceLeadingZeros prop to DatePicker Jun 16, 2023
@rspbot
Copy link

rspbot commented Jun 16, 2023

@rspbot
Copy link

rspbot commented Jun 16, 2023

## API Changes

unknown top level export { type: 'identifier', name: 'Column' }
unknown top level export { type: 'identifier', name: 'Column' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }

@react-aria/datepicker

AriaDateFieldProps

 AriaDateFieldProps<T extends DateValue> {
   granularity?: Granularity
   hideTimeZone?: boolean = false
   hourCycle?: number | number
   isDateUnavailable?: (DateValue) => boolean
   maxValue?: DateValue
   minValue?: DateValue
   placeholderValue?: DateValue
+  shouldForceLeadingZeros?: boolean
 }

AriaDatePickerProps

 AriaDatePickerProps<T extends DateValue> {
   granularity?: Granularity
   hideTimeZone?: boolean = false
   hourCycle?: number | number
   isDateUnavailable?: (DateValue) => boolean
   maxValue?: DateValue
   minValue?: DateValue
   pageBehavior?: PageBehavior = visible
   placeholderValue?: DateValue
+  shouldForceLeadingZeros?: boolean
 }

AriaDateRangePickerProps

 AriaDateRangePickerProps<T extends DateValue> {
   allowsNonContiguousRanges?: boolean
   granularity?: Granularity
   hideTimeZone?: boolean = false
   hourCycle?: number | number
   isDateUnavailable?: (DateValue) => boolean
   maxValue?: DateValue
   minValue?: DateValue
   pageBehavior?: PageBehavior = visible
   placeholderValue?: DateValue
+  shouldForceLeadingZeros?: boolean
 }

AriaTimeFieldProps

 AriaTimeFieldProps<T extends TimeValue> {
   granularity?: 'hour' | 'minute' | 'second' = 'minute'
   hideTimeZone?: boolean
   hourCycle?: number | number
   maxValue?: TimeValue
   minValue?: TimeValue
   placeholderValue?: TimeValue
+  shouldForceLeadingZeros?: boolean
 }

@react-spectrum/datepicker

DatePicker

 SpectrumDateFieldProps<T extends DateValue> {
   granularity?: Granularity
   hideTimeZone?: boolean = false
   hourCycle?: number | number
   isDateUnavailable?: (DateValue) => boolean
   isQuiet?: boolean = false
   maxValue?: DateValue
   minValue?: DateValue
   placeholderValue?: DateValue
+  shouldForceLeadingZeros?: boolean
   showFormatHelpText?: boolean = false
 }

DateRangePicker

 SpectrumDatePickerProps<T extends DateValue> {
   granularity?: Granularity
   hideTimeZone?: boolean = false
   hourCycle?: number | number
   isDateUnavailable?: (DateValue) => boolean
   isQuiet?: boolean = false
   maxValue?: DateValue
   maxVisibleMonths?: number = 1
   minValue?: DateValue
   pageBehavior?: PageBehavior = visible
   placeholderValue?: DateValue
   shouldFlip?: boolean = true
+  shouldForceLeadingZeros?: boolean
   showFormatHelpText?: boolean = false
 }

TimeField

 SpectrumDateRangePickerProps<T extends DateValue> {
   allowsNonContiguousRanges?: boolean
   granularity?: Granularity
   hideTimeZone?: boolean = false
   hourCycle?: number | number
   isDateUnavailable?: (DateValue) => boolean
   isQuiet?: boolean = false
   maxValue?: DateValue
   maxVisibleMonths?: number = 1
   minValue?: DateValue
   pageBehavior?: PageBehavior = visible
   placeholderValue?: DateValue
   shouldFlip?: boolean = true
+  shouldForceLeadingZeros?: boolean
   showFormatHelpText?: boolean = false
 }

DateField

 SpectrumTimeFieldProps<T extends TimeValue> {
   granularity?: 'hour' | 'minute' | 'second' = 'minute'
   hideTimeZone?: boolean
   hourCycle?: number | number
   isQuiet?: boolean = false
   maxValue?: TimeValue
   minValue?: TimeValue
   placeholderValue?: TimeValue
+  shouldForceLeadingZeros?: boolean
 }

Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm, tested on iOS

@@ -78,6 +78,12 @@ HourCycle24.story = {
name: 'hourCycle: 24'
};

export const ForceLeadingZeros = () => render({defaultValue: {start: new CalendarDate(2020, 2, 3), end: new CalendarDate(2020, 5, 4)}, shouldForceLeadingZeros: true});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a new story when it's already in the controls?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DateRangePicker and TimeField don't have controls for some reason. I added to the controls for DatePicker and DateField. Seems like we need to convert the others over at some point.

@devongovett devongovett merged commit a4f8ec3 into main Jun 21, 2023
@devongovett devongovett deleted the force-leading-zeros branch June 21, 2023 00:27
@dannify dannify removed the release label Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Leading zero is truncated for day in New Zealand region where it shouldnt be.
5 participants