Skip to content

Commit d8a5e6a

Browse files
[core] fix(Popover): apply aria attrs to child, not wrapper (#6604)
1 parent 6b63649 commit d8a5e6a

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

packages/core/src/components/popover/popover.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,6 @@ export class Popover<
373373
// Ensure target is focusable if relevant prop enabled
374374
const targetTabIndex = openOnTargetFocus && isHoverInteractionKind ? 0 : undefined;
375375
const ownTargetProps = {
376-
"aria-expanded": isOpen,
377-
"aria-haspopup":
378-
this.props.popupKind ??
379-
(this.props.interactionKind === PopoverInteractionKind.HOVER_TARGET_ONLY
380-
? undefined
381-
: ("true" as const)),
382376
// N.B. this.props.className is passed along to renderTarget even though the user would have access to it.
383377
// If, instead, renderTarget is undefined and the target is provided as a child, this.props.className is
384378
// applied to the generated target wrapper element.
@@ -390,6 +384,12 @@ export class Popover<
390384
ref,
391385
...targetEventHandlers,
392386
} satisfies React.HTMLProps<HTMLElement>;
387+
const childTargetProps = {
388+
"aria-expanded": isOpen,
389+
"aria-haspopup":
390+
this.props.popupKind ??
391+
(this.props.interactionKind === PopoverInteractionKind.HOVER_TARGET_ONLY ? undefined : true),
392+
} satisfies React.HTMLProps<HTMLElement>;
393393

394394
const targetModifierClasses = {
395395
// this class is mainly useful for Blueprint <Button> targets; we should only apply it for
@@ -404,6 +404,7 @@ export class Popover<
404404
if (renderTarget !== undefined) {
405405
target = renderTarget({
406406
...ownTargetProps,
407+
...childTargetProps,
407408
className: classNames(ownTargetProps.className, targetModifierClasses),
408409
// if the consumer renders a tooltip target, it's their responsibility to disable that tooltip
409410
// when *this* popover is open
@@ -418,6 +419,7 @@ export class Popover<
418419
}
419420

420421
const clonedTarget: JSX.Element = React.cloneElement(childTarget, {
422+
...childTargetProps,
421423
className: classNames(childTarget.props.className, targetModifierClasses),
422424
// force disable single Tooltip child when popover is open
423425
disabled: isOpen && Utils.isElementOfType(childTarget, Tooltip) ? true : childTarget.props.disabled,

packages/core/test/popover/popoverTests.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ describe("<Popover>", () => {
201201

202202
it("renders with aria-haspopup attr", () => {
203203
wrapper = renderPopover({ isOpen: true });
204-
assert.isTrue(wrapper.find("[aria-haspopup='true']").exists());
204+
assert.isTrue(wrapper.find("[aria-haspopup=true]").exists());
205205
});
206206

207207
it("sets aria-haspopup attr base on popupKind", () => {

0 commit comments

Comments
 (0)