813
813
import NcButton from ' ../NcButton/index.js'
814
814
import NcPopover from ' ../NcPopover/index.js'
815
815
import GenRandomId from ' ../../utils/GenRandomId.js'
816
+ import { getTrapStack } from ' ../../utils/focusTrap.js'
816
817
import { t } from ' ../../l10n.js'
817
818
818
819
import Vue , { computed } from ' vue'
@@ -1009,6 +1010,7 @@ export default {
1009
1010
* @type {'menu'|'navigation'|'dialog'|'tooltip'|''}
1010
1011
*/
1011
1012
actionsMenuSemanticType: ' ' ,
1013
+ externalFocusTrapStack: [],
1012
1014
}
1013
1015
},
1014
1016
@@ -1035,6 +1037,10 @@ export default {
1035
1037
1036
1038
this .opened = state
1037
1039
},
1040
+
1041
+ opened () {
1042
+ this .intersectIntoCurrentFocusTrapStack ()
1043
+ },
1038
1044
},
1039
1045
1040
1046
methods: {
@@ -1048,6 +1054,33 @@ export default {
1048
1054
return action? .componentOptions ? .Ctor ? .extendOptions ? .name ?? action? .componentOptions ? .tag
1049
1055
},
1050
1056
1057
+ /**
1058
+ * When the component has its own focus trap, then it is managed by global trap stack by focus-trap.
1059
+ *
1060
+ * However if the component has no focus trap and is used inside another focus trap - there is an issue.
1061
+ * By default popover content is rendered in body or other container, which is likely outside the current focus trap containers.
1062
+ * It results in broken behavior from focus-trap.
1063
+ *
1064
+ * We need to pause all the focus traps for opening popover and then unpause them back after closing.
1065
+ */
1066
+ intersectIntoCurrentFocusTrapStack () {
1067
+ if (this .withFocusTrap ) {
1068
+ return
1069
+ }
1070
+
1071
+ if (this .opened ) {
1072
+ this .externalFocusTrapStack = [... getTrapStack ()]
1073
+ for (const trap of this .externalFocusTrapStack ) {
1074
+ trap .pause ()
1075
+ }
1076
+ } else {
1077
+ for (const trap of this .externalFocusTrapStack ) {
1078
+ trap .unpause ()
1079
+ }
1080
+ this .externalFocusTrapStack = []
1081
+ }
1082
+ },
1083
+
1051
1084
/**
1052
1085
* Do we have exactly one Action and
1053
1086
* is it allowed as a standalone element?
0 commit comments