Skip to content

Commit 8ac79ee

Browse files
gaearonEthan-Arrowood
authored andcommitted
Don't emit autoFocus={false} attribute on the server (facebook#11543)
1 parent 88e036e commit 8ac79ee

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

packages/react-dom/src/__tests__/ReactServerRendering-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,21 @@ describe('ReactDOMServer', () => {
382382
expect(element.firstChild.focus).not.toHaveBeenCalled();
383383
});
384384

385+
it('should not focus on either server or client with autofocus={false}', () => {
386+
var element = document.createElement('div');
387+
element.innerHTML = ReactDOMServer.renderToString(
388+
<input autoFocus={false} />,
389+
);
390+
expect(element.firstChild.autofocus).toBe(false);
391+
392+
element.firstChild.focus = jest.fn();
393+
ReactDOM.hydrate(<input autoFocus={false} />, element);
394+
expect(element.firstChild.focus).not.toHaveBeenCalled();
395+
396+
ReactDOM.render(<input autoFocus={false} />, element);
397+
expect(element.firstChild.focus).not.toHaveBeenCalled();
398+
});
399+
385400
it('should throw with silly args', () => {
386401
expect(
387402
ReactDOMServer.renderToString.bind(ReactDOMServer, {x: 123}),

packages/react-dom/src/shared/HTMLDOMPropertyConfig.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ var HTMLDOMPropertyConfig = {
2020
// name warnings.
2121
Properties: {
2222
allowFullScreen: HAS_BOOLEAN_VALUE,
23-
autoFocus: HAS_STRING_BOOLEAN_VALUE,
2423
// specifies target context for links with `preload` type
2524
async: HAS_BOOLEAN_VALUE,
26-
// autoFocus is polyfilled/normalized by AutoFocusUtils
27-
// autoFocus: HAS_BOOLEAN_VALUE,
25+
// Note: there is a special case that prevents it from being written to the DOM
26+
// on the client side because the browsers are inconsistent. Instead we call focus().
27+
autoFocus: HAS_BOOLEAN_VALUE,
2828
autoPlay: HAS_BOOLEAN_VALUE,
2929
capture: HAS_OVERLOADED_BOOLEAN_VALUE,
3030
checked: MUST_USE_PROPERTY | HAS_BOOLEAN_VALUE,

0 commit comments

Comments
 (0)