Skip to content

Commit cf26126

Browse files
committed
[fix] createElement uses provided function component
If the component provided to 'createElement' is not a string alias for a DOM component, it will no longer attempt to replace that component with a DOM component inferred from the 'accessibility{Component,Role,Traits}' prop. Fix #895
1 parent 1aec803 commit cf26126

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

packages/react-native-web/src/exports/AppRegistry/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default class AppRegistry {
6767
appParameters.initialProps || emptyObject,
6868
appParameters.rootTag,
6969
wrapperComponentProvider && wrapperComponentProvider(appParameters),
70-
appParameters.callback,
70+
appParameters.callback
7171
)
7272
};
7373
return appKey;

packages/react-native-web/src/exports/createElement/__tests__/index-test.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/* eslint-env jasmine, jest */
22

33
import createElement from '..';
4-
import { shallow, render } from 'enzyme';
4+
import React from 'react';
5+
import { render, shallow } from 'enzyme';
56

67
describe('modules/createElement', () => {
78
test('it renders different DOM elements', () => {
@@ -23,9 +24,20 @@ describe('modules/createElement', () => {
2324
});
2425
});
2526

26-
describe('when ARIA role is "button"', () => {
27+
describe('prop "accessibilityRole"', () => {
28+
test('and string component type', () => {
29+
const component = shallow(createElement('span', { accessibilityRole: 'link' }));
30+
expect(component.find('a').length).toBe(1);
31+
});
32+
33+
test('and function component type', () => {
34+
const Custom = () => <div />;
35+
const component = shallow(createElement(Custom, { accessibilityRole: 'link' }));
36+
expect(component.find('div').length).toBe(1);
37+
});
38+
2739
[{ disabled: true }, { disabled: false }].forEach(({ disabled }) => {
28-
describe(`and disabled is "${disabled}"`, () => {
40+
describe(`value is "button" and disabled is "${disabled}"`, () => {
2941
[{ name: 'Enter', which: 13 }, { name: 'Space', which: 32 }].forEach(({ name, which }) => {
3042
test(`"onClick" is ${disabled ? 'not ' : ''}called when "${name}" is pressed`, () => {
3143
const onClick = jest.fn();

packages/react-native-web/src/exports/createElement/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ const adjustProps = domProps => {
8383

8484
const createElement = (component, props, ...children) => {
8585
// use equivalent platform elements where possible
86-
const accessibilityComponent = AccessibilityUtil.propsToAccessibilityComponent(props);
86+
let accessibilityComponent;
87+
if (component && component.constructor === String) {
88+
accessibilityComponent = AccessibilityUtil.propsToAccessibilityComponent(props);
89+
}
8790
const Component = accessibilityComponent || component;
8891
const domProps = createDOMProps(Component, props);
8992
adjustProps(domProps);

0 commit comments

Comments
 (0)