From 621f4cf3b12979b62d2e1d49d63eaf85e0707026 Mon Sep 17 00:00:00 2001 From: Gabriel Donadel Dall'Agnol Date: Mon, 29 Aug 2022 18:54:51 -0700 Subject: [PATCH] feat: Add tabIndex prop to View component (#34486) Summary: This adds the `tabIndex` Android only prop to View as requested on https://github.com/facebook/react-native/issues/34424 mapping the existing `focusable` prop to `tabIndex` so that `tabIndex={0}` maps to `focusable={true}` and `tabIndex={-1}` represents ` focusable={false}`. ## Changelog [Android] [Added] - Add tabIndex prop to View component Pull Request resolved: https://github.com/facebook/react-native/pull/34486 Test Plan: I'm still investigating the best way to test this but we're are just mapping this to an existing prop Reviewed By: GijsWeterings Differential Revision: D38957303 Pulled By: necolas fbshipit-source-id: d00db854e11cb3457329c1547b69cff60afb34cf --- Libraries/Components/View/View.js | 20 +++++++++++++------- Libraries/Components/View/ViewPropTypes.js | 13 +++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Libraries/Components/View/View.js b/Libraries/Components/View/View.js index 0379a7ce912..7822e8184f2 100644 --- a/Libraries/Components/View/View.js +++ b/Libraries/Components/View/View.js @@ -26,13 +26,19 @@ export type Props = ViewProps; const View: React.AbstractComponent< ViewProps, React.ElementRef, -> = React.forwardRef((props: ViewProps, forwardedRef) => { - return ( - - - - ); -}); +> = React.forwardRef( + ({tabIndex, focusable, ...otherProps}: ViewProps, forwardedRef) => { + return ( + + + + ); + }, +); View.displayName = 'View'; diff --git a/Libraries/Components/View/ViewPropTypes.js b/Libraries/Components/View/ViewPropTypes.js index 24c0afcaee8..effed17622c 100644 --- a/Libraries/Components/View/ViewPropTypes.js +++ b/Libraries/Components/View/ViewPropTypes.js @@ -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. *