Skip to content

fix(material/mdc-form-field): text-field should stretch based on host element #18778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions src/dev-app/mdc-input/mdc-input-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -637,23 +637,27 @@ <h3>&lt;textarea&gt; with bindable autosize </h3>
<mat-card class="demo-card demo-basic">
<mat-toolbar color="primary">Autocomplete</mat-toolbar>
<mat-card-content>
<mat-form-field class="demo-block">
<mat-label>Pick Number</mat-label>
<input type="text" aria-label="Number" matInput
[matAutocomplete]="autoComplete1">
<mat-autocomplete #autoComplete1="matAutocomplete">
<mat-option *ngFor="let option of options" [value]="option">{{option}}</mat-option>
</mat-autocomplete>
</mat-form-field>
<p>
<mat-form-field>
<mat-label>Pick Number</mat-label>
<input type="text" aria-label="Number" matInput
[matAutocomplete]="autoComplete1">
<mat-autocomplete #autoComplete1="matAutocomplete">
<mat-option *ngFor="let option of options" [value]="option">{{option}}</mat-option>
</mat-autocomplete>
</mat-form-field>
</p>

<mat-form-field appearance="outline" class="demo-block">
<mat-label>Pick Number</mat-label>
<input type="text" aria-label="Number" matInput
[matAutocomplete]="autoComplete2">
<mat-autocomplete #autoComplete2="matAutocomplete">
<mat-option *ngFor="let option of options" [value]="option">{{option}}</mat-option>
</mat-autocomplete>
</mat-form-field>
<p>
<mat-form-field appearance="outline">
<mat-label>Pick Number</mat-label>
<input type="text" aria-label="Number" matInput
[matAutocomplete]="autoComplete2">
<mat-autocomplete #autoComplete2="matAutocomplete">
<mat-option *ngFor="let option of options" [value]="option">{{option}}</mat-option>
</mat-autocomplete>
</mat-form-field>
</p>
</mat-card-content>
</mat-card>

Expand Down
6 changes: 6 additions & 0 deletions src/material-experimental/mdc-form-field/form-field.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
width: 100%;
}

// The MDC text-field should stretch to the width of the host `<mat-form-field>` element.
// This allows developers to control the width without needing custom CSS overrides.
.mat-mdc-text-field-wrapper {
width: 100%;
}

// Infix that contains the projected content (usually an input or a textarea). We ensure
// that the projected form-field control and content can stretch as needed, but we also
// apply a default infix width to make the form-field's look natural.
Expand Down