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(Popover): fix autoFocus on target focus #6991

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

bvandercar-vt
Copy link
Contributor

@bvandercar-vt bvandercar-vt commented Sep 19, 2024

Fixes autofocus to the Overlay.

@changelog-app
Copy link

changelog-app bot commented Sep 19, 2024

Generate changelog in packages/core/changelog/@unreleased

What do the change types mean?
  • feature: A new feature of the service.
  • improvement: An incremental improvement in the functionality or operation of the service.
  • fix: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
  • break: Has the potential to break consumers of this service's API, inclusive of both Palantir services
    and external consumers of the service's API (e.g. customer-written software or integrations).
  • deprecation: Advertises the intention to remove service functionality without any change to the
    operation of the service itself.
  • manualTask: Requires the possibility of manual intervention (running a script, eyeballing configuration,
    performing database surgery, ...) at the time of upgrade for it to succeed.
  • migration: A fully automatic upgrade migration task with no engineer input required.

Note: only one type should be chosen.

How are new versions calculated?
  • ❗The break and manual task changelog types will result in a major release!
  • 🐛 The fix changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
  • ✨ All others will result in a minor version release.

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

DRAFT: remove overlay outer tabIndex

Check the box to generate changelog(s)

  • Generate changelog entry

@bvandercar-vt bvandercar-vt changed the title DRAFT: remove overlay outer tabIndex remove overlay outer tabIndex (DRAFT) Sep 19, 2024
@bvandercar-vt bvandercar-vt changed the title remove overlay outer tabIndex (DRAFT) remove overlay outer tabIndex Sep 19, 2024
@bvandercar-vt bvandercar-vt changed the title remove overlay outer tabIndex fix(Overlay,Overlay2): remove overlay outer tabIndex Sep 20, 2024
@bvandercar-vt bvandercar-vt force-pushed the bvandercar/fix-overlay-autoFocus branch from acbe513 to cd0115d Compare January 27, 2025 21:10
@bvandercar-vt bvandercar-vt changed the title fix(Overlay,Overlay2): remove overlay outer tabIndex fix(Popover): fix autoFocus on target focus Jan 27, 2025
@bvandercar-vt bvandercar-vt force-pushed the bvandercar/fix-overlay-autoFocus branch from 2e257b0 to 5f358d2 Compare January 27, 2025 21:26
@bvandercar-vt bvandercar-vt force-pushed the bvandercar/fix-overlay-autoFocus branch from 5f358d2 to 613911f Compare January 27, 2025 21:26
@@ -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;
Copy link
Contributor Author

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>) => {
Copy link
Contributor Author

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,
Copy link
Contributor Author

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)
Copy link
Contributor Author

@bvandercar-vt bvandercar-vt Jan 27, 2025

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

@bvandercar-vt
Copy link
Contributor Author

@ggdouglas Made some updates to this PR after finding another bug with this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant