Skip to content

Commit

Permalink
feat(field,textfield): add container slot for custom background con…
Browse files Browse the repository at this point in the history
…tent

PiperOrigin-RevId: 673417206
  • Loading branch information
material-web-copybara authored and copybara-github committed Sep 11, 2024
1 parent a9ee4f5 commit 44c13cd
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
11 changes: 11 additions & 0 deletions field/internal/_shared.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@
pointer-events: none;
}

slot[name='container'] {
border-radius: inherit;
}

slot[name='container']::slotted(*) {
border-radius: inherit;
inset: 0;
pointer-events: none;
position: absolute;
}

@include content.styles;
@include label.styles;
@include supporting-text.styles;
Expand Down
5 changes: 4 additions & 1 deletion field/internal/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ export class Field extends LitElement {
return html`
<div class="field ${classMap(classes)}">
<div class="container-overflow">
${this.renderBackground?.()} ${this.renderIndicator?.()} ${outline}
${this.renderBackground?.()}
<slot name="container"></slot>
${this.renderStateLayer?.()} ${this.renderIndicator?.()} ${outline}
<div class="container">
<div class="start">
<slot name="start"></slot>
Expand Down Expand Up @@ -181,6 +183,7 @@ export class Field extends LitElement {
}

protected renderBackground?(): TemplateResult;
protected renderStateLayer?(): TemplateResult;
protected renderIndicator?(): TemplateResult;
protected renderOutline?(floatingLabel: unknown): TemplateResult;

Expand Down
9 changes: 5 additions & 4 deletions field/internal/filled-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import {Field} from './field.js';
*/
export class FilledField extends Field {
protected override renderBackground() {
return html`
<div class="background"></div>
<div class="state-layer"></div>
`;
return html` <div class="background"></div> `;
}

protected override renderStateLayer() {
return html` <div class="state-layer"></div> `;
}

protected override renderIndicator() {
Expand Down
4 changes: 4 additions & 0 deletions textfield/internal/_shared.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
resize: inherit;
}

slot[name='container'] {
border-radius: inherit;
}

@include icon.styles;
@include input.styles;
}
1 change: 1 addition & 0 deletions textfield/internal/text-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ export abstract class TextField extends textFieldBaseClass {
${this.renderInputOrTextarea()}
${this.renderTrailingIcon()}
<div id="description" slot="aria-describedby"></div>
<slot name="container" slot="container"></slot>
</${this.fieldTag}>`;
}

Expand Down

0 comments on commit 44c13cd

Please sign in to comment.