Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/example/src/ListScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function ListRow({ item, index }: ListRowProps) {
const addedLines = expandedRows ? 2 : 0
const detailLineCount = index % 3 + addedLines
const detailLines = Array.from({ length: detailLineCount }, (_, lineIndex) => {
return <Text key={lineIndex}>{`Additional content line ${lineIndex + 1}`}</Text>
return <Text key={lineIndex} aria-hidden>{`Additional content line ${lineIndex + 1}`}</Text>
})

return (
Expand Down
14 changes: 13 additions & 1 deletion docs/content/docs/accessibility.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function ContactRow({ name, phone }: { name: string; phone: string }) {
<Text role="button" gestureRecognizers={[archiveTap]}>Archive</Text>
```

The roles use the web's ARIA names: `alert`, `button`, `checkbox`, `combobox`, `dialog`, `grid`, `group`, `heading`, `img`, `link`, `list`, `listitem`, `menu`, `menubar`, `menuitem`, `progressbar`, `radio`, `radiogroup`, `scrollbar`, `searchbox`, `slider`, `spinbutton`, `switch`, `tab`, `tablist`, `timer` and `toolbar`. `none` and `presentation` only clear the role. They don't hide the view from screen readers.
The roles use the web's ARIA names: `alert`, `button`, `checkbox`, `combobox`, `dialog`, `grid`, `group`, `heading`, `img`, `link`, `list`, `listitem`, `menu`, `menubar`, `menuitem`, `progressbar`, `radio`, `radiogroup`, `scrollbar`, `searchbox`, `slider`, `spinbutton`, `switch`, `tab`, `tablist`, `timer` and `toolbar`. `none` and `presentation` only clear the role. They don't hide the view from screen readers. Use `aria-hidden` for that.

On iOS each role maps to traits, and a role replaces the view's own traits, such as a label's static text trait. On Android a role reports the matching widget class, such as `Button` or `CheckBox`. `heading` marks the node as a heading, and `link` and `tab` set its role description. An `alert` is also an assertive live region on Android, so TalkBack announces its changes. Other roles without a matching widget, such as `menu` or `toolbar`, don't change the node on Android.

Expand All @@ -72,6 +72,17 @@ The state props tell the screen reader what a view is doing: `aria-disabled`, `a

`aria-disabled` only changes what the screen reader says. It doesn't block touches.

## Hide decorative content

`aria-hidden` hides a view and its children from screen readers. Use it for decoration and for content that repeats what a nearby label already says. A grouped view leaves hidden children out of the text it reads.

```tsx
<View accessible aria-label="Rain, 12 degrees">
<Image image={rainIcon} layout={{ width: 24, height: 24 }} aria-hidden />
<Text>12°</Text>
</View>
```

## Props

| Prop | Type | iOS | Android |
Expand All @@ -81,3 +92,4 @@ The state props tell the screen reader what a view is doing: `aria-disabled`, `a
| `accessibilityHint` | `string` | `accessibilityHint` | Node hint text |
| `role` | `Role` | `accessibilityTraits` | Node class name, heading, or role description |
| `aria-disabled`, `aria-selected`, `aria-checked`, `aria-expanded`, `aria-busy` | `boolean`, or `'mixed'` for `aria-checked` | Traits, value, and expanded status on iOS 18 | Node enabled, selected, checked, expand actions, state description |
| `aria-hidden` | `boolean` | `accessibilityElementsHidden` | Important for accessibility, no, hiding descendants |
2 changes: 1 addition & 1 deletion docs/content/docs/components/view/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ Pass `gestureRecognizers` to attach touch handlers. The `ref` exposes the native
| `style` | Style object | Accepts shared styles, a linear-gradient `background`, and an ordered `boxShadow` array. Each shadow takes `offsetX`, `offsetY`, `color`, and optional `blurRadius`, `spreadDistance`, and `inset`. Shadows require Android API 31+ on Android. [Style properties](/docs/layout#style-properties) |
| `gestureRecognizers` | `GestureRecognizer[]` | Attach these recognizers to the native view. [Gestures](/docs/gestures) |
| `isUserInteractionEnabled` | `boolean` | Set to `false` to disable touch interaction on the view. |
| `accessible`, `aria-label`, `accessibilityHint`, `role`, `aria-disabled`, `aria-selected`, `aria-checked`, `aria-expanded`, `aria-busy` | Accessibility props | Describe the view to screen readers. [Accessibility](/docs/accessibility) |
| `accessible`, `aria-label`, `accessibilityHint`, `role`, `aria-disabled`, `aria-selected`, `aria-checked`, `aria-expanded`, `aria-busy`, `aria-hidden` | Accessibility props | Describe the view to screen readers. [Accessibility](/docs/accessibility) |
| `ref` | React ref | Access the native container as `ViewRef`. |
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,11 @@ public extension View {
}
}

var ariaHidden: Bool {
get { view.accessibilityElementsHidden }
set { view.accessibilityElementsHidden = newValue }
}

/// A role replaces the view's own traits, such as a label's static text trait.
private func updateAccessibilityTraits() {
if accessibilityAttributes.defaultTraits == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface ViewOperations {
var ariaChecked: AccessibilityCheckedState?
var ariaExpanded: Boolean?
var ariaBusy: Boolean
var ariaHidden: Boolean

fun setBackgroundColor(color: Double?)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,23 @@ class ViewState(
get() = ViewCompat.isScreenReaderFocusable(view)
set(value) {
ViewCompat.setScreenReaderFocusable(view, value)
view.importantForAccessibility =
if (value) View.IMPORTANT_FOR_ACCESSIBILITY_YES else View.IMPORTANT_FOR_ACCESSIBILITY_AUTO
updateImportantForAccessibility()
}

override var ariaHidden = false
set(value) {
field = value
updateImportantForAccessibility()
}

private fun updateImportantForAccessibility() {
view.importantForAccessibility = when {
ariaHidden -> View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
accessible -> View.IMPORTANT_FOR_ACCESSIBILITY_YES
else -> View.IMPORTANT_FOR_ACCESSIBILITY_AUTO
}
}

override var ariaLabel: String?
get() = view.contentDescription?.toString()
set(value) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/nitro-ui-renderer/src/ViewPropSetters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,7 @@ export const viewPropsSetters: {
'aria-busy': (view, value) => {
view.ariaBusy = value ?? false
},
'aria-hidden': (view, value) => {
view.ariaHidden = value ?? false
},
};
5 changes: 5 additions & 0 deletions packages/nitro-ui-renderer/src/specs/View.nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ export declare class View extends HybridObject {
ariaExpanded?: boolean
/** Screen readers read the view as busy, such as while it loads. */
ariaBusy: boolean
/**
* Hides this view and its children from screen readers, such as a decorative image.
* Maps to `accessibilityElementsHidden` on iOS and hidden descendants on Android.
*/
ariaHidden: boolean

animate(duration: number, curve: AnimationCurve, animations: () => void): Animator
/**
Expand Down
2 changes: 2 additions & 0 deletions packages/nitro-ui-renderer/src/types/AccessibilityProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ export type AccessibilityProps = {
'aria-expanded'?: boolean
/** Screen readers read the view as busy, such as while it loads. */
'aria-busy'?: boolean
/** Hides this view and its children from screen readers, such as decorative content. */
'aria-hidden'?: boolean
}
1 change: 1 addition & 0 deletions packages/nitro-ui-renderer/test/list-recycling.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class FakeView implements NativeView {
ariaChecked?: AccessibilityCheckedState
ariaExpanded?: boolean
ariaBusy = false
ariaHidden = false

constructor(readonly kind: string) {
nodes.set(this.layoutNodePtr, { view: this, children: [] })
Expand Down
Loading