Skip to content

Normalize press handling for Checkbox, Radio, and Switch labels - #5525

Merged
devongovett merged 7 commits into
mainfrom
label-press-ios
Dec 7, 2023
Merged

devongovett merged 7 commits into
mainfrom
label-press-ios

Conversation

@devongovett

@devongovett devongovett commented Dec 5, 2023 •

Copy link
Copy Markdown
Member

Fixes #3675

Built this animation for the new landing page to show how our press interactions work, but then realized that it didn't work on iOS. Seems like Safari doesn't trigger a click event if you drag off and then back onto the label like it works on desktop.

Switch.Animation2.mov

This adds labelProps as a return value to useCheckbox, useRadio, and useSwitch, which uses usePress to toggle the value and prevents the native onClick. This has the side benefit of allowing us to remove the press handling from RAC, which we use for the visible press state. This is not a breaking change: if labelProps is unused, it will have no effect.

@rspbot

rspbot commented Dec 5, 2023

Copy link
Copy Markdown

snowystinger
snowystinger previously approved these changes Dec 5, 2023

@snowystinger snowystinger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, also, i think you might've solved #3675

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

shouldn't we also make the Spectrum components use the labelProps returned by the hooks as well? Probably should update the hooks docs as well to do the same, happy to help with these if you'd like

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yeah but I'm on a tight schedule and not sure I'll have time. mainly wanted this because it was very visible for this demo. seems fine to add to the backlog for RSP if we don't get to it, but if you have time feel free!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

makes sense, I'll see about getting something out for it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah I see, it isn't as trivial as using the labelProps since RSP/hooks example have an actual pressable input (and thus block the press + release on label) element vs RAC which hides it and relies on the label for pointer interactions. I'll file something

@rspbot

rspbot commented Dec 5, 2023

Copy link
Copy Markdown

LFDanLu
LFDanLu previously approved these changes Dec 6, 2023
@rspbot

rspbot commented Dec 6, 2023

Copy link
Copy Markdown

@rspbot

rspbot commented Dec 7, 2023

Copy link
Copy Markdown

@devongovett
devongovett dismissed stale reviews from LFDanLu and snowystinger via 243a803 December 7, 2023 00:54
@rspbot

rspbot commented Dec 7, 2023

Copy link
Copy Markdown

@rspbot

rspbot commented Dec 7, 2023

Copy link
Copy Markdown
## API Changes

unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any', access: 'private' }
unknown top level export { type: 'any', access: 'private' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
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' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }

@react-aria/checkbox

CheckboxAria

 CheckboxAria {
   inputProps: InputHTMLAttributes<HTMLInputElement>
   isDisabled: boolean
   isPressed: boolean
   isReadOnly: boolean
   isSelected: boolean
+  labelProps: LabelHTMLAttributes<HTMLLabelElement>
 }

it changed:

  • useCheckbox

@react-aria/radio

RadioAria

 RadioAria {
   inputProps: InputHTMLAttributes<HTMLInputElement>
   isDisabled: boolean
   isPressed: boolean
   isSelected: boolean
+  labelProps: LabelHTMLAttributes<HTMLLabelElement>
 }

it changed:

  • useRadio

@react-aria/switch

SwitchAria

 SwitchAria {
   inputProps: InputHTMLAttributes<HTMLInputElement>
   isDisabled: boolean
   isPressed: boolean
   isReadOnly: boolean
   isSelected: boolean
+  labelProps: LabelHTMLAttributes<HTMLLabelElement>
 }

it changed:

  • useSwitch

@react-aria/toggle

ToggleAria

 ToggleAria {
   inputProps: InputHTMLAttributes<HTMLInputElement>
   isDisabled: boolean
   isInvalid: boolean
   isPressed: boolean
   isReadOnly: boolean
   isSelected: boolean
+  labelProps: LabelHTMLAttributes<HTMLLabelElement>
 }

it changed:

  • useToggle

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.

isFocusVisible is true when clicking label elements (e.g for Checkbox) inside elements with tabIndex

4 participants