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

autoFocus related tweaks #8779

Merged
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
11 changes: 6 additions & 5 deletions src/renderers/dom/fiber/ReactDOMFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ findDOMNode._injectFiber(function(fiber: Fiber) {
type DOMContainerElement = Element & { _reactRootContainer: ?Object };

type Container = Element;
type Props = { children ?: mixed };
type Props = {
autoFocus ?: boolean,
children ?: mixed,
};
type Instance = Element;
type TextInstance = Text;

Expand Down Expand Up @@ -105,7 +108,7 @@ function shouldAutoFocusHostComponent(
case 'input':
case 'select':
case 'textarea':
return !!(props : any).autoFocus;
return !!props.autoFocus;
}
return false;
}
Expand Down Expand Up @@ -223,9 +226,7 @@ var DOMRenderer = ReactFiberReconciler({
rootContainerInstance : Container,
internalInstanceHandle : Object,
) : void {
if (shouldAutoFocusHostComponent(type, newProps)) {
(domElement : any).focus();
}
((domElement : any) : HTMLButtonElement | HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement).focus();
},

commitUpdate(
Expand Down
5 changes: 3 additions & 2 deletions src/renderers/shared/fiber/ReactFiberCompleteWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var {
Fragment,
} = ReactTypeOfWork;
var {
Ref,
Update,
} = ReactTypeOfSideEffect;

Expand Down Expand Up @@ -233,13 +234,13 @@ module.exports = function<T, P, I, TI, PI, C, CX>(
// (eg DOM renderer supports auto-focus for certain elements).
// Make sure such renderers get scheduled for later work.
if (finalizeInitialChildren(instance, type, newProps, rootContainerInstance)) {
workInProgress.effectTag |= Update;
markUpdate(workInProgress);
}

workInProgress.stateNode = instance;
if (workInProgress.ref) {
// If there is a ref on a host node we need to schedule a callback
markUpdate(workInProgress);
workInProgress.effectTag |= Ref;
}
}
return null;
Expand Down