@@ -247,6 +247,7 @@ class MasterDetailLayout extends ElementMixin(ThemableMixin(PolylitMixin(LitElem
247247 super . disconnectedCallback ( ) ;
248248 this . __resizeObserver . disconnect ( ) ;
249249 cancelAnimationFrame ( this . __resizeRaf ) ;
250+ this . __endTransition ( ) ;
250251 }
251252
252253 /** @private */
@@ -419,18 +420,7 @@ class MasterDetailLayout extends ElementMixin(ThemableMixin(PolylitMixin(LitElem
419420 return Promise . resolve ( ) ;
420421 }
421422
422- const hasDetail = ! ! currentDetail ;
423- const hasDetailPlaceholder = ! ! this . querySelector ( '[slot="detail-placeholder"]' ) ;
424- const hasOverflow = this . hasAttribute ( 'overlay' ) ;
425-
426- let transitionType ;
427- if ( ( hasDetail && element ) || ( hasDetailPlaceholder && ! hasOverflow ) ) {
428- transitionType = 'replace' ;
429- } else if ( hasDetail ) {
430- transitionType = 'remove' ;
431- } else {
432- transitionType = 'add' ;
433- }
423+ const transitionType = this . __getTransitionType ( currentDetail , element ) ;
434424
435425 return this . _startTransition ( transitionType , ( ) => {
436426 // Update the DOM
@@ -440,6 +430,34 @@ class MasterDetailLayout extends ElementMixin(ThemableMixin(PolylitMixin(LitElem
440430 } ) ;
441431 }
442432
433+ /**
434+ * Determines the transition type for a detail change.
435+ *
436+ * Returns 'replace' in two cases:
437+ * - Swapping one detail for another (standard replace).
438+ * - Swapping between placeholder and detail in split mode,
439+ * so the swap appears instant (replace has 0ms duration in split).
440+ * In overlay mode, placeholder doesn't participate in transitions,
441+ * so standard 'add'/'remove' are used instead.
442+ *
443+ * @param {Element | null } currentDetail
444+ * @param {Element | null } newDetail
445+ * @return {string }
446+ * @private
447+ */
448+ __getTransitionType ( currentDetail , newDetail ) {
449+ if ( currentDetail && newDetail ) {
450+ return 'replace' ;
451+ }
452+
453+ const hasPlaceholder = ! ! this . querySelector ( '[slot="detail-placeholder"]' ) ;
454+ if ( hasPlaceholder && ! this . hasAttribute ( 'overlay' ) ) {
455+ return 'replace' ;
456+ }
457+
458+ return currentDetail ? 'remove' : 'add' ;
459+ }
460+
443461 /**
444462 * Starts an animated transition for adding, replacing or removing the
445463 * detail area using the Web Animations API.
0 commit comments