From 4dfe2349506a12eb9598bf6a12fd54ce74920957 Mon Sep 17 00:00:00 2001 From: hkal Date: Mon, 3 Oct 2016 10:51:44 -0400 Subject: [PATCH] Add unknown property warning for use of `autofocus` (#7694) (cherry picked from commit f6fdfd1bf0d13e51098a6009c2c85687b1245c9b) --- src/renderers/dom/shared/DOMProperty.js | 6 +++++- .../shared/__tests__/ReactDOMComponent-test.js | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/renderers/dom/shared/DOMProperty.js b/src/renderers/dom/shared/DOMProperty.js index 068638ad6b7cb..8496fb7acf89d 100644 --- a/src/renderers/dom/shared/DOMProperty.js +++ b/src/renderers/dom/shared/DOMProperty.js @@ -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. diff --git a/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js b/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js index a93ca9c7caf4b..2f7ce9a7764c7 100644 --- a/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js +++ b/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js @@ -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' + ); + }); }); });