Skip to content

Commit 394fd3f

Browse files
Adds wrapper nodes around slots as a polyfill styling accommodation and for compatibility with internal tooling.
PiperOrigin-RevId: 334150103
1 parent 72aa112 commit 394fd3f

File tree

6 files changed

+34
-9
lines changed

6 files changed

+34
-9
lines changed

packages/button/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ mwc-button {
124124
| `dense` | `boolean` | `false` | Makes the button text and container slightly smaller.
125125
| `disabled` | `boolean` | `false` | Disabled buttons cannot be interacted with and have no visual interaction effect.
126126
| `trailingIcon` | `boolean` | `false` | When `true`, `icon` will be displayed _after_ `label`.
127+
| 'expandContent' | `boolean` | `false` | When `true`, the space after the label and before any trailing icon, where default slotted content is rendered, is expanded to fit the available space inside the button.
127128

128129
### Methods
129130
*None*

packages/button/_button.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ limitations under the License.
7070
}
7171
}
7272

73+
.slot-container {
74+
display: inline-flex;
75+
align-items: center;
76+
justify-content: center;
77+
78+
&.flex {
79+
flex: auto;
80+
}
81+
}
82+
7383
$text-padding: custom-properties.create(
7484
--mdc-button-horizontal-padding,
7585
button-variables.$horizontal-padding

packages/button/mwc-button-base.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export class ButtonBase extends LitElement {
4242

4343
@property({type: String}) label = '';
4444

45+
@property({type: Boolean}) expandContent = false;
46+
4547
@query('#button') buttonElement!: HTMLElement;
4648

4749
@queryAsync('mwc-ripple') ripple!: Promise<Ripple|null>;
@@ -115,7 +117,11 @@ export class ButtonBase extends LitElement {
115117
</slot>
116118
</span>
117119
<span class="mdc-button__label">${this.label}</span>
118-
<slot></slot>
120+
<span class="slot-container ${classMap({
121+
flex: this.expandContent
122+
})}">
123+
<slot></slot>
124+
</span>
119125
<span class="trailing-icon">
120126
<slot name="trailingIcon">
121127
${this.icon && this.trailingIcon ? this.renderIcon() : ''}

packages/fab/_fab.scss

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,12 @@ $icon-size: map.get(fab-theme.$light-theme, icon-size);
9090
@extend %material-icons;
9191
}
9292

93+
.icon-slot-container {
94+
display: inline-flex;
95+
}
96+
9397
.mdc-fab__icon,
94-
::slotted([slot='icon']) {
98+
.icon-slot-container ::slotted([slot='icon']) {
9599
@include theme.property(
96100
width,
97101
custom-properties.create(--mdc-icon-size, $icon-size)
@@ -124,7 +128,7 @@ $icon-size: map.get(fab-theme.$light-theme, icon-size);
124128
$extended-label-padding
125129
);
126130

127-
::slotted([slot='icon']) {
131+
.icon-slot-container ::slotted([slot='icon']) {
128132
@include fab-mixins.extended-icon-padding(
129133
$extended-icon-padding,
130134
$extended-label-padding
@@ -140,7 +144,7 @@ $icon-size: map.get(fab-theme.$light-theme, icon-size);
140144
);
141145
}
142146

143-
::slotted([slot='icon']) {
147+
.icon-slot-container ::slotted([slot='icon']) {
144148
@include fab-mixins.extended-icon-padding(
145149
$extended-icon-padding,
146150
$extended-label-padding,
@@ -150,7 +154,7 @@ $icon-size: map.get(fab-theme.$light-theme, icon-size);
150154
}
151155
}
152156

153-
&.mdc-fab--exited ::slotted([slot='icon']) {
157+
&.mdc-fab--exited .icon-slot-container ::slotted([slot='icon']) {
154158
transform: scale(0);
155159
transition: animation.exit-permanent(transform, 135ms);
156160
}

packages/fab/mwc-fab-base.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@ export class FabBase extends LitElement {
8585
${this.renderBeforeRipple()}
8686
${this.renderRipple()}
8787
${this.showIconAtEnd ? this.renderLabel() : ''}
88-
<slot name="icon">
89-
${this.renderIcon()}
90-
</slot>
88+
<span class="icon-slot-container">
89+
<slot name="icon">
90+
${this.renderIcon()}
91+
</slot>
92+
</span>
9193
${!this.showIconAtEnd ? this.renderLabel() : ''}
9294
${this.renderTouchTarget()}
9395
</button>`;

packages/icon-button/mwc-icon-button-base.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ export class IconButtonBase extends LitElement {
8181
@touchcancel="${this.handleRippleDeactivate}">
8282
${this.renderRipple()}
8383
<i class="material-icons">${this.icon}</i>
84-
<slot></slot>
84+
<span class="default-slot-container">
85+
<slot></slot>
86+
</span>
8587
</button>`;
8688
}
8789

0 commit comments

Comments
 (0)