mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-05-27 08:13:46 +00:00
[add] View/Text prop nativeID
Maps the View and Text prop 'nativeID' to DOM 'id' as these are equivalent. Enables declarative use of various 'aria-*' properties that require ID references. Ref #1116 Close #1130
This commit is contained in:
@@ -21,6 +21,7 @@ const TextPropTypes = {
|
|||||||
accessible: bool,
|
accessible: bool,
|
||||||
children: any,
|
children: any,
|
||||||
importantForAccessibility: oneOf(['auto', 'no', 'no-hide-descendants', 'yes']),
|
importantForAccessibility: oneOf(['auto', 'no', 'no-hide-descendants', 'yes']),
|
||||||
|
nativeID: string,
|
||||||
numberOfLines: number,
|
numberOfLines: number,
|
||||||
onBlur: func,
|
onBlur: func,
|
||||||
onContextMenu: func,
|
onContextMenu: func,
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ export type ViewProps = {
|
|||||||
children?: any,
|
children?: any,
|
||||||
hitSlop?: EdgeInsetsProp,
|
hitSlop?: EdgeInsetsProp,
|
||||||
importantForAccessibility?: 'auto' | 'yes' | 'no' | 'no-hide-descendants',
|
importantForAccessibility?: 'auto' | 'yes' | 'no' | 'no-hide-descendants',
|
||||||
|
nativeID?: string,
|
||||||
onBlur?: Function,
|
onBlur?: Function,
|
||||||
onClick?: Function,
|
onClick?: Function,
|
||||||
onClickCapture?: Function,
|
onClickCapture?: Function,
|
||||||
@@ -87,6 +88,7 @@ const ViewPropTypes = {
|
|||||||
children: any,
|
children: any,
|
||||||
hitSlop: EdgeInsetsPropType,
|
hitSlop: EdgeInsetsPropType,
|
||||||
importantForAccessibility: oneOf(['auto', 'no', 'no-hide-descendants', 'yes']),
|
importantForAccessibility: oneOf(['auto', 'no', 'no-hide-descendants', 'yes']),
|
||||||
|
nativeID: string,
|
||||||
onBlur: func,
|
onBlur: func,
|
||||||
onClick: func,
|
onClick: func,
|
||||||
onClickCapture: func,
|
onClickCapture: func,
|
||||||
|
|||||||
@@ -183,6 +183,12 @@ describe('modules/createDOMProps', () => {
|
|||||||
expect(props['aria-hidden']).toEqual(true);
|
expect(props['aria-hidden']).toEqual(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('prop "nativeID" becomes "id"', () => {
|
||||||
|
const nativeID = 'Example.nativeID';
|
||||||
|
const props = createProps({ nativeID });
|
||||||
|
expect(props.id).toEqual(nativeID);
|
||||||
|
});
|
||||||
|
|
||||||
test('prop "testID" becomes "data-testid"', () => {
|
test('prop "testID" becomes "data-testid"', () => {
|
||||||
const testID = 'Example.testID';
|
const testID = 'Example.testID';
|
||||||
const props = createProps({ testID });
|
const props = createProps({ testID });
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ const createDOMProps = (component, props, styleResolver) => {
|
|||||||
accessibilityLabel,
|
accessibilityLabel,
|
||||||
accessibilityLiveRegion,
|
accessibilityLiveRegion,
|
||||||
importantForAccessibility,
|
importantForAccessibility,
|
||||||
|
nativeID,
|
||||||
placeholderTextColor,
|
placeholderTextColor,
|
||||||
pointerEvents,
|
pointerEvents,
|
||||||
style: providedStyle,
|
style: providedStyle,
|
||||||
@@ -164,10 +165,15 @@ const createDOMProps = (component, props, styleResolver) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// OTHER
|
// OTHER
|
||||||
|
// Native element ID
|
||||||
|
if (nativeID && nativeID.constructor === String) {
|
||||||
|
domProps.id = nativeID;
|
||||||
|
}
|
||||||
// Link security and automation test ids
|
// Link security and automation test ids
|
||||||
if (component === 'a' && domProps.target === '_blank') {
|
if (component === 'a' && domProps.target === '_blank') {
|
||||||
domProps.rel = `${domProps.rel || ''} noopener noreferrer`;
|
domProps.rel = `${domProps.rel || ''} noopener noreferrer`;
|
||||||
}
|
}
|
||||||
|
// Automated test IDs
|
||||||
if (testID && testID.constructor === String) {
|
if (testID && testID.constructor === String) {
|
||||||
domProps['data-testid'] = testID;
|
domProps['data-testid'] = testID;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,6 +116,12 @@ const TextScreen = () => (
|
|||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<DocItem
|
||||||
|
name="nativeID"
|
||||||
|
typeInfo="?string"
|
||||||
|
description="Used to locate this view from any native DOM code, or to define accessibility relationships. This is rendered to the native 'id' DOM attribute"
|
||||||
|
/>
|
||||||
|
|
||||||
<DocItem
|
<DocItem
|
||||||
name="numberOfLines"
|
name="numberOfLines"
|
||||||
typeInfo="?number"
|
typeInfo="?number"
|
||||||
|
|||||||
@@ -119,6 +119,12 @@ const ViewScreen = () => (
|
|||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<DocItem
|
||||||
|
name="nativeID"
|
||||||
|
typeInfo="?string"
|
||||||
|
description="Used to locate this view from any native DOM code, or to define accessibility relationships. This is rendered to the native 'id' DOM attribute"
|
||||||
|
/>
|
||||||
|
|
||||||
<DocItem name="onBlur" typeInfo="?function" />
|
<DocItem name="onBlur" typeInfo="?function" />
|
||||||
<DocItem name="onContextMenu" typeInfo="?function" />
|
<DocItem name="onContextMenu" typeInfo="?function" />
|
||||||
<DocItem name="onFocus" typeInfo="?function" />
|
<DocItem name="onFocus" typeInfo="?function" />
|
||||||
|
|||||||
Reference in New Issue
Block a user