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

feat: Add tabIndex prop to View component #34486

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions Libraries/Components/View/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@ export type Props = ViewProps;
const View: React.AbstractComponent<
ViewProps,
React.ElementRef<typeof ViewNativeComponent>,
> = React.forwardRef((props: ViewProps, forwardedRef) => {
return (
<TextAncestor.Provider value={false}>
<ViewNativeComponent {...props} ref={forwardedRef} />
</TextAncestor.Provider>
);
});
> = React.forwardRef(
({tabIndex, focusable, ...otherProps}: ViewProps, forwardedRef) => {
return (
<TextAncestor.Provider value={false}>
<ViewNativeComponent
focusable={tabIndex !== undefined ? !tabIndex : focusable}
{...otherProps}
ref={forwardedRef}
/>
</TextAncestor.Provider>
);
},
);

View.displayName = 'View';

Expand Down
13 changes: 13 additions & 0 deletions Libraries/Components/View/ViewPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,19 @@ type AndroidViewProps = $ReadOnly<{|
*/
focusable?: boolean,

/**
* Indicates whether this `View` should be focusable with a non-touch input device, eg. receive focus with a hardware keyboard.
* See https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex
* for more details.
*
* Supports the following values:
* - 0 (View is focusable)
* - -1 (View is not focusable)
*
* @platform android
*/
tabIndex?: 0 | -1,

/**
* The action to perform when this `View` is clicked on by a non-touch click, eg. enter key on a hardware keyboard.
*
Expand Down