@@ -110,19 +110,29 @@ export class Toolbar implements ComponentInterface {
110110 const slots = [ 'start' , 'end' , 'primary' , 'secondary' ] ;
111111 slots . forEach ( ( slot ) => {
112112 if ( this . el . classList . contains ( `has-${ slot } -content` ) ) {
113- const slotElement = this . el . shadowRoot ?. querySelector ( `slot[name="${ slot } "]` ) as HTMLElement | null ;
113+ const slotElement = this . el . shadowRoot ?. querySelector ( `slot[name="${ slot } "]` ) as HTMLSlotElement | null ;
114114 if ( slotElement ) {
115+ // Check if the slot contains an img or ion-img
116+ const assignedElements = slotElement . assignedElements ( { flatten : true } ) ;
117+ const hasImg = assignedElements . some ( ( el ) => {
118+ if ( el . tagName === 'IMG' || el . tagName === 'ION-IMG' ) {
119+ return true ;
120+ }
121+ // Check for nested images
122+ return el . querySelector ( 'img, ion-img' ) ;
123+ } ) ;
124+
115125 // Temporarily allow slot to size to content by setting flex-basis
116- // to 'auto'. This ensures that slotted content (like images) can
117- // render at their intrinsic width for measurement.
118- const { name } = slotPairs . find ( ( pair ) => pair . slots . includes ( slot ) ) ! ;
119- this . el . style . setProperty ( `--${ name } -size` , 'auto' ) ;
126+ // to 'auto'. This ensures that slotted images can render at their
127+ // intrinsic width for measurement.
128+ if ( hasImg ) {
129+ const { name } = slotPairs . find ( ( pair ) => pair . slots . includes ( slot ) ) ! ;
130+ this . el . style . setProperty ( `--${ name } -size` , 'auto' ) ;
131+ }
120132
121133 const width = slotElement . offsetWidth ;
122134
123- // Set the slot size variable to the measured width
124135 if ( width > 0 ) {
125- this . el . style . setProperty ( `--${ name } -size` , `${ width } px` ) ;
126136 slotWidths . set ( slot , width ) ;
127137 } else {
128138 allMeasurementsSuccessful = false ;
0 commit comments