Skip to content

[Flare] First pass at an implementation of experimental FocusManager API #15849

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

Closed
wants to merge 15 commits into from
Closed
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
69 changes: 2 additions & 67 deletions packages/react-dom/src/events/DOMEventResponderSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ import warning from 'shared/warning';
import {enableEventAPI} from 'shared/ReactFeatureFlags';
import {invokeGuardedCallbackAndCatchFirstError} from 'shared/ReactErrorUtils';
import invariant from 'shared/invariant';
import {
isFiberSuspenseAndTimedOut,
getSuspenseFallbackChild,
} from 'react-reconciler/src/ReactFiberEvents';

import {getClosestInstanceFromNode} from '../client/ReactDOMComponentTree';
import {
Expand Down Expand Up @@ -389,16 +385,9 @@ const eventResponderContext: ReactDOMResponderContext = {
}
}
},
getFocusableElementsInScope(): Array<HTMLElement> {
getCurrentInstance(): ReactDOMEventComponentInstance {
validateResponderContext();
const focusableElements = [];
const eventComponentInstance = ((currentInstance: any): ReactDOMEventComponentInstance);
const child = ((eventComponentInstance.currentFiber: any): Fiber).child;

if (child !== null) {
collectFocusableElements(child, focusableElements);
}
return focusableElements;
return ((currentInstance: any): ReactDOMEventComponentInstance);
},
getActiveDocument,
objectAssign: Object.assign,
Expand Down Expand Up @@ -464,33 +453,6 @@ const eventResponderContext: ReactDOMResponderContext = {
},
};

function collectFocusableElements(
node: Fiber,
focusableElements: Array<HTMLElement>,
): void {
if (isFiberSuspenseAndTimedOut(node)) {
const fallbackChild = getSuspenseFallbackChild(node);
if (fallbackChild !== null) {
collectFocusableElements(fallbackChild, focusableElements);
}
} else {
if (isFiberHostComponentFocusable(node)) {
focusableElements.push(node.stateNode);
} else {
const child = node.child;

if (child !== null) {
collectFocusableElements(child, focusableElements);
}
}
}
const sibling = node.sibling;

if (sibling !== null) {
collectFocusableElements(sibling, focusableElements);
}
}

function getActiveDocument(): Document {
return ((currentDocument: any): Document);
}
Expand All @@ -506,33 +468,6 @@ function releaseOwnershipForEventComponentInstance(
return false;
}

function isFiberHostComponentFocusable(fiber: Fiber): boolean {
if (fiber.tag !== HostComponent) {
return false;
}
const {type, memoizedProps} = fiber;
if (memoizedProps.tabIndex === -1 || memoizedProps.disabled) {
return false;
}
if (memoizedProps.tabIndex === 0 || memoizedProps.contentEditable === true) {
return true;
}
if (type === 'a' || type === 'area') {
return !!memoizedProps.href && memoizedProps.rel !== 'ignore';
}
if (type === 'input') {
return memoizedProps.type !== 'hidden' && memoizedProps.type !== 'file';
}
return (
type === 'button' ||
type === 'textarea' ||
type === 'object' ||
type === 'select' ||
type === 'iframe' ||
type === 'embed'
);
}

function processTimers(
timers: Map<number, ResponderTimer>,
delay: number,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-events/focus-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@

const FocusScope = require('./src/dom/FocusScope');

module.exports = FocusScope.default || FocusScope;
module.exports = FocusScope;
Loading