Skip to content
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

fix(NcPopover): emit after-show after focus-trap init to correctly return focus when content set focus initially (e.g. NcEmojiPicker) #6342

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
39 changes: 22 additions & 17 deletions src/components/NcPopover/NcPopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ import { createFocusTrap } from 'focus-trap'
import { getTrapStack } from '../../utils/focusTrap.js'
import NcPopoverTriggerProvider from './NcPopoverTriggerProvider.vue'

/**
* @typedef {import('focus-trap').FocusTargetValueOrFalse} FocusTargetValueOrFalse
* @typedef {FocusTargetValueOrFalse|() => FocusTargetValueOrFalse} SetReturnFocus
*/

export default {
name: 'NcPopover',

Expand Down Expand Up @@ -214,11 +219,11 @@ export default {
/**
* Set element to return focus to after focus trap deactivation
*
* @type {import('focus-trap').FocusTargetValueOrFalse}
* @type {SetReturnFocus}
*/
setReturnFocus: {
default: undefined,
type: [HTMLElement, SVGElement, String, Boolean],
type: [HTMLElement, SVGElement, String, Boolean, Function],
},
},

Expand Down Expand Up @@ -371,29 +376,29 @@ export default {
}
},

afterShow() {
async afterShow() {
this.removeFloatingVueAriaDescribedBy()

this.$nextTick(() => {
/**
* Triggered after the tooltip was visually displayed.
*
* This is different from the 'show' and 'apply-show' which
* run earlier than this where there is no guarantee that the
* tooltip is already visible and in the DOM.
*/
this.$emit('after-show')
this.useFocusTrap()
this.addEscapeStopPropagation()
})
await this.$nextTick()
await this.useFocusTrap()
this.addEscapeStopPropagation()

/**
* Triggered after the tooltip was visually displayed.
*
* This is different from the 'show' and 'apply-show' which
* run earlier than this where there is no guarantee that the
* tooltip is already visible and in the DOM.
*/
this.$emit('after-show')
},
afterHide() {
this.clearFocusTrap()
this.clearEscapeStopPropagation()
/**
* Triggered after the tooltip was visually hidden.
*/
this.$emit('after-hide')
this.clearFocusTrap()
this.clearEscapeStopPropagation()
},
},
}
Expand Down
Loading