Skip to content

Commit

Permalink
APP-18235 returnFocusToTrigger prop for popover (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sqrrl authored Nov 13, 2023
1 parent 8d4ce24 commit 89726d7
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 158 deletions.
7 changes: 7 additions & 0 deletions .changeset/spotty-ducks-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@getflip/swirl-components": minor
"@getflip/swirl-components-angular": minor
"@getflip/swirl-components-react": minor
---

Add "returnFocusToTrigger" prop to swirl-popover
2 changes: 1 addition & 1 deletion packages/swirl-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"remark-gfm": "^3.0.1",
"storybook": "^7.4.0",
"storybook-addon-themes": "^6.1.0",
"storybook-design-token": "^3.0.0-beta.3",
"storybook-design-token": "^3.0.0-beta.7",
"svgo": "^2.8.0",
"typescript": "^4.7.4",
"vite": "^3.2.7"
Expand Down
2 changes: 2 additions & 0 deletions packages/swirl-components/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,7 @@ export namespace Components {
"open": (triggerEl?: HTMLElement) => Promise<void>;
"placement"?: Placement;
"popoverId"?: string;
"returnFocusToTrigger"?: boolean;
"trigger"?: string | HTMLElement;
"triggerContainer"?: HTMLElement;
"useContainerWidth"?: boolean | string;
Expand Down Expand Up @@ -5148,6 +5149,7 @@ declare namespace LocalJSX {
"onPopoverOpen"?: (event: SwirlPopoverCustomEvent<{ position: ComputePositionReturn }>) => void;
"placement"?: Placement;
"popoverId"?: string;
"returnFocusToTrigger"?: boolean;
"trigger"?: string | HTMLElement;
"triggerContainer"?: HTMLElement;
"useContainerWidth"?: boolean | string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export default {
type: "number",
},
},
returnFocusToTrigger: {
description:
"By default, the focus is returned to the trigger element when the popover is closed. Pass false to disable this behavior.",
},
trigger: {
description:
"**Deprecated! Please use the swirl-popover-trigger component instead.** ID of the trigger element or the trigger DOM element.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class SwirlPopover {
@Prop() offset?: number | number[] = 8;
@Prop() popoverId?: string;
@Prop() placement?: Placement = "bottom-start";
@Prop() returnFocusToTrigger?: boolean = true;
@Prop() trigger?: string | HTMLElement;
@Prop() triggerContainer?: HTMLElement;
@Prop() useContainerWidth?: boolean | string;
Expand Down Expand Up @@ -164,7 +165,10 @@ export class SwirlPopover {
}, 150);

this.unlockBodyScroll();
this.getNativeTriggerElement()?.focus();

if (this.returnFocusToTrigger) {
this.getNativeTriggerElement()?.focus();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const Template = (args) => {
popover.animation = "scale-in-y";
popover.label = "Options";
popover.placement = "bottom-end";
popover.returnFocusToTrigger = false;

popover.innerHTML = `
<swirl-action-list>
Expand Down
4 changes: 4 additions & 0 deletions packages/swirl-components/vscode-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -5022,6 +5022,10 @@
"name": "popover-id",
"description": ""
},
{
"name": "return-focus-to-trigger",
"description": ""
},
{
"name": "trigger",
"description": ""
Expand Down
162 changes: 6 additions & 156 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit 89726d7

Please sign in to comment.