Skip to content

Commit 77b05f7

Browse files
committed
feat(material/autocomplete): add option to enable inlined overlay
1 parent 2f3de91 commit 77b05f7

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

goldens/material/autocomplete/index.api.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, AfterViewIn
174174
// (undocumented)
175175
static ngAcceptInputType_autocompleteDisabled: unknown;
176176
// (undocumented)
177+
static ngAcceptInputType_overlayInlined: unknown;
178+
// (undocumented)
177179
ngAfterViewInit(): void;
178180
// (undocumented)
179181
ngOnChanges(changes: SimpleChanges): void;
@@ -183,6 +185,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, AfterViewIn
183185
_onTouched: () => void;
184186
openPanel(): void;
185187
readonly optionSelections: Observable<MatOptionSelectionChange>;
188+
overlayInlined: boolean;
186189
readonly _overlayPanelClass: string[];
187190
get panelClosingActions(): Observable<MatOptionSelectionChange | null>;
188191
get panelOpen(): boolean;
@@ -197,7 +200,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, AfterViewIn
197200
// (undocumented)
198201
writeValue(value: any): void;
199202
// (undocumented)
200-
static ɵdir: i0.ɵɵDirectiveDeclaration<MatAutocompleteTrigger, "input[matAutocomplete], textarea[matAutocomplete]", ["matAutocompleteTrigger"], { "autocomplete": { "alias": "matAutocomplete"; "required": false; }; "position": { "alias": "matAutocompletePosition"; "required": false; }; "connectedTo": { "alias": "matAutocompleteConnectedTo"; "required": false; }; "autocompleteAttribute": { "alias": "autocomplete"; "required": false; }; "autocompleteDisabled": { "alias": "matAutocompleteDisabled"; "required": false; }; }, {}, never, never, true, never>;
203+
static ɵdir: i0.ɵɵDirectiveDeclaration<MatAutocompleteTrigger, "input[matAutocomplete], textarea[matAutocomplete]", ["matAutocompleteTrigger"], { "autocomplete": { "alias": "matAutocomplete"; "required": false; }; "position": { "alias": "matAutocompletePosition"; "required": false; }; "overlayInlined": { "alias": "matAutocompleteOverlayInlined"; "required": false; }; "connectedTo": { "alias": "matAutocompleteConnectedTo"; "required": false; }; "autocompleteAttribute": { "alias": "autocomplete"; "required": false; }; "autocompleteDisabled": { "alias": "matAutocompleteDisabled"; "required": false; }; }, {}, never, never, true, never>;
201204
// (undocumented)
202205
static ɵfac: i0.ɵɵFactoryDeclaration<MatAutocompleteTrigger, never>;
203206
}

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)