Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unknown property warning for use of autofocus #7694

Merged
merged 1 commit into from
Oct 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a space before the key name and after the value? { autofocus: 'autoFocus' }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


/**
* 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 @@ -1495,5 +1495,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'
);
});
});
});