File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed
core/src/components/toolbar Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change 7070// Ionic Toolbar Slot Placement
7171// --------------------------------------------------
7272// We're using the slots to force the main toolbar content to be
73- // cenetered in the toolbar. This is a bit of a hack but it works.
73+ // centered in the toolbar. This is a bit of a hack but it works.
7474// The main content is placed in the center and then JavaScript evaluates
7575// the sizes of the different slots and sets what size the pairs should be
7676// based on the larger one. We then use `flex-basis` to set the expected
7777// size of the slots and disable `flex-shrink` so that the smaller slot cannot
78- // shrink and throw off the center, we also diable flex-grow so that slots do
78+ // shrink and throw off the center, we also disable flex-grow so that slots do
7979// not grow more than they need. The slots are paired up so the mirroring slots
8080// always have the same size. That is, start and end are paired and primary
8181// and secondary are paired. All of this works together to force the main
Original file line number Diff line number Diff line change @@ -112,8 +112,17 @@ export class Toolbar implements ComponentInterface {
112112 if ( this . el . classList . contains ( `has-${ slot } -content` ) ) {
113113 const slotElement = this . el . shadowRoot ?. querySelector ( `slot[name="${ slot } "]` ) as HTMLElement | null ;
114114 if ( slotElement ) {
115+ // 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' ) ;
120+
115121 const width = slotElement . offsetWidth ;
122+
123+ // Set the slot size variable to the measured width
116124 if ( width > 0 ) {
125+ this . el . style . setProperty ( `--${ name } -size` , `${ width } px` ) ;
117126 slotWidths . set ( slot , width ) ;
118127 } else {
119128 allMeasurementsSuccessful = false ;
You can’t perform that action at this time.
0 commit comments