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

fix(Overlay,Overlay2): remove overlay outer tabIndex #6991

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
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
19 changes: 6 additions & 13 deletions packages/core/src/components/overlay/overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -215,18 +215,11 @@ export class Overlay extends AbstractPureComponent<OverlayProps, OverlayState> {
}

// 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,
})
) : (
<span className={Classes.OVERLAY_CONTENT} tabIndex={tabIndex}>
{child}
</span>
);
const decoratedChild = isReactElement(child) ? (
React.cloneElement(child, { className: classNames(child.props.className, Classes.OVERLAY_CONTENT) })
) : (
<span className={Classes.OVERLAY_CONTENT}>{child}</span>
);

const { onOpening, onOpened, onClosing, transitionDuration, transitionName } = this.props;

Expand Down
3 changes: 0 additions & 3 deletions packages/core/src/components/overlay2/overlay2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ export const Overlay2 = React.forwardRef<OverlayInstance, Overlay2Props>((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;

Expand All @@ -416,8 +415,6 @@ export const Overlay2 = React.forwardRef<OverlayInstance, Overlay2Props>((props,
);
},
[
autoFocus,
enforceFocus,
getUserChildRef,
handleTransitionAddEnd,
handleTransitionExited,
Expand Down