Skip to content

Commit 2a38067

Browse files
feat(field,textfield): add container slot for custom background content
PiperOrigin-RevId: 673060991
1 parent a9ee4f5 commit 2a38067

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed

field/internal/_shared.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@
7272
pointer-events: none;
7373
}
7474

75+
slot[name='container'] {
76+
border-radius: inherit;
77+
}
78+
79+
slot[name='container']::slotted(*) {
80+
border-radius: inherit;
81+
inset: 0;
82+
pointer-events: none;
83+
position: absolute;
84+
}
85+
7586
@include content.styles;
7687
@include label.styles;
7788
@include supporting-text.styles;

field/internal/field.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ export class Field extends LitElement {
132132
return html`
133133
<div class="field ${classMap(classes)}">
134134
<div class="container-overflow">
135-
${this.renderBackground?.()} ${this.renderIndicator?.()} ${outline}
135+
${this.renderBackground?.()}
136+
<slot name="container"></slot>
137+
${this.renderStateLayer?.()} ${this.renderIndicator?.()} ${outline}
136138
<div class="container">
137139
<div class="start">
138140
<slot name="start"></slot>
@@ -181,6 +183,7 @@ export class Field extends LitElement {
181183
}
182184

183185
protected renderBackground?(): TemplateResult;
186+
protected renderStateLayer?(): TemplateResult;
184187
protected renderIndicator?(): TemplateResult;
185188
protected renderOutline?(floatingLabel: unknown): TemplateResult;
186189

field/internal/filled-field.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ import {Field} from './field.js';
1313
*/
1414
export class FilledField extends Field {
1515
protected override renderBackground() {
16-
return html`
17-
<div class="background"></div>
18-
<div class="state-layer"></div>
19-
`;
16+
return html` <div class="background"></div> `;
17+
}
18+
19+
protected override renderStateLayer() {
20+
return html` <div class="state-layer"></div> `;
2021
}
2122

2223
protected override renderIndicator() {

textfield/internal/_shared.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
resize: inherit;
4545
}
4646

47+
slot[name='container'] {
48+
border-radius: inherit;
49+
}
50+
4751
@include icon.styles;
4852
@include input.styles;
4953
}

textfield/internal/text-field.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ export abstract class TextField extends textFieldBaseClass {
569569
${this.renderInputOrTextarea()}
570570
${this.renderTrailingIcon()}
571571
<div id="description" slot="aria-describedby"></div>
572+
<slot name="container" slot="container"></slot>
572573
</${this.fieldTag}>`;
573574
}
574575

0 commit comments

Comments
 (0)