Skip to content

Commit 65b16b1

Browse files
nucsebmarkbage
authored andcommitted
Allow custom attribute named on to be passed on to elements (#11153)
* Allow single `on` property for custom elements * Remove test from ReactDOMComponent-test * Allow custom attribute named 'on' to be passed * Check property length instead of comparing strings
1 parent 80596c2 commit 65b16b1

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/renderers/dom/shared/DOMProperty.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ var DOMProperty = {
205205
}
206206
if (
207207
(name[0] === 'o' || name[0] === 'O') &&
208-
(name[1] === 'n' || name[1] === 'N')
208+
(name[1] === 'n' || name[1] === 'N') &&
209+
name.length > 2
209210
) {
210211
return false;
211212
}

src/renderers/dom/shared/__tests__/ReactDOMServerIntegration-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,11 @@ describe('ReactDOMServerIntegration', () => {
991991
);
992992
expect(e.getAttribute('onunknownevent')).toBe(null);
993993
});
994+
995+
itRenders('custom attribute named `on`', async render => {
996+
const e = await render(<div on="tap:do-something" />);
997+
expect(e.getAttribute('on')).toEqual('tap:do-something');
998+
});
994999
});
9951000

9961001
describe('elements and children', function() {

src/renderers/dom/shared/hooks/ReactDOMUnknownPropertyHook.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ if (__DEV__) {
7070
return true;
7171
}
7272

73-
if (lowerCasedName.indexOf('on') === 0) {
73+
if (lowerCasedName.indexOf('on') === 0 && lowerCasedName.length > 2) {
7474
warning(
7575
false,
7676
'Unknown event handler property `%s`. It will be ignored.%s',

0 commit comments

Comments
 (0)