Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/components/NcPopover/NcPopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ options.themes[theme] = structuredClone(options.themes.dropdown)
* @typedef {import('focus-trap').FocusTargetValueOrFalse} FocusTargetValueOrFalse
* @typedef {FocusTargetValueOrFalse|() => FocusTargetValueOrFalse} SetReturnFocus
*/

export default {
name: 'NcPopover',

Expand Down Expand Up @@ -361,6 +362,15 @@ export default {
type: [Array, Object],
default: () => ['click'],
},

/**
* When there is no setReturnFocus, NcPopover will try to return focus to the trigger button.
* Use this prop to disable this behavior.
*/
noAutoReturnFocus: {
type: Boolean,
default: false,
},
},

emits: [
Expand Down Expand Up @@ -496,6 +506,14 @@ export default {
return this.$refs.popover?.$refs.popper?.$refs.reference
},

/**
* @return {HTMLElement|undefined}
*/
getPopoverTriggerButtonElement() {
const triggerContainer = this.getPopoverTriggerElement()
return triggerContainer && tabbable(triggerContainer)[0]
},

/**
* Add focus trap for accessibility.
*/
Expand All @@ -519,7 +537,7 @@ export default {
// Focus will be release when popover be hide
escapeDeactivates: false,
allowOutsideClick: true,
setReturnFocus: this.setReturnFocus,
setReturnFocus: this.setReturnFocus || (!this.noAutoReturnFocus && this.getPopoverTriggerButtonElement()),
trapStack: getTrapStack(),
fallBackFocus: el,
})
Expand Down