mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-01 01:59:10 +00:00
[change] Map 'button' and 'paragraph' role to HTML elements
Fix #1899 Close #1944
This commit is contained in:
committed by
Nicolas Gallagher
parent
95c8a545a7
commit
e8a0cbc60a
@@ -277,13 +277,11 @@ The value of the `accessibilityRole` prop is used to infer an [analogous HTML el
|
|||||||
</View>
|
</View>
|
||||||
/*
|
/*
|
||||||
<article>
|
<article>
|
||||||
<div role="paragraph">This is an article</div>
|
<p>This is an article</p>
|
||||||
</article>
|
</article>
|
||||||
*/
|
*/
|
||||||
```
|
```
|
||||||
|
|
||||||
The `"paragraph"` role isn't mapped to a `<p>` tag because it's an HTML conformance error to include block-level children within the element; both `Text` and `View` support block-level children.
|
|
||||||
|
|
||||||
If the `"heading"` role is combined with an `accessibilityLevel`, the equivalent HTML heading element is rendered. Otherwise, it is rendered as `<h1>`.
|
If the `"heading"` role is combined with an `accessibilityLevel`, the equivalent HTML heading element is rendered. Otherwise, it is rendered as `<h1>`.
|
||||||
|
|
||||||
```jsx
|
```jsx
|
||||||
|
|||||||
+16
-14
@@ -1,70 +1,72 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`components/Button prop "accessibilityLabel" 1`] = `
|
exports[`components/Button prop "accessibilityLabel" 1`] = `
|
||||||
<div
|
<button
|
||||||
aria-label="accessibility label"
|
aria-label="accessibility label"
|
||||||
class="css-view-175oi2r r-transitionProperty-1i6wzkk r-userSelect-lrvibr r-cursor-1loqt21 r-touchAction-1otgn73 r-backgroundColor-14sbq61 r-borderRadius-1jkafct"
|
class="css-view-175oi2r r-transitionProperty-1i6wzkk r-userSelect-lrvibr r-cursor-1loqt21 r-touchAction-1otgn73 r-backgroundColor-14sbq61 r-borderRadius-1jkafct"
|
||||||
role="button"
|
role="button"
|
||||||
style="transition-duration: 0s;"
|
style="transition-duration: 0s;"
|
||||||
tabindex="0"
|
type="button"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="css-text-1rynq56 r-color-jwli3a r-fontWeight-majxgm r-padding-edyy15 r-textAlign-q4m81j r-textTransform-tsynxw"
|
class="css-text-1rynq56 r-color-jwli3a r-fontWeight-majxgm r-padding-edyy15 r-textAlign-q4m81j r-textTransform-tsynxw"
|
||||||
dir="auto"
|
dir="auto"
|
||||||
/>
|
/>
|
||||||
</div>
|
</button>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`components/Button prop "color" 1`] = `
|
exports[`components/Button prop "color" 1`] = `
|
||||||
<div
|
<button
|
||||||
class="css-view-175oi2r r-transitionProperty-1i6wzkk r-userSelect-lrvibr r-cursor-1loqt21 r-touchAction-1otgn73 r-borderRadius-1jkafct"
|
class="css-view-175oi2r r-transitionProperty-1i6wzkk r-userSelect-lrvibr r-cursor-1loqt21 r-touchAction-1otgn73 r-borderRadius-1jkafct"
|
||||||
role="button"
|
role="button"
|
||||||
style="background-color: rgb(0, 0, 255); transition-duration: 0s;"
|
style="background-color: rgb(0, 0, 255); transition-duration: 0s;"
|
||||||
tabindex="0"
|
type="button"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="css-text-1rynq56 r-color-jwli3a r-fontWeight-majxgm r-padding-edyy15 r-textAlign-q4m81j r-textTransform-tsynxw"
|
class="css-text-1rynq56 r-color-jwli3a r-fontWeight-majxgm r-padding-edyy15 r-textAlign-q4m81j r-textTransform-tsynxw"
|
||||||
dir="auto"
|
dir="auto"
|
||||||
/>
|
/>
|
||||||
</div>
|
</button>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`components/Button prop "disabled" 1`] = `
|
exports[`components/Button prop "disabled" 1`] = `
|
||||||
<div
|
<button
|
||||||
aria-disabled="true"
|
aria-disabled="true"
|
||||||
class="css-view-175oi2r r-transitionProperty-1i6wzkk r-userSelect-lrvibr r-borderRadius-1jkafct r-backgroundColor-11mpjr4 r-pointerEvents-633pao"
|
class="css-view-175oi2r r-transitionProperty-1i6wzkk r-userSelect-lrvibr r-borderRadius-1jkafct r-backgroundColor-11mpjr4 r-pointerEvents-633pao"
|
||||||
|
disabled=""
|
||||||
role="button"
|
role="button"
|
||||||
style="transition-duration: 0s;"
|
style="transition-duration: 0s;"
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
|
type="button"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="css-text-1rynq56 r-fontWeight-majxgm r-padding-edyy15 r-textAlign-q4m81j r-textTransform-tsynxw r-color-c68hjy"
|
class="css-text-1rynq56 r-fontWeight-majxgm r-padding-edyy15 r-textAlign-q4m81j r-textTransform-tsynxw r-color-c68hjy"
|
||||||
dir="auto"
|
dir="auto"
|
||||||
/>
|
/>
|
||||||
</div>
|
</button>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`components/Button prop "testID" 1`] = `
|
exports[`components/Button prop "testID" 1`] = `
|
||||||
<div
|
<button
|
||||||
class="css-view-175oi2r r-transitionProperty-1i6wzkk r-userSelect-lrvibr r-cursor-1loqt21 r-touchAction-1otgn73 r-backgroundColor-14sbq61 r-borderRadius-1jkafct"
|
class="css-view-175oi2r r-transitionProperty-1i6wzkk r-userSelect-lrvibr r-cursor-1loqt21 r-touchAction-1otgn73 r-backgroundColor-14sbq61 r-borderRadius-1jkafct"
|
||||||
data-testid="123"
|
data-testid="123"
|
||||||
role="button"
|
role="button"
|
||||||
style="transition-duration: 0s;"
|
style="transition-duration: 0s;"
|
||||||
tabindex="0"
|
type="button"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="css-text-1rynq56 r-color-jwli3a r-fontWeight-majxgm r-padding-edyy15 r-textAlign-q4m81j r-textTransform-tsynxw"
|
class="css-text-1rynq56 r-color-jwli3a r-fontWeight-majxgm r-padding-edyy15 r-textAlign-q4m81j r-textTransform-tsynxw"
|
||||||
dir="auto"
|
dir="auto"
|
||||||
/>
|
/>
|
||||||
</div>
|
</button>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`components/Button prop "title" 1`] = `
|
exports[`components/Button prop "title" 1`] = `
|
||||||
<div
|
<button
|
||||||
class="css-view-175oi2r r-transitionProperty-1i6wzkk r-userSelect-lrvibr r-cursor-1loqt21 r-touchAction-1otgn73 r-backgroundColor-14sbq61 r-borderRadius-1jkafct"
|
class="css-view-175oi2r r-transitionProperty-1i6wzkk r-userSelect-lrvibr r-cursor-1loqt21 r-touchAction-1otgn73 r-backgroundColor-14sbq61 r-borderRadius-1jkafct"
|
||||||
role="button"
|
role="button"
|
||||||
style="transition-duration: 0s;"
|
style="transition-duration: 0s;"
|
||||||
tabindex="0"
|
type="button"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="css-text-1rynq56 r-color-jwli3a r-fontWeight-majxgm r-padding-edyy15 r-textAlign-q4m81j r-textTransform-tsynxw"
|
class="css-text-1rynq56 r-color-jwli3a r-fontWeight-majxgm r-padding-edyy15 r-textAlign-q4m81j r-textTransform-tsynxw"
|
||||||
@@ -72,5 +74,5 @@ exports[`components/Button prop "title" 1`] = `
|
|||||||
>
|
>
|
||||||
Click me
|
Click me
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</button>
|
||||||
`;
|
`;
|
||||||
|
|||||||
+2
-2
@@ -134,10 +134,10 @@ exports[`components/Pressable prop "accessibilityRole" value alters HTML element
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`components/Pressable prop "accessibilityRole" value is "button" 1`] = `
|
exports[`components/Pressable prop "accessibilityRole" value is "button" 1`] = `
|
||||||
<div
|
<button
|
||||||
class="css-view-175oi2r r-cursor-1loqt21 r-touchAction-1otgn73"
|
class="css-view-175oi2r r-cursor-1loqt21 r-touchAction-1otgn73"
|
||||||
role="button"
|
role="button"
|
||||||
tabindex="0"
|
type="button"
|
||||||
/>
|
/>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -52,11 +52,11 @@ exports[`components/Text prop "accessibilityRole" value alters HTML element 1`]
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`components/Text prop "accessibilityRole" value is "button" 1`] = `
|
exports[`components/Text prop "accessibilityRole" value is "button" 1`] = `
|
||||||
<div
|
<button
|
||||||
class="css-text-1rynq56"
|
class="css-text-1rynq56"
|
||||||
dir="auto"
|
dir="auto"
|
||||||
role="button"
|
role="button"
|
||||||
tabindex="0"
|
type="button"
|
||||||
/>
|
/>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -46,10 +46,10 @@ exports[`components/View prop "accessibilityRole" value alters HTML element 1`]
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`components/View prop "accessibilityRole" value is "button" 1`] = `
|
exports[`components/View prop "accessibilityRole" value is "button" 1`] = `
|
||||||
<div
|
<button
|
||||||
class="css-view-175oi2r"
|
class="css-view-175oi2r"
|
||||||
role="button"
|
role="button"
|
||||||
tabindex="0"
|
type="button"
|
||||||
/>
|
/>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|||||||
@@ -471,7 +471,6 @@ describe('exports/createElement', () => {
|
|||||||
createElement('div', { accessibilityRole: 'button' })
|
createElement('div', { accessibilityRole: 'button' })
|
||||||
);
|
);
|
||||||
expect(getAttribute(hasValue, 'role')).toBe('button');
|
expect(getAttribute(hasValue, 'role')).toBe('button');
|
||||||
expect(getAttribute(hasValue, 'tabIndex')).toBe('0');
|
|
||||||
const { container: roleIsNone } = render(
|
const { container: roleIsNone } = render(
|
||||||
createElement('div', { accessibilityRole: 'none' })
|
createElement('div', { accessibilityRole: 'none' })
|
||||||
);
|
);
|
||||||
@@ -649,11 +648,6 @@ describe('exports/createElement', () => {
|
|||||||
);
|
);
|
||||||
expect(getAttribute(isTrueNativelyFocusable, 'tabindex')).toBeNull();
|
expect(getAttribute(isTrueNativelyFocusable, 'tabindex')).toBeNull();
|
||||||
|
|
||||||
const { container: isFocusableRole } = render(
|
|
||||||
createElement('div', { accessibilityRole: 'button', focusable: true })
|
|
||||||
);
|
|
||||||
expect(getAttribute(isFocusableRole, 'tabindex')).toBe('0');
|
|
||||||
|
|
||||||
const { container: isFalseFocusableRole } = render(
|
const { container: isFalseFocusableRole } = render(
|
||||||
createElement('div', { accessibilityRole: 'button', focusable: false })
|
createElement('div', { accessibilityRole: 'button', focusable: false })
|
||||||
);
|
);
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ describe('modules/AccessibilityUtil/propsToAccessibilityComponent', () => {
|
|||||||
test('when "accessibilityRole" is "button"', () => {
|
test('when "accessibilityRole" is "button"', () => {
|
||||||
expect(
|
expect(
|
||||||
propsToAccessibilityComponent({ accessibilityRole: 'button' })
|
propsToAccessibilityComponent({ accessibilityRole: 'button' })
|
||||||
).toBeUndefined();
|
).toEqual('button');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('when "accessibilityRole" is "heading"', () => {
|
test('when "accessibilityRole" is "heading"', () => {
|
||||||
|
|||||||
+2
@@ -13,6 +13,7 @@ const roleComponents = {
|
|||||||
article: 'article',
|
article: 'article',
|
||||||
banner: 'header',
|
banner: 'header',
|
||||||
blockquote: 'blockquote',
|
blockquote: 'blockquote',
|
||||||
|
button: 'button',
|
||||||
code: 'code',
|
code: 'code',
|
||||||
complementary: 'aside',
|
complementary: 'aside',
|
||||||
contentinfo: 'footer',
|
contentinfo: 'footer',
|
||||||
@@ -25,6 +26,7 @@ const roleComponents = {
|
|||||||
listitem: 'li',
|
listitem: 'li',
|
||||||
main: 'main',
|
main: 'main',
|
||||||
navigation: 'nav',
|
navigation: 'nav',
|
||||||
|
paragraph: 'p',
|
||||||
region: 'section',
|
region: 'section',
|
||||||
strong: 'strong'
|
strong: 'strong'
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -349,6 +349,9 @@ const createDOMProps = (elementType, props, options) => {
|
|||||||
domProps['data-testid'] = testID;
|
domProps['data-testid'] = testID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (domProps.type == null && elementType === 'button') {
|
||||||
|
domProps.type = 'button';
|
||||||
|
}
|
||||||
return domProps;
|
return domProps;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user