@@ -19,6 +19,7 @@ import {
1919 SpectrumElement ,
2020 TemplateResult ,
2121} from '@spectrum-web-components/base' ;
22+ import { reparentChildren } from '@spectrum-web-components/shared' ;
2223import { Color , Scale } from '@spectrum-web-components/theme' ;
2324import styles from './active-overlay.css.js' ;
2425import {
@@ -115,9 +116,7 @@ export class ActiveOverlay extends SpectrumElement {
115116 public overlayContentTip ?: HTMLElement ;
116117 public trigger ! : HTMLElement ;
117118
118- private placeholder ?: Comment ;
119119 private popper ?: Instance ;
120- private originalSlot ?: string ;
121120
122121 @property ( )
123122 public _state = stateTransition ( ) ;
@@ -155,6 +154,7 @@ export class ActiveOverlay extends SpectrumElement {
155154
156155 public tabbingAway = false ;
157156 private originalPlacement ?: Placement ;
157+ private restoreContent ?: ( ) => Element [ ] ;
158158
159159 /**
160160 * @prop Used by the popper library to indicate where the overlay was
@@ -361,68 +361,25 @@ export class ActiveOverlay extends SpectrumElement {
361361 }
362362
363363 private stealOverlayContent ( element : HTMLElement ) : void {
364- /* c8 ignore next */
365- if ( this . placeholder || ! element ) return ;
366- if ( ! this . placeholder ) {
367- this . placeholder = document . createComment (
368- 'placeholder for ' + element . nodeName
369- ) ;
370- }
371-
372- const parentElement = element . parentElement || element . getRootNode ( ) ;
373-
374- if ( parentElement ) {
375- parentElement . replaceChild ( this . placeholder , element ) ;
376- }
377-
378- this . overlayContent = element ;
379- this . originalSlot =
380- this . overlayContent . getAttribute ( 'slot' ) || undefined ;
381- this . overlayContent . setAttribute ( 'slot' , 'overlay' ) ;
382- this . appendChild ( this . overlayContent ) ;
383-
384- this . originalPlacement = this . overlayContent . getAttribute (
385- 'placement'
386- ) as Placement ;
387-
364+ this . originalPlacement = element . getAttribute ( 'placement' ) as Placement ;
365+ this . restoreContent = reparentChildren ( [ element ] , this ) ;
388366 this . stealOverlayContentResolver ( ) ;
389367 }
390368
391369 private willNotifyClosed = false ;
392370
393371 private returnOverlayContent ( ) : void {
394372 /* c8 ignore next */
395- if ( ! this . overlayContent ) return ;
373+ if ( ! this . restoreContent ) return ;
396374
397- if ( this . originalSlot ) {
398- this . overlayContent . setAttribute ( 'slot' , this . originalSlot ) ;
399- delete this . originalSlot ;
400- } else {
401- this . overlayContent . removeAttribute ( 'slot' ) ;
402- }
403-
404- if ( this . placeholder ) {
405- const parentElement =
406- this . placeholder . parentElement ||
407- this . placeholder . getRootNode ( ) ;
408- if ( parentElement ) {
409- parentElement . replaceChild (
410- this . overlayContent ,
411- this . placeholder
412- ) ;
413- this . willNotifyClosed = true ;
414- }
415- }
375+ const [ element ] = this . restoreContent ( ) ;
376+ this . restoreContent = undefined ;
377+ this . willNotifyClosed = true ;
416378
417379 if ( this . originalPlacement ) {
418- this . overlayContent . setAttribute (
419- 'placement' ,
420- this . originalPlacement
421- ) ;
380+ element . setAttribute ( 'placement' , this . originalPlacement ) ;
422381 delete this . originalPlacement ;
423382 }
424-
425- delete this . placeholder ;
426383 }
427384
428385 public async updateOverlayPosition ( ) : Promise < void > {
@@ -506,7 +463,7 @@ export class ActiveOverlay extends SpectrumElement {
506463 public render ( ) : TemplateResult {
507464 const content = html `
508465 < div id ="contents ">
509- < slot @slotchange =${ this . onSlotChange } name ="overlay" > </ slot >
466+ < slot @slotchange =${ this . onSlotChange } > </ slot >
510467 </ div >
511468 ` ;
512469 return this . hasTheme ? this . renderTheme ( content ) : content ;
0 commit comments