-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Refactoring date components to use useFocusWithin #3694
Conversation
Build successful! 🎉 |
@@ -64,8 +64,23 @@ export function useDateField<T extends DateValue>(props: AriaDateFieldProps<T>, | |||
}); | |||
|
|||
let {focusWithinProps} = useFocusWithin({ | |||
onBlurWithin() { | |||
...props, | |||
onBlurWithin: (e: ReactFocusEvent) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just FocusEvent, see useFocusWithin for types
Build successful! 🎉 |
Build successful! 🎉 |
if (props.onFocus) { | ||
props.onFocus(e); | ||
} | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably don't need these wrapper functions. You could do something like this:
onFocusWithin: props.onFocus
if (props.onFocusChange) { | ||
props.onFocusChange(value); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An easier way to do this could be
useFocusWithin({
...props,
isDisabled: state.isOpen,
onBlurWithin: props.onBlur,
// ...
});
Build successful! 🎉 |
API Changes@react-stately/datepickerDateFieldState DateFieldState {
calendar: Calendar
clearSegment: (SegmentType) => void
confirmPlaceholder: () => void
dateFormatter: DateFormatter
dateValue: Date
decrement: (SegmentType) => void
decrementPage: (SegmentType) => void
formatValue: (FieldOptions) => string
granularity: Granularity
increment: (SegmentType) => void
incrementPage: (SegmentType) => void
isDisabled: boolean
- isFocused: boolean
isReadOnly: boolean
isRequired: boolean
maxGranularity: 'year' | 'month' | Granularity
segments: Array<DateSegment>
- setFocused: (boolean) => void
setSegment: (SegmentType, number) => void
setValue: (DateValue) => void
validationState: ValidationState
value: DateValue
it changed:
DatePickerState DatePickerState {
close: () => void
dateValue: DateValue
formatValue: (string, FieldOptions) => string
granularity: Granularity
hasTime: boolean
- isFocused: boolean
isOpen: boolean
open: () => void
setDateValue: (CalendarDate) => void
- setFocused: (boolean) => void
setOpen: (boolean) => void
setTimeValue: (TimeValue) => void
setValue: (DateValue) => void
timeValue: TimeValue
validationState: ValidationState
value: DateValue
}
it changed:
DateRangePickerState DateRangePickerState {
close: () => void
dateRange: DateRange
formatValue: (string, FieldOptions) => {
start: string
end: string
}
granularity: Granularity
hasTime: boolean
- isFocused: boolean
isOpen: boolean
open: () => void
setDate: ('start' | 'end', DateValue) => void
setDateRange: (DateRange) => void
setDateTime: ('start' | 'end', DateValue) => void
- setFocused: (boolean) => void
setOpen: (boolean) => void
setTime: ('start' | 'end', TimeValue) => void
setTimeRange: (TimeRange) => void
setValue: (DateRange) => void
toggle: () => void
validationState: ValidationState
value: DateRange
}
it changed:
|
Build successful! 🎉 |
API Changes@react-stately/datepickerDateFieldState DateFieldState {
calendar: Calendar
clearSegment: (SegmentType) => void
confirmPlaceholder: () => void
dateFormatter: DateFormatter
dateValue: Date
decrement: (SegmentType) => void
decrementPage: (SegmentType) => void
formatValue: (FieldOptions) => string
granularity: Granularity
increment: (SegmentType) => void
incrementPage: (SegmentType) => void
isDisabled: boolean
- isFocused: boolean
isReadOnly: boolean
isRequired: boolean
maxGranularity: 'year' | 'month' | Granularity
segments: Array<DateSegment>
- setFocused: (boolean) => void
setSegment: (SegmentType, number) => void
setValue: (DateValue) => void
validationState: ValidationState
value: DateValue
it changed:
DatePickerState DatePickerState {
close: () => void
dateValue: DateValue
formatValue: (string, FieldOptions) => string
granularity: Granularity
hasTime: boolean
- isFocused: boolean
isOpen: boolean
open: () => void
setDateValue: (CalendarDate) => void
- setFocused: (boolean) => void
setOpen: (boolean) => void
setTimeValue: (TimeValue) => void
setValue: (DateValue) => void
timeValue: TimeValue
validationState: ValidationState
value: DateValue
}
it changed:
DateRangePickerState DateRangePickerState {
close: () => void
dateRange: DateRange
formatValue: (string, FieldOptions) => {
start: string
end: string
}
granularity: Granularity
hasTime: boolean
- isFocused: boolean
isOpen: boolean
open: () => void
setDate: ('start' | 'end', DateValue) => void
setDateRange: (DateRange) => void
setDateTime: ('start' | 'end', DateValue) => void
- setFocused: (boolean) => void
setOpen: (boolean) => void
setTime: ('start' | 'end', TimeValue) => void
setTimeRange: (TimeRange) => void
setValue: (DateRange) => void
toggle: () => void
validationState: ValidationState
value: DateRange
}
it changed:
|
This is followup for #3605
Refactoring date components to use useFocusWithin and remove api changes from react-stately
✅ Pull Request Checklist:
📝 Test Instructions:
goto the "all the events" story in DateField, DatePicker, DateRangePicker, and TimeField, confirm the events exist and are called correctly. see issues #3272 #3346 and PR #3605
🧢 Your Project:
RSP