-
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
Do not set tabIndex
when no popover will show
#6851
Conversation
Make popover targets not tabble when disabledBuild artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job. |
c26173f
to
ced45fd
Compare
Make popover targets not tabble when disabledBuild artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job. |
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.
Thank you for the PR!
This is looking good, I've encountered this issue in the wild and believe I've done annoying things like optionally wrap Tooltip
when not disabled to avoid this. Let's just get the empty check cleaned up to support the trim
case then I think this should be ready to merge.
for good measure I also tested
disabling tooltip (popover) shouldn't override already focusable target element
<Tooltip
disabled={true}
content="tooltip!"
intent="danger"
placement="right"
>
<Button onClick={() => console.log("hello world")}>I should still be focusable</Button>
</Tooltip>
keeps existing tabIndex
<Tooltip
disabled={true}
content="tooltip!"
intent="danger"
placement="right"
>
<div tabIndex={0}>target text, not sure why anyone would define tabIndex here but...</div>
</Tooltip>
and in the renderTarget
case the consumer is fully responsible for rendering anyways - if they accept our "recommended" tabIndex
, they'll get this new behavior, otherwise they can always do whatever they want.
@@ -375,7 +375,8 @@ export class Popover< | |||
onKeyDown: this.handleKeyDown, | |||
}; | |||
// Ensure target is focusable if relevant prop enabled | |||
const targetTabIndex = openOnTargetFocus && isHoverInteractionKind ? 0 : undefined; | |||
const targetTabIndex = | |||
content != null && !disabled && openOnTargetFocus && isHoverInteractionKind ? 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.
could you split out and reuse this check?
const isContentEmpty = content == null || (typeof content === "string" && content.trim() === "");
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.
Okay! I pulled that into a private class method. Let me know if you envisioned a different way to share it between renderTarget
and render
. Thanks for the review!
Move content emptiness check to private class functionBuild artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job. |
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.
thank you for the fix!
10e6464
to
52db8bc
Compare
Invalidated by push of 52db8bc
52db8bc
to
bbdc761
Compare
bbdc761
to
0b53277
Compare
Move content emptiness check to private class functionBuild artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job. |
Fixes no ticket
Checklist
Changes proposed in this pull request:
This PR makes
Popover
s not add atabIndex
to the target when thePopover
will not render due todisabled={true}
orcontent={undefined}
. This has been done by making sure that we do not overridetabIndex
on the popover target in those scenarios even ifopenOnTargetFocus
is also true.This is useful when rendering shared components that have conditional
Tooltips
implemented via thecontent
ordisabled
props. Before this change, those components would always be focusable.This PR does not address
Popover
s that are rendered in control mode and not open, though they exhibit similar behavior. This could be a follow-up change if desired.Popover -> Tooltip nesting
This PR is consistent with previous behavior regarding nesting a
Tooltip
in aPopover
.For context, default
Popover
s do not apply atabIndex=0
to their targets. This is becausePopover
s are by defaultPopoverInteractionKind.CLICK
, which does not meet the pre-requisite for gettingtabIndex=0
applied to the target ofPopoverInteractionKind.HOVER
.Previously, a
Popover
with a nestedTooltip
would always have a focusable target. Now, that will only be true if theTooltip
is both not disabled and has content.This behavior has been codified in the test suite.
Reviewers should focus on:
getButton
function of some sort?openOnTargetFocus
TSDoc?After
Screen.Recording.2024-06-18.at.11.30.09.AM.mov
Lines that are no longer focusable:
Lines that were never focusable:
Lines that are notably still focusable: