@@ -472,6 +472,20 @@ export const MenuBarMixin = (superClass) =>
472472 } ) ;
473473 }
474474
475+ /**
476+ * Restores all buttons, the overflow button and the state attributes, so that
477+ * the measurement does not use the button margins of the previous state.
478+ *
479+ * @param {!Array<!HTMLElement> } buttons
480+ * @private
481+ */
482+ __restoreState ( buttons ) {
483+ this . __restoreButtons ( buttons ) ;
484+ this . __updateOverflow ( [ ] ) ;
485+ this . toggleAttribute ( 'has-single-button' , buttons . length === 1 ) ;
486+ this . __updateVisibleAttributes ( buttons ) ;
487+ }
488+
475489 /** @private */
476490 __restoreItem ( button , item ) {
477491 button . appendChild ( item ) ;
@@ -596,9 +610,7 @@ export const MenuBarMixin = (superClass) =>
596610 const buttons = this . _buttons . filter ( ( btn ) => btn !== overflow ) ;
597611 const oldOverflowCount = this . __getOverflowCount ( overflow ) ;
598612
599- // Reset all buttons in the menu bar and the overflow button
600- this . __restoreButtons ( buttons ) ;
601- this . __updateOverflow ( [ ] ) ;
613+ this . __restoreState ( buttons ) ;
602614
603615 // Hide any overflowing buttons and put them in the 'overflow' button
604616 this . __setOverflowItems ( buttons , overflow ) ;
@@ -627,6 +639,11 @@ export const MenuBarMixin = (superClass) =>
627639 this . _setTabindex ( visibleButtons [ visibleButtons . length - 1 ] , true ) ;
628640 }
629641
642+ this . __updateVisibleAttributes ( visibleButtons ) ;
643+ }
644+
645+ /** @private */
646+ __updateVisibleAttributes ( visibleButtons ) {
630647 visibleButtons . forEach ( ( btn , index ) => {
631648 btn . toggleAttribute ( 'first-visible' , index === 0 ) ;
632649 btn . toggleAttribute ( 'last-visible' , ! this . _hasOverflow && index === visibleButtons . length - 1 ) ;
0 commit comments