-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Focusable Pressables should take focus when they are clicked on
#15327
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
Conversation
| } | ||
| onPress?.(args); | ||
| }, | ||
| [focusOnPress, onPress, focusable], |
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.
Do you need to add viewRef here? I can't remember
| // [Windows | ||
| /** | ||
| * When the pressable is pressed it will take focus | ||
| * Default value: true |
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.
if the default is true should this prop become disableFocusOnPress?
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.
I prefer to avoid negative props. - But I see an argument for avoiding default true props too.
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.
would also prefer not having bool in the name, I don't like that we have enableFocusRing instead something like focusRingVisible. I also think it wouldn't be true by default except on windows..
| const onPressWithFocus = React.useCallback( | ||
| (args: GestureResponderEvent) => { | ||
| if (focusable !== false && focusOnPress !== false) { | ||
| viewRef?.current?.focus(); | ||
| } | ||
| onPress?.(args); | ||
| }, | ||
| [focusOnPress, onPress, focusable], |
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.
I think it would be better to this in Pressability, where we already override onPress once.
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.
ah.. but we don't have the ref there..
Description
Focusable
Pressables should take focus when they are clicked on.I added a new property to Pressable
focusOnPress, which can be set to false to prevent this behavior.Type of Change
Why
Resolves #14497 #14496
Microsoft Reviewers: Open in CodeFlow