Skip to content

Commit

Permalink
feat: restore focus to the popover target on overlay close (#7421)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored May 20, 2024
1 parent dc5c7e2 commit dd6c5b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/popover/src/vaadin-popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class Popover extends PopoverPositionMixin(
.horizontalAlign="${this.__computeHorizontalAlign(effectivePosition)}"
.verticalAlign="${this.__computeVerticalAlign(effectivePosition)}"
@opened-changed="${this.__onOpenedChanged}"
restore-focus-on-close
.restoreFocusNode="${this.target}"
@vaadin-overlay-escape-press="${this.__onEscapePress}"
@vaadin-overlay-outside-click="${this.__onOutsideClick}"
></vaadin-popover-overlay>
Expand Down
10 changes: 10 additions & 0 deletions packages/popover/test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ describe('popover', () => {
await nextUpdate(popover);
expect(overlay.positionTarget).to.eql(target);
});

it('should set target as overlay restoreFocusNode', async () => {
popover.target = target;
await nextUpdate(popover);
expect(overlay.restoreFocusNode).to.eql(target);
});
});

describe('for', () => {
Expand Down Expand Up @@ -146,6 +152,10 @@ describe('popover', () => {
await nextUpdate(popover);
expect(overlay.withBackdrop).to.be.false;
});

it('should set restoreFocusOnClose on the overlay to true', () => {
expect(overlay.restoreFocusOnClose).to.be.true;
});
});

describe('interactions', () => {
Expand Down

0 comments on commit dd6c5b0

Please sign in to comment.