-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add role prop to Text component (#34976)
Summary: As pointed out by necolas on #34424 (comment) we forgot we add the `role` prop mapping to the `Text` component. This PR adds a new `role` prop to `Text`, mapping the web `role` values to the already existing `accessibilityRole` prop and moves the `roleToAccessibilityRoleMapping` to a common file that can be imported by both the `Text` and `View` components as requested on #34424. This PR also updates the RNTester AcessebilityExample to include a test using this new prop. ## Changelog [General] [Added] - Add role prop to Text component Pull Request resolved: #34976 Test Plan: 1. Open the RNTester app and navigate to the Accessibility Example page 2. Test the `role` prop through the `Text with role = heading` section Reviewed By: yungsters Differential Revision: D40596039 Pulled By: jacdebug fbshipit-source-id: f72f02e8bd32169423ea517ad18b598b52257b17
- Loading branch information
1 parent
8ad86c7
commit 20718e6
Showing
6 changed files
with
244 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict-local | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import type { | ||
AccessibilityRole, | ||
Role, | ||
} from '../Components/View/ViewAccessibility'; | ||
|
||
// Map role values to AccessibilityRole values | ||
export function getAccessibilityRoleFromRole(role: Role): ?AccessibilityRole { | ||
switch (role) { | ||
case 'alert': | ||
return 'alert'; | ||
case 'alertdialog': | ||
return undefined; | ||
case 'application': | ||
return undefined; | ||
case 'article': | ||
return undefined; | ||
case 'banner': | ||
return undefined; | ||
case 'button': | ||
return 'button'; | ||
case 'cell': | ||
return undefined; | ||
case 'checkbox': | ||
return 'checkbox'; | ||
case 'columnheader': | ||
return undefined; | ||
case 'combobox': | ||
return 'combobox'; | ||
case 'complementary': | ||
return undefined; | ||
case 'contentinfo': | ||
return undefined; | ||
case 'definition': | ||
return undefined; | ||
case 'dialog': | ||
return undefined; | ||
case 'directory': | ||
return undefined; | ||
case 'document': | ||
return undefined; | ||
case 'feed': | ||
return undefined; | ||
case 'figure': | ||
return undefined; | ||
case 'form': | ||
return undefined; | ||
case 'grid': | ||
return 'grid'; | ||
case 'group': | ||
return undefined; | ||
case 'heading': | ||
return 'header'; | ||
case 'img': | ||
return 'image'; | ||
case 'link': | ||
return 'link'; | ||
case 'list': | ||
return 'list'; | ||
case 'listitem': | ||
return undefined; | ||
case 'log': | ||
return undefined; | ||
case 'main': | ||
return undefined; | ||
case 'marquee': | ||
return undefined; | ||
case 'math': | ||
return undefined; | ||
case 'menu': | ||
return 'menu'; | ||
case 'menubar': | ||
return 'menubar'; | ||
case 'menuitem': | ||
return 'menuitem'; | ||
case 'meter': | ||
return undefined; | ||
case 'navigation': | ||
return undefined; | ||
case 'none': | ||
return 'none'; | ||
case 'note': | ||
return undefined; | ||
case 'presentation': | ||
return 'none'; | ||
case 'progressbar': | ||
return 'progressbar'; | ||
case 'radio': | ||
return 'radio'; | ||
case 'radiogroup': | ||
return 'radiogroup'; | ||
case 'region': | ||
return undefined; | ||
case 'row': | ||
return undefined; | ||
case 'rowgroup': | ||
return undefined; | ||
case 'rowheader': | ||
return undefined; | ||
case 'scrollbar': | ||
return 'scrollbar'; | ||
case 'searchbox': | ||
return 'search'; | ||
case 'separator': | ||
return undefined; | ||
case 'slider': | ||
return 'adjustable'; | ||
case 'spinbutton': | ||
return 'spinbutton'; | ||
case 'status': | ||
return undefined; | ||
case 'summary': | ||
return 'summary'; | ||
case 'switch': | ||
return 'switch'; | ||
case 'tab': | ||
return 'tab'; | ||
case 'table': | ||
return undefined; | ||
case 'tablist': | ||
return 'tablist'; | ||
case 'tabpanel': | ||
return undefined; | ||
case 'term': | ||
return undefined; | ||
case 'timer': | ||
return 'timer'; | ||
case 'toolbar': | ||
return 'toolbar'; | ||
case 'tooltip': | ||
return undefined; | ||
case 'tree': | ||
return undefined; | ||
case 'treegrid': | ||
return undefined; | ||
case 'treeitem': | ||
return undefined; | ||
} | ||
|
||
return undefined; | ||
} |
Oops, something went wrong.