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

Refactoring date components to use useFocusWithin #3694

Merged
merged 8 commits into from
Oct 29, 2022
Merged

Conversation

ktabors
Copy link
Member

@ktabors ktabors commented Oct 28, 2022

This is followup for #3605

Refactoring date components to use useFocusWithin and remove api changes from react-stately

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 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

@ktabors ktabors marked this pull request as ready for review October 28, 2022 19:04
@adobe-bot
Copy link

@adobe adobe deleted a comment from adobe-bot Oct 28, 2022
@@ -64,8 +64,23 @@ export function useDateField<T extends DateValue>(props: AriaDateFieldProps<T>,
});

let {focusWithinProps} = useFocusWithin({
onBlurWithin() {
...props,
onBlurWithin: (e: ReactFocusEvent) => {
Copy link
Member

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

@adobe-bot
Copy link

@adobe-bot
Copy link

@adobe adobe deleted a comment from adobe-bot Oct 28, 2022
snowystinger
snowystinger previously approved these changes Oct 28, 2022
if (props.onFocus) {
props.onFocus(e);
}
},
Copy link
Member

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);
}
}
Copy link
Member

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,
  // ...
});

@adobe-bot
Copy link

@adobe-bot
Copy link

API Changes

@react-stately/datepicker

DateFieldState

 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:

  • useDateSegment
  • useDateField
  • useTimeField
  • useDateFieldState
  • useTimeFieldState

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:

  • useDatePicker
  • useDatePickerState

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:

  • useDateRangePicker
  • useDateRangePickerState

@adobe adobe deleted a comment from adobe-bot Oct 28, 2022
@adobe-bot
Copy link

@adobe-bot
Copy link

API Changes

@react-stately/datepicker

DateFieldState

 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:

  • useDateSegment
  • useDateField
  • useTimeField
  • useDateFieldState
  • useTimeFieldState

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:

  • useDatePicker
  • useDatePickerState

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:

  • useDateRangePicker
  • useDateRangePickerState

@devongovett devongovett merged commit 286dbcd into main Oct 29, 2022
@devongovett devongovett deleted the date_focusWithin branch October 29, 2022 00:35
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.

5 participants