Skip to content

Commit 6c520b6

Browse files
committed
fix(NcEmojiPicker): return focus steals actual focus
Signed-off-by: Grigorii K. Shartsev <me@shgk.me> [skip ci]
1 parent 1ba43d7 commit 6c520b6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/components/NcEmojiPicker/NcEmojiPicker.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ This component allows the user to pick an emoji.
192192
</template>
193193

194194
<script>
195+
import { isFocusable } from 'tabbable'
195196
import { getCurrentSkinTone, setCurrentSkinTone } from '../../functions/emoji/emoji.ts'
196197
import { useTrapStackControl } from '../../composables/useTrapStackControl.ts'
197198
import { Color } from '../../utils/GenColors.js'
@@ -407,7 +408,10 @@ export default {
407408
408409
afterHide() {
409410
// Manually return focus to the trigger button, as we disabled focus-trap
410-
this.$refs.popover.$el.querySelector('button, [role="button"]')?.focus()
411+
// But only if there is no focus target outside the picker, for example, input element that received focus by click closing the emoji picker
412+
if (!document.activeElement || this.$refs.picker.$el.contains(document.activeElement) || !isFocusable(document.activeElement)) {
413+
this.$refs.popover.$el.querySelector('button, [role="button"]')?.focus()
414+
}
411415
},
412416
413417
/**

0 commit comments

Comments
 (0)