@@ -388,6 +388,71 @@ describe('DtPopover Tests', () => {
388388 } ) ;
389389 } ) ;
390390
391+ describe ( 'appendTo behavior' , ( ) => {
392+ describe ( 'when anchor is inside a <dialog> element and appendTo is "body"' , ( ) => {
393+ it ( 'should append the popover to the dialog element, not body' , async ( ) => {
394+ const dialogEl = document . createElement ( 'dialog' ) ;
395+ document . body . appendChild ( dialogEl ) ;
396+
397+ const localWrapper = mount ( DtPopover , {
398+ props : { ...baseProps , open : null } ,
399+ slots : { ...baseSlots } ,
400+ global : { stubs : { transition : false } } ,
401+ attachTo : dialogEl ,
402+ } ) ;
403+
404+ const btn = localWrapper . find ( '[data-qa="dt-button"]' ) ;
405+ await btn . trigger ( 'click' ) ;
406+
407+ expect ( localWrapper . vm . tip . popper . parentElement ) . toBe ( dialogEl ) ;
408+
409+ localWrapper . unmount ( ) ;
410+ document . body . removeChild ( dialogEl ) ;
411+ } ) ;
412+ } ) ;
413+
414+ describe ( 'when anchor is NOT inside a <dialog> element and appendTo is "body"' , ( ) => {
415+ it ( 'should append the popover to document.body' , async ( ) => {
416+ const localWrapper = mount ( DtPopover , {
417+ props : { ...baseProps , open : null } ,
418+ slots : { ...baseSlots } ,
419+ global : { stubs : { transition : false } } ,
420+ attachTo : document . body ,
421+ } ) ;
422+
423+ const btn = localWrapper . find ( '[data-qa="dt-button"]' ) ;
424+ await btn . trigger ( 'click' ) ;
425+
426+ expect ( localWrapper . vm . tip . popper . parentElement ) . toBe ( document . body ) ;
427+
428+ localWrapper . unmount ( ) ;
429+ } ) ;
430+ } ) ;
431+
432+ describe ( 'when anchor is inside a <dialog> but appendTo is explicitly set' , ( ) => {
433+ it ( 'should use the explicit appendTo target, bypassing dialog detection' , async ( ) => {
434+ const dialogEl = document . createElement ( 'dialog' ) ;
435+ document . body . appendChild ( dialogEl ) ;
436+
437+ const localWrapper = mount ( DtPopover , {
438+ props : { ...baseProps , open : null , appendTo : 'parent' } ,
439+ slots : { ...baseSlots } ,
440+ global : { stubs : { transition : false } } ,
441+ attachTo : dialogEl ,
442+ } ) ;
443+
444+ const btn = localWrapper . find ( '[data-qa="dt-button"]' ) ;
445+ await btn . trigger ( 'click' ) ;
446+
447+ // 'parent' means the popover container element, not the dialog
448+ expect ( localWrapper . vm . tip . popper . parentElement ) . not . toBe ( dialogEl ) ;
449+
450+ localWrapper . unmount ( ) ;
451+ document . body . removeChild ( dialogEl ) ;
452+ } ) ;
453+ } ) ;
454+ } ) ;
455+
391456 describe ( 'When anchor slot content changes' , ( ) => {
392457 it ( 'should attach the tippy instance to the new DOM node' , async ( ) => {
393458 const component = {
0 commit comments