feat(a11y): automatically set accessible prop with role prop - #57633
feat(a11y): automatically set accessible prop with role prop#57633mdjastrzebski wants to merge 3 commits into
accessible prop with role prop#57633Conversation
accessible with role propaccessible prop with role prop
|
This seems reasonable, but is there any chance we can do this on the native side instead? We should avoid post-processing props in JS for perf reasons. |
|
@javache I did some research and it looks like C++ calculation would be fine for iOS, but on Android we need to have duplicated logic in Kotlin since the ViewManagers use the original JS Hence, I would advise to keep it in JS right now, and migrate multiple prop calculation from JS to C++ as a unified effort when Props 2.0 is available on Android. |
| const { | ||
| 'aria-busy': ariaBusy, | ||
| 'aria-checked': ariaChecked, | ||
| 'aria-disabled': ariaDisabled, | ||
| 'aria-expanded': ariaExpanded, | ||
| 'aria-selected': ariaSelected, | ||
| 'aria-hidden': ariaHidden, | ||
| src, | ||
| ...restProps | ||
| } = props; |
There was a problem hiding this comment.
Extract accessible here (ditto for 'aria-label/accessibilityLabel) - we generally want to extract props once, and avoid passing them both in restProps` and through explicit props.
You'd want to model this like View where we create a single resolvedProps object which we write everything to.
Fine to do this as a follow-up cleanup PR, and overload this one.
There was a problem hiding this comment.
I will submit follow-up for not to muddle the scope
|
@javache has imported this pull request. If you are a Meta employee, you can view this in D113754156. |
Summary: This diff reverts react#57633 ## Changelog [GENERAL] [CHANGED] Revert: Automatically set acessible prop when role prop is set (except none/presenation) Differential Revision: D113922297
|
This caused some internal failures, so we've had to back it out for now. Let me follow-up to identify the root cause. |
…t none/presenation) (#57743) Summary: Pull Request resolved: #57743 This diff reverts #57633 ## Changelog [GENERAL] [CHANGED] Revert: Automatically set acessible prop when role prop is set (except none/presenation) Reviewed By: javache Differential Revision: D113922297 fbshipit-source-id: 705fe67f5f712be5e7baccdd01603915f47893a1
|
The reason for the revert is that we had some components already setting role, but not accessible, so this change made them Focusable. This is a breaking change (and we should document it as such) and we should wait until the next breaking changes window to re-land this. |
|
@javache thank you for your research, could you share some context why components (View, Image) would be setting role without Q2: when would be next such window? |
We had some accidental usages of this, as previously this was a no-op.
the next branch-cut is September 7. |
|
To clarify the window is before or after Sep 7? |
It's after. We're aiming to not make any breaking changes on main until the next branch cut. |
Summary: Two changes to `Image.ios.js` (follow up to #57633): 1. **Extract props once.** Per javache's review comment, props are destructured once in the parameter list and written into a single `resolvedProps` object, spread into `ImageViewNativeComponent` once — modelled on `View`, matching `Image.android.js`. `ImageAnalyticsTagContext.Consumer` is replaced with `use(ImageAnalyticsTagContext)`. 2. **Align `aria-*` vs `accessibilityState`.** `aria-*` state props now take priority per key with fallback to `accessibilityState`, matching `View`, `Text`, `TextInput`, `Pressable` and `Image.android.js`. `Image.ios.js` was the only outlier, where the raw `accessibilityState` object replaced the merged one. Also aligns the `alt` null-check with `Image.android.js` (`alt != null`), so an explicit `alt={null}` no longer forces `accessible: true`. Adds `Image-itest.js` coverage for the `aria-*` to `accessibilityState` mapping, including `aria-checked` as `true`/`false`/`"mixed"`, precedence over the matching `accessibilityState` field, and that `accessibilityState` is not emitted when no state props are given. ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [IOS] [FIXED] - Image: aria-* state props are no longer ignored when accessibilityState is also present Pull Request resolved: #57710 Test Plan: Unchanged tests pass + added new tests Reviewed By: christophpurrer Differential Revision: D114048967 Pulled By: javache fbshipit-source-id: c09647dba932cb747ecab6392e281009e85b8d3f
Summary:
Setting
roleprop (exceptnone/presentation) automatically setsaccessibleprop onViewandImage. This aligns web behavior when settingroleattribute is enough to add the element into accessibility tree.This aligns also with
Imagealtweb-compat prop which also enablesaccessiblewhen set.The change skips
Text,TextInput, etc as they are implicitly members of accessibility tree by default.This change also intentionally skips
accessibilityRoleas legacy, non-web version.This also helps when using React Strict DOM, as it exposes
roleprop, but does not exposeaccessibleprop, hence settingroleonh.divbasically has no effect. I think this changes is better suited for RN repo though.Changelog:
[GENERAL] [CHANGED] Automatically set
acessibleprop whenroleprop is set (exceptnone/presenation)Test Plan:
Added relevant Fantom tests.