Repository navigation
fix: map aria-* props in Switch, ScrollView and ActivityIndicator #59379
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /** | ||
| * 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 | ||
| */ | ||
|
|
||
| import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes'; | ||
|
|
||
| /** | ||
| * Converts the web-style accessibility props (`aria-*`, `id`, `tabIndex`) to | ||
| * the props the native side reads, the same way `View` does. For components | ||
| * that render a native component directly instead of a `View`: without it, | ||
| * the native side drops these props. | ||
| */ | ||
| export default function resolveAriaProps<T extends {...ViewProps, ...}>( | ||
| props: T, | ||
| ): T { | ||
| const { | ||
| 'aria-busy': ariaBusy, | ||
| 'aria-checked': ariaChecked, | ||
| 'aria-disabled': ariaDisabled, | ||
| 'aria-expanded': ariaExpanded, | ||
| 'aria-hidden': ariaHidden, | ||
| 'aria-label': ariaLabel, | ||
| 'aria-labelledby': ariaLabelledBy, | ||
| 'aria-live': ariaLive, | ||
| 'aria-modal': ariaModal, | ||
| 'aria-selected': ariaSelected, | ||
| 'aria-valuemax': ariaValueMax, | ||
| 'aria-valuemin': ariaValueMin, | ||
| 'aria-valuenow': ariaValueNow, | ||
| 'aria-valuetext': ariaValueText, | ||
| id, | ||
| tabIndex, | ||
| ...otherProps | ||
| } = props; | ||
|
|
||
| const resolvedProps = otherProps as {...ViewProps, ...}; | ||
|
|
||
| const parsedAriaLabelledBy = ariaLabelledBy?.split(/\s*,\s*/g); | ||
| if (parsedAriaLabelledBy !== undefined) { | ||
| resolvedProps.accessibilityLabelledBy = parsedAriaLabelledBy; | ||
| } | ||
|
|
||
| if (ariaLabel !== undefined) { | ||
| resolvedProps.accessibilityLabel = ariaLabel; | ||
| } | ||
|
|
||
| if (ariaLive !== undefined) { | ||
| resolvedProps.accessibilityLiveRegion = | ||
| ariaLive === 'off' ? 'none' : ariaLive; | ||
| } | ||
|
|
||
| if (ariaModal !== undefined) { | ||
| resolvedProps.accessibilityViewIsModal = ariaModal; | ||
| } | ||
|
|
||
| if (ariaHidden !== undefined) { | ||
| resolvedProps.accessibilityElementsHidden = ariaHidden; | ||
| if (ariaHidden === true) { | ||
| resolvedProps.importantForAccessibility = 'no-hide-descendants'; | ||
| } | ||
| } | ||
|
|
||
| if (id !== undefined) { | ||
| resolvedProps.nativeID = id; | ||
| } | ||
|
|
||
| if (tabIndex !== undefined) { | ||
| resolvedProps.focusable = !tabIndex; | ||
| } | ||
|
|
||
| if ( | ||
| ariaBusy != null || | ||
| ariaChecked != null || | ||
| ariaDisabled != null || | ||
| ariaExpanded != null || | ||
| ariaSelected != null | ||
| ) { | ||
| resolvedProps.accessibilityState = { | ||
| busy: ariaBusy ?? props.accessibilityState?.busy, | ||
| checked: ariaChecked ?? props.accessibilityState?.checked, | ||
| disabled: ariaDisabled ?? props.accessibilityState?.disabled, | ||
| expanded: ariaExpanded ?? props.accessibilityState?.expanded, | ||
| selected: ariaSelected ?? props.accessibilityState?.selected, | ||
| }; | ||
| } | ||
|
Comment on lines
+77
to
+91
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you match the logic of https://github.com/react/react-native/pull/59807/changes, and remove
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done: |
||
|
|
||
| if ( | ||
| ariaValueMax != null || | ||
| ariaValueMin != null || | ||
| ariaValueNow != null || | ||
| ariaValueText != null | ||
| ) { | ||
| resolvedProps.accessibilityValue = { | ||
| max: ariaValueMax ?? props.accessibilityValue?.max, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: read |
||
| min: ariaValueMin ?? props.accessibilityValue?.min, | ||
| now: ariaValueNow ?? props.accessibilityValue?.now, | ||
| text: ariaValueText ?? props.accessibilityValue?.text, | ||
| }; | ||
| } | ||
|
|
||
| // $FlowFixMe[incompatible-type] The aria-* props are replaced, the rest of T is kept | ||
| return resolvedProps; | ||
| } | ||
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.
nit: read
props.accessibilityStateonce