Skip to content

Commit 8e12b3d

Browse files
authored
refactor(material/select): remove dependency on NgClass (#32776)
Drops the dependency on `NgClass` from the select component since we can achieve the same with class bindings.
1 parent 0870786 commit 8e12b3d

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

goldens/material/select/index.api.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ export class MatSelect implements AfterContentInit, OnChanges, OnDestroy, OnInit
274274
get focused(): boolean;
275275
_getAriaActiveDescendant(): string | null;
276276
_getPanelAriaLabelledby(): string | null;
277-
_getPanelTheme(): string;
278277
_handleKeydown(event: KeyboardEvent): void;
279278
protected _handleOverlayKeydown(event: KeyboardEvent): void;
280279
get hideSingleSelectionIndicator(): boolean;

src/material/select/select.html

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,24 @@
4343
[cdkConnectedOverlayUsePopover]="_popoverLocation"
4444
(detach)="close()"
4545
(backdropClick)="close()"
46-
(overlayKeydown)="_handleOverlayKeydown($event)"
47-
>
46+
(overlayKeydown)="_handleOverlayKeydown($event)">
47+
<!-- `mat-undefined` is weird, but we were using it internally -->
4848
<div
4949
#panel
5050
role="listbox"
5151
tabindex="-1"
52-
class="mat-mdc-select-panel mdc-menu-surface mdc-menu-surface--open {{ _getPanelTheme() }}"
52+
class="mat-mdc-select-panel mdc-menu-surface mdc-menu-surface--open"
53+
[class]="panelClass"
5354
[class.mat-select-panel-animations-enabled]="!_animationsDisabled"
55+
[class.mat-primary]="_parentFormField?.color === 'primary'"
56+
[class.mat-accent]="_parentFormField?.color === 'accent'"
57+
[class.mat-warn]="_parentFormField?.color === 'warn'"
58+
[class.mat-undefined]="!_parentFormField?.color"
5459
[attr.id]="id + '-panel'"
5560
[attr.aria-multiselectable]="multiple"
5661
[attr.aria-label]="ariaLabel || null"
5762
[attr.aria-labelledby]="_getPanelAriaLabelledby()"
58-
[ngClass]="panelClass"
59-
(keydown)="_handleKeydown($event)"
60-
>
63+
(keydown)="_handleKeydown($event)">
6164
<ng-content></ng-content>
6265
</div>
6366
</ng-template>

src/material/select/select.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ import {
9494
getMatSelectNonArrayValueError,
9595
getMatSelectNonFunctionValueError,
9696
} from './select-errors';
97-
import {NgClass} from '@angular/common';
9897

9998
/** Injection token that determines the scroll handling while a select is open. */
10099
export const MAT_SELECT_SCROLL_STRATEGY = new InjectionToken<() => ScrollStrategy>(
@@ -189,7 +188,7 @@ export class MatSelectChange<T = any> {
189188
{provide: MatFormFieldControl, useExisting: MatSelect},
190189
{provide: MAT_OPTION_PARENT_COMPONENT, useExisting: MatSelect},
191190
],
192-
imports: [CdkOverlayOrigin, CdkConnectedOverlay, NgClass],
191+
imports: [CdkOverlayOrigin, CdkConnectedOverlay],
193192
})
194193
export class MatSelect
195194
implements
@@ -711,6 +710,10 @@ export class MatSelect
711710
if (changes['typeaheadDebounceInterval'] && this._keyManager) {
712711
this._keyManager.withTypeAhead(this.typeaheadDebounceInterval);
713712
}
713+
714+
if (changes['panelClass'] && this.panelClass instanceof Set) {
715+
this.panelClass = Array.from(this.panelClass);
716+
}
714717
}
715718

716719
ngOnDestroy() {
@@ -1085,11 +1088,6 @@ export class MatSelect
10851088
}
10861089
}
10871090

1088-
/** Returns the theme to be used on the panel. */
1089-
_getPanelTheme(): string {
1090-
return this._parentFormField ? `mat-${this._parentFormField.color}` : '';
1091-
}
1092-
10931091
/** Whether the select has a value. */
10941092
get empty(): boolean {
10951093
return !this._selectionModel || this._selectionModel.isEmpty();

0 commit comments

Comments
 (0)