Skip to content

Conversation

@acoates-ms
Copy link
Contributor

@acoates-ms acoates-ms commented Nov 6, 2025

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Why

Resolves #14497 #14496

Microsoft Reviewers: Open in CodeFlow

@acoates-ms acoates-ms requested a review from a team as a code owner November 6, 2025 21:34
}
onPress?.(args);
},
[focusOnPress, onPress, focusable],
Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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..

Comment on lines +321 to +328
const onPressWithFocus = React.useCallback(
(args: GestureResponderEvent) => {
if (focusable !== false && focusOnPress !== false) {
viewRef?.current?.focus();
}
onPress?.(args);
},
[focusOnPress, onPress, focusable],
Copy link
Contributor

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.

Copy link
Contributor

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..

@acoates-ms acoates-ms merged commit 01364aa into microsoft:main Nov 10, 2025
57 checks passed
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.

Keyboard focus remains in same location after mouse click elsewhere in app

3 participants