Skip to content

Commit 2c4f4bf

Browse files
authored
fix(material/select): global option not disabling popover (angular#32610)
Fixes that disabling popovers globally wasn't doing so for `mat-select`. Relates to angular#32592 (comment).
1 parent 83e30e2 commit 2c4f4bf

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

goldens/material/paginator/index.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { Directionality } from '@angular/cdk/bidi';
2121
import { DoCheck } from '@angular/core';
2222
import { ElementRef } from '@angular/core';
2323
import { EventEmitter } from '@angular/core';
24+
import { FlexibleOverlayPopoverLocation } from '@angular/cdk/overlay';
2425
import { FocusableOption } from '@angular/cdk/a11y';
2526
import { FocusOrigin } from '@angular/cdk/a11y';
2627
import { FormGroupDirective } from '@angular/forms';

goldens/material/select/index.api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { ControlValueAccessor } from '@angular/forms';
2020
import { DoCheck } from '@angular/core';
2121
import { ElementRef } from '@angular/core';
2222
import { EventEmitter } from '@angular/core';
23+
import { FlexibleOverlayPopoverLocation } from '@angular/cdk/overlay';
2324
import { FocusableOption } from '@angular/cdk/a11y';
2425
import { FocusOrigin } from '@angular/cdk/a11y';
2526
import { FormGroupDirective } from '@angular/forms';
@@ -340,6 +341,8 @@ export class MatSelect implements AfterContentInit, OnChanges, OnDestroy, OnInit
340341
protected _parentFormField: MatFormField | null;
341342
get placeholder(): string;
342343
set placeholder(value: string);
344+
// (undocumented)
345+
protected _popoverLocation: FlexibleOverlayPopoverLocation | null;
343346
_positions: ConnectedPosition[];
344347
_preferredOverlayOrigin: CdkOverlayOrigin | ElementRef | undefined;
345348
registerOnChange(fn: (value: any) => void): void;

src/material/select/select.html

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
<div cdk-overlay-origin
2-
class="mat-mdc-select-trigger"
3-
(click)="open()"
4-
#fallbackOverlayOrigin="cdkOverlayOrigin"
5-
#trigger>
6-
1+
<div
2+
cdk-overlay-origin
3+
class="mat-mdc-select-trigger"
4+
(click)="open()"
5+
#fallbackOverlayOrigin="cdkOverlayOrigin"
6+
#trigger
7+
>
78
<div class="mat-mdc-select-value" [attr.id]="_valueId">
89
@if (empty) {
910
<span class="mat-mdc-select-placeholder mat-mdc-select-min-line">{{placeholder}}</span>
@@ -22,7 +23,7 @@
2223
<div class="mat-mdc-select-arrow">
2324
<!-- Use an inline SVG, because it works better than a CSS triangle in high contrast mode. -->
2425
<svg viewBox="0 0 24 24" width="24px" height="24px" focusable="false" aria-hidden="true">
25-
<path d="M7 10l5 5 5-5z"/>
26+
<path d="M7 10l5 5 5-5z" />
2627
</svg>
2728
</div>
2829
</div>
@@ -40,10 +41,11 @@
4041
[cdkConnectedOverlayPositions]="_positions"
4142
[cdkConnectedOverlayWidth]="_overlayWidth"
4243
[cdkConnectedOverlayFlexibleDimensions]="true"
43-
cdkConnectedOverlayUsePopover="inline"
44+
[cdkConnectedOverlayUsePopover]="_popoverLocation"
4445
(detach)="close()"
4546
(backdropClick)="close()"
46-
(overlayKeydown)="_handleOverlayKeydown($event)">
47+
(overlayKeydown)="_handleOverlayKeydown($event)"
48+
>
4749
<div
4850
#panel
4951
role="listbox"
@@ -55,7 +57,8 @@
5557
[attr.aria-label]="ariaLabel || null"
5658
[attr.aria-labelledby]="_getPanelAriaLabelledby()"
5759
[ngClass]="panelClass"
58-
(keydown)="_handleKeydown($event)">
60+
(keydown)="_handleKeydown($event)"
61+
>
5962
<ng-content></ng-content>
6063
</div>
6164
</ng-template>

src/material/select/select.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import {
3131
CdkOverlayOrigin,
3232
ConnectedPosition,
3333
createRepositionScrollStrategy,
34+
FlexibleOverlayPopoverLocation,
35+
OVERLAY_DEFAULT_CONFIG,
3436
ScrollStrategy,
3537
} from '@angular/cdk/overlay';
3638
import {ViewportRuler} from '@angular/cdk/scrolling';
@@ -210,6 +212,7 @@ export class MatSelect
210212
private _liveAnnouncer = inject(LiveAnnouncer);
211213
protected _defaultOptions = inject(MAT_SELECT_CONFIG, {optional: true});
212214
protected _animationsDisabled = _animationsDisabled();
215+
protected _popoverLocation: FlexibleOverlayPopoverLocation | null;
213216
private _initialized = new Subject();
214217
private _cleanupDetach: (() => void) | undefined;
215218

@@ -602,6 +605,7 @@ export class MatSelect
602605
const parentForm = inject(NgForm, {optional: true});
603606
const parentFormGroup = inject(FormGroupDirective, {optional: true});
604607
const tabIndex = inject(new HostAttributeToken('tabindex'), {optional: true});
608+
const defaultPopoverConfig = inject(OVERLAY_DEFAULT_CONFIG, {optional: true});
605609

606610
if (this.ngControl) {
607611
// Note: we provide the value accessor through here, instead of
@@ -622,8 +626,10 @@ export class MatSelect
622626
parentForm,
623627
this.stateChanges,
624628
);
629+
625630
this._scrollStrategy = this._scrollStrategyFactory();
626631
this.tabIndex = tabIndex == null ? 0 : parseInt(tabIndex) || 0;
632+
this._popoverLocation = defaultPopoverConfig?.usePopover === false ? null : 'inline';
627633

628634
// Force setter to be called in case id was not specified.
629635
this.id = this.id;

0 commit comments

Comments
 (0)