diff --git a/packages/core/src/components/overlay/overlay.tsx b/packages/core/src/components/overlay/overlay.tsx index 4efe4df06a..a0cf4a279a 100644 --- a/packages/core/src/components/overlay/overlay.tsx +++ b/packages/core/src/components/overlay/overlay.tsx @@ -27,7 +27,7 @@ import { CSSTransition, TransitionGroup } from "react-transition-group"; import { AbstractPureComponent, Classes } from "../../common"; import { DISPLAYNAME_PREFIX, type HTMLDivProps } from "../../common/props"; -import { getActiveElement, isFunction } from "../../common/utils"; +import { getActiveElement, isFunction, isReactElement } from "../../common/utils"; import { Portal } from "../portal/portal"; import type { OverlayProps } from "./overlayProps"; @@ -215,18 +215,11 @@ export class Overlay extends AbstractPureComponent { } // decorate the child with a few injected props - const tabIndex = this.props.enforceFocus || this.props.autoFocus ? 0 : undefined; - const decoratedChild = - typeof child === "object" ? ( - React.cloneElement(child as React.ReactElement, { - className: classNames((child as React.ReactElement).props.className, Classes.OVERLAY_CONTENT), - tabIndex, - }) - ) : ( - - {child} - - ); + const decoratedChild = isReactElement(child) ? ( + React.cloneElement(child, { className: classNames(child.props.className, Classes.OVERLAY_CONTENT) }) + ) : ( + {child} + ); const { onOpening, onOpened, onClosing, transitionDuration, transitionName } = this.props; diff --git a/packages/core/src/components/overlay2/overlay2.tsx b/packages/core/src/components/overlay2/overlay2.tsx index 260b184302..3546087452 100644 --- a/packages/core/src/components/overlay2/overlay2.tsx +++ b/packages/core/src/components/overlay2/overlay2.tsx @@ -393,7 +393,6 @@ export const Overlay2 = React.forwardRef((props, // IMPORTANT: only inject our ref if the user didn't specify childRef or childRefs already. Otherwise, // we risk clobbering the user's ref (which we cannot inspect here while cloning/decorating the child). ref: userChildRef === undefined ? localChildRef : undefined, - tabIndex: enforceFocus || autoFocus ? 0 : undefined, }); const resolvedChildRef = userChildRef ?? localChildRef; @@ -416,8 +415,6 @@ export const Overlay2 = React.forwardRef((props, ); }, [ - autoFocus, - enforceFocus, getUserChildRef, handleTransitionAddEnd, handleTransitionExited,