Conversation
|
@crazeface has exported this pull request. If you are a Meta employee, you can view the originating Diff in D120049025. |
Summary: Pull Request resolved: react#58599 `AccessibilityState::selected` was a plain `bool` defaulting to `false`, so the native side could not tell a component that is selectable but currently unselected (`accessibilityState={{selected: false}}`) from one that is not selectable at all (`accessibilityState={{}}`). Both arrived as `false`. The JS type is already `selected?: ?boolean`, so this is the bridge discarding a value the public API accepts. Make `selected` a `std::optional<bool>` defaulting to `std::nullopt`. JS accessibilityState native selected (before -> after) {} false -> undefined {selected: false} false -> false {selected: true} true -> true This aligns the representation with ARIA, which `accessibilityState` mirrors: the bool / tri-state split now tracks which ARIA attributes admit an undefined value. field ARIA value type admits undefined representation disabled boolean no bool busy boolean no bool selected boolean yes std::optional<bool> (changed) expanded boolean yes std::optional<bool> checked tristate yes CheckedState (None = unset) That is also why `disabled` and `busy` stay plain `bool`: ARIA gives them no undefined value, so there is no unset state to preserve. `expanded` was made optional for this same reason in react#40881 and `checked` has always carried a `None`; `selected` was the outlier. Nor is "unset" merely "absent" for this attribute. `testing-library/dom` computes it as `boolean | undefined`, documented "false/true if (not)selected, undefined if not selectable" -- the same shape, with the same meaning, that this change introduces. Host platforms need the distinction: on Windows a selectable component must implement ISelectionItemProvider so UIA can report selection state, and with the old representation every component carrying an accessibilityState looked selectable. iOS and Android rendering is unchanged. Trait derivation coalesces the optional with `value_or(false)`, and the Android serializer omits the key when the value is unset, which `BaseViewManager#setViewState` already handles by falling back to `setSelected(false)`. Reviewer note: `std::optional<bool>` is contextually convertible to `bool`, so a bare `if (state.selected)` still compiles but tests engagement rather than value, silently marking an explicitly unselected component as selected. There is a regression test for that specific hazard. Fixes react#46988 Supersedes react#47296, which went stale. Changelog: [General][Breaking] - `AccessibilityState::selected` is now `std::optional<bool>` in C++ props, preserving an unset `selected` instead of coercing it to `false` Reviewed By: javache Differential Revision: D120049025
crazeface
force-pushed
the
export-D120049025
branch
from
September 18, 2026 19:39
ae4d91d to
3b01f3d
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
AccessibilityState::selectedwas a plainbooldefaulting tofalse, so thenative side could not tell a component that is selectable but currently
unselected (
accessibilityState={{selected: false}}) from one that is notselectable at all (
accessibilityState={{}}). Both arrived asfalse. The JStype is already
selected?: ?boolean, so this is the bridge discarding a valuethe public API accepts.
Make
selectedastd::optional<bool>defaulting tostd::nullopt.JS accessibilityState native selected (before -> after)
{} false -> undefined
{selected: false} false -> false
{selected: true} true -> true
This aligns the representation with ARIA, which
accessibilityStatemirrors:the bool / tri-state split now tracks which ARIA attributes admit an undefined
value.
field ARIA value type admits undefined representation
disabled boolean no bool
busy boolean no bool
selected boolean yes std::optional (changed)
expanded boolean yes std::optional
checked tristate yes CheckedState (None = unset)
That is also why
disabledandbusystay plainbool: ARIA gives them noundefined value, so there is no unset state to preserve.
expandedwas madeoptional for this same reason in
#40881 and
checkedhas alwayscarried a
None;selectedwas the outlier.Nor is "unset" merely "absent" for this attribute.
testing-library/domcomputes it as
boolean | undefined, documented "false/true if (not)selected,undefined if not selectable" -- the same shape, with the same meaning, that
this change introduces.
Host platforms need the distinction: on Windows a selectable component must
implement ISelectionItemProvider so UIA can report selection state, and with
the old representation every component carrying an accessibilityState looked
selectable.
iOS and Android rendering is unchanged. Trait derivation coalesces the optional
with
value_or(false), and the Android serializer omits the key when the valueis unset, which
BaseViewManager#setViewStatealready handles by falling backto
setSelected(false).Reviewer note:
std::optional<bool>is contextually convertible tobool, so abare
if (state.selected)still compiles but tests engagement rather thanvalue, silently marking an explicitly unselected component as selected. There is
a regression test for that specific hazard.
Fixes #46988
Supersedes #47296, which went stale.
Changelog:
[General][Breaking] -
AccessibilityState::selectedis nowstd::optional<bool>in C++ props, preserving an unsetselectedinstead of coercing it tofalseReviewed By: javache
Differential Revision: D120049025