Skip to content

Commit bc23ca8

Browse files
authored
feat(popover,hovercard): DP-175404 support externalAnchorElement (#1108)
1 parent d2be0fa commit bc23ca8

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

packages/dialtone-vue/components/hovercard/hovercard.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
:header-class="headerClass"
1717
:footer-class="footerClass"
1818
:append-to="appendTo"
19+
:external-anchor-element="externalAnchorElement"
1920
data-qa="dt-hovercard"
2021
:enter-delay="enterDelay"
2122
:leave-delay="leaveDelay"
@@ -203,6 +204,15 @@ const props = defineProps({
203204
type: Number,
204205
default: TOOLTIP_DELAY_MS,
205206
},
207+
208+
/**
209+
* External anchor element reference. Use this instead of the anchor slot when
210+
* the anchor may be inside a Shadow DOM, as querySelector cannot pierce shadow boundaries.
211+
*/
212+
externalAnchorElement: {
213+
type: HTMLElement,
214+
default: null,
215+
},
206216
});
207217
208218
defineEmits([

packages/dialtone-vue/components/popover/popover.vue

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,22 @@ export default {
281281
/**
282282
* External anchor id to use in those cases the anchor can't be provided via the slot.
283283
* For instance, using the combobox's input as the anchor for the popover.
284+
* @deprecated Use externalAnchorElement instead for Shadow DOM compatibility.
284285
*/
285286
externalAnchor: {
286287
type: String,
287288
default: '',
288289
},
289290
291+
/**
292+
* External anchor element reference. Use this instead of externalAnchor when
293+
* the anchor may be inside a Shadow DOM, as querySelector cannot pierce shadow boundaries.
294+
*/
295+
externalAnchorElement: {
296+
type: HTMLElement,
297+
default: null,
298+
},
299+
290300
/**
291301
* The id of the tooltip
292302
*/
@@ -642,6 +652,10 @@ export default {
642652
});
643653
},
644654
655+
externalAnchorElement () {
656+
this.updateAnchorEl();
657+
},
658+
645659
placement (placement) {
646660
this.tip?.setProps({
647661
placement,
@@ -718,9 +732,10 @@ export default {
718732
},
719733
720734
updateAnchorEl () {
721-
const externalAnchorEl = this.externalAnchor
722-
? this.$refs.anchor.getRootNode().querySelector(`#${this.externalAnchor}`)
723-
: null;
735+
const externalAnchorEl = this.externalAnchorElement ||
736+
(this.externalAnchor
737+
? this.$refs.anchor.getRootNode().querySelector(`#${this.externalAnchor}`)
738+
: null);
724739
const anchorEl = externalAnchorEl ?? this.$refs.anchor.children[0];
725740
if (anchorEl === this.anchorEl) {
726741
return;

0 commit comments

Comments
 (0)