Skip to content

Commit

Permalink
Add unknown property warning for use of autofocus (#7694)
Browse files Browse the repository at this point in the history
(cherry picked from commit f6fdfd1)
  • Loading branch information
hkal authored and zpao committed Oct 4, 2016
1 parent 8ecaadd commit 4dfe234
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/renderers/dom/shared/DOMProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,13 @@ var DOMProperty = {
/**
* Mapping from lowercase property names to the properly cased version, used
* to warn in the case of missing properties. Available only in __DEV__.
*
* autofocus is predefined, because adding it to the property whitelist
* causes unintended side effects.
*
* @type {Object}
*/
getPossibleStandardName: __DEV__ ? {} : null,
getPossibleStandardName: __DEV__ ? {autofocus: 'autoFocus'} : null,

/**
* All of the isCustomAttribute() functions that have been injected.
Expand Down
17 changes: 17 additions & 0 deletions src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1494,5 +1494,22 @@ describe('ReactDOMComponent', () => {
//since hard coding the line number would make test too brittle
expect(parseInt(previousLine, 10) + 12).toBe(parseInt(currentLine, 10));
});

it('should suggest property name if available', () => {
spyOn(console, 'error');

ReactTestUtils.renderIntoDocument(React.createElement('label', {for: 'test'}));
ReactTestUtils.renderIntoDocument(React.createElement('input', {type: 'text', autofocus: true}));

expect(console.error.calls.count()).toBe(2);

expect(console.error.calls.argsFor(0)[0]).toBe(
'Warning: Unknown DOM property for. Did you mean htmlFor?\n in label'
);

expect(console.error.calls.argsFor(1)[0]).toBe(
'Warning: Unknown DOM property autofocus. Did you mean autoFocus?\n in input'
);
});
});
});

0 comments on commit 4dfe234

Please sign in to comment.