Skip to content

Commit 79f271d

Browse files
committed
feat(material/autocomplete): add option to enable inlined overlay
1 parent ef63efe commit 79f271d

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/dev-app/autocomplete/autocomplete-demo.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#reactiveInput
1313
matInput
1414
[matAutocomplete]="reactiveAuto"
15+
[matAutocompleteOverlayInlined]="true"
1516
[formControl]="stateCtrl"
1617
(input)="reactiveStates = filterStates(reactiveInput.value)"
1718
(focus)="reactiveStates = filterStates(reactiveInput.value)">
@@ -71,7 +72,7 @@
7172
@if (true) {
7273
<mat-form-field [color]="templateStatesTheme">
7374
<mat-label>State</mat-label>
74-
<input matInput [matAutocomplete]="tdAuto" [(ngModel)]="currentState"
75+
<input matInput [matAutocomplete]="tdAuto" [matAutocompleteOverlayInlined]="true" [(ngModel)]="currentState"
7576
(ngModelChange)="tdStates = filterStates(currentState)" [disabled]="tdDisabled">
7677
<mat-autocomplete #tdAuto="matAutocomplete"
7778
[hideSingleSelectionIndicator]="templateHideSingleSelectionIndicator"
@@ -132,6 +133,7 @@
132133
<input
133134
matInput
134135
[matAutocomplete]="groupedAuto"
136+
[matAutocompleteOverlayInlined]="true"
135137
[(ngModel)]="currentGroupedState"
136138
(ngModelChange)="filteredGroupedStates = filterStateGroups(currentGroupedState)">
137139
</mat-form-field>

src/dev-app/autocomplete/autocomplete-demo.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,9 @@ export class AutocompleteDemo {
221221
<p>Choose a T-shirt size.</p>
222222
<mat-form-field>
223223
<mat-label>T-Shirt Size</mat-label>
224-
<input matInput [matAutocomplete]="tdAuto" [(ngModel)]="currentSize" name="size">
224+
<input
225+
matInput [matAutocomplete]="tdAuto" [matAutocompleteOverlayInlined]="true"
226+
[(ngModel)]="currentSize" name="size">
225227
<mat-autocomplete #tdAuto="matAutocomplete">
226228
@for (size of sizes; track size) {
227229
<mat-option [value]="size">{{size}}</mat-option>

src/material/autocomplete/autocomplete-trigger.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,12 @@ export class MatAutocompleteTrigger
224224
*/
225225
@Input('matAutocompletePosition') position: 'auto' | 'above' | 'below' = 'auto';
226226

227+
/**
228+
* Whether to inline the overlay, instead of using the global overlay container.
229+
*/
230+
@Input({alias: 'matAutocompleteOverlayInlined', transform: booleanAttribute})
231+
overlayInlined: boolean;
232+
227233
/**
228234
* Reference relative to which to position the autocomplete panel.
229235
* Defaults to the autocomplete trigger element.
@@ -894,6 +900,7 @@ export class MatAutocompleteTrigger
894900
backdropClass: this._defaults?.backdropClass || 'cdk-overlay-transparent-backdrop',
895901
panelClass: this._overlayPanelClass,
896902
disableAnimations: this._animationsDisabled,
903+
insertOverlayAfter: this.overlayInlined ? this._getConnectedElement() : undefined,
897904
});
898905
}
899906

0 commit comments

Comments
 (0)