Skip to content

Commit 53f37f1

Browse files
committed
Add default accessibility roles to native elements
1 parent 7b035ff commit 53f37f1

File tree

5 files changed

+1043
-5
lines changed

5 files changed

+1043
-5
lines changed

packages/react-strict-dom/src/native/modules/createStrictDOMComponent.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,14 @@ export function createStrictDOMComponent<T, P: StrictProps>(
6262

6363
// Tag-specific props
6464

65-
if (tagName === 'header') {
65+
if (tagName === 'button') {
66+
nativeProps.role ??= 'button';
67+
} else if (tagName === 'header') {
6668
nativeProps.role ??= 'header';
69+
} else if (tagName === 'li') {
70+
nativeProps.role ??= 'listitem';
71+
} else if (tagName === 'ol' || tagName === 'ul') {
72+
nativeProps.role ??= 'list';
6773
}
6874

6975
// Component-specific props

packages/react-strict-dom/src/native/modules/createStrictDOMTextComponent.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ export function createStrictDOMTextComponent<T, P: StrictProps>(
7373
}
7474
} else if (tagName === 'br') {
7575
nativeProps.children = '\n';
76+
} else if (
77+
tagName === 'h1' ||
78+
tagName === 'h2' ||
79+
tagName === 'h3' ||
80+
tagName === 'h4' ||
81+
tagName === 'h5' ||
82+
tagName === 'h6'
83+
) {
84+
nativeProps.role ??= 'heading';
7685
} else if (tagName === 'option') {
7786
nativeProps.children = label;
7887
}

0 commit comments

Comments
 (0)