-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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(Popover): fix autoFocus on target focus #6991
base: develop
Are you sure you want to change the base?
fix(Popover): fix autoFocus on target focus #6991
Conversation
Generate changelog in
|
acbe513
to
cd0115d
Compare
2e257b0
to
5f358d2
Compare
5f358d2
to
613911f
Compare
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tabIndex={0}
doesn't do anything because it's not on an interactive element. And autoFocus
brings focus to startFocusTrapElement
, not this element.
@@ -290,7 +283,7 @@ export class Overlay extends AbstractPureComponent<OverlayProps, OverlayState> { | |||
* the `startFocusTrapElement`), depending on whether the element losing focus is inside the | |||
* Overlay. | |||
*/ | |||
private handleStartFocusTrapElementFocus = (e: React.FocusEvent<HTMLDivElement>) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can cast relatedTarget
type using the 2nd param
@@ -408,7 +408,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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tabIndex={0}
doesn't do anything because it's not on an interactive element. And autoFocus
brings focus to startFocusTrapElement
, not this element.
// popover open. | ||
if ( | ||
e.relatedTarget !== this.popoverElement && | ||
!this.isElementInPopover(e.relatedTarget as HTMLElement) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main fix in this PR. Overlay2
brings focus to its startFocusTrapElement
upon autoFocus
, and this element is not within the popover element. It is just outside the popover element, within the overlay
element. So, use isElementInOverlay
instead of isElementInPopover
@ggdouglas Made some updates to this PR after finding another bug with this issue. |
Fixes autofocus to the
Overlay
.