Skip to content

Commit 99293d9

Browse files
crisbetommalerba
authored andcommitted
feat(select): add input for adding classes to the panel (#4629)
Adds the `panelClass` input, which allows consumers to set extra classes on a select's panel. Fixes #4485.
1 parent 508b141 commit 99293d9

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

src/lib/select/select.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
<ng-template cdk-connected-overlay [origin]="origin" [open]="panelOpen" hasBackdrop (backdropClick)="close()"
1717
backdropClass="cdk-overlay-transparent-backdrop" [positions]="_positions" [minWidth]="_triggerWidth"
1818
[offsetY]="_offsetY" (attach)="_onAttached()" (detach)="close()">
19-
<div class="mat-select-panel" [@transformPanel]="'showing'" (@transformPanel.done)="_onPanelDone()"
20-
(keydown)="_handlePanelKeydown($event)" [style.transformOrigin]="_transformOrigin"
21-
[class.mat-select-panel-done-animating]="_panelDoneAnimating" [ngClass]="'mat-' + color">
19+
<div class="mat-select-panel {{ 'mat-' + color }}" [ngClass]="panelClass" [@transformPanel]="'showing'"
20+
(@transformPanel.done)="_onPanelDone()" (keydown)="_handlePanelKeydown($event)"
21+
[style.transformOrigin]="_transformOrigin" [class.mat-select-panel-done-animating]="_panelDoneAnimating">
2222
<div class="mat-select-content" [@fadeInContent]="'showing'" (@fadeInContent.done)="_onFadeInDone()">
2323
<ng-content></ng-content>
2424
</div>

src/lib/select/select.spec.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,16 @@ describe('MdSelect', () => {
260260
expect(event.defaultPrevented).toBe(true);
261261
});
262262

263+
it('should be able to set extra classes on the panel', () => {
264+
trigger.click();
265+
fixture.detectChanges();
266+
267+
const panel = overlayContainerElement.querySelector('.mat-select-panel') as HTMLElement;
268+
269+
expect(panel.classList).toContain('custom-one');
270+
expect(panel.classList).toContain('custom-two');
271+
});
272+
263273
});
264274

265275
describe('selection logic', () => {
@@ -2142,7 +2152,8 @@ describe('MdSelect', () => {
21422152
template: `
21432153
<div [style.height.px]="heightAbove"></div>
21442154
<md-select placeholder="Food" [formControl]="control" [required]="isRequired"
2145-
[tabIndex]="tabIndexOverride" [aria-label]="ariaLabel" [aria-labelledby]="ariaLabelledby">
2155+
[tabIndex]="tabIndexOverride" [aria-label]="ariaLabel" [aria-labelledby]="ariaLabelledby"
2156+
[panelClass]="panelClass">
21462157
<md-option *ngFor="let food of foods" [value]="food.value" [disabled]="food.disabled">
21472158
{{ food.viewValue }}
21482159
</md-option>
@@ -2168,6 +2179,7 @@ class BasicSelect {
21682179
tabIndexOverride: number;
21692180
ariaLabel: string;
21702181
ariaLabelledby: string;
2182+
panelClass = ['custom-one', 'custom-two'];
21712183

21722184
@ViewChild(MdSelect) select: MdSelect;
21732185
@ViewChildren(MdOption) options: QueryList<MdOption>;

src/lib/select/select.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ export class MdSelect implements AfterContentInit, OnDestroy, OnInit, ControlVal
229229
/** All of the defined select options. */
230230
@ContentChildren(MdOption) options: QueryList<MdOption>;
231231

232+
/** Classes to be passed to the select panel. Supports the same syntax as `ngClass`. */
233+
@Input() panelClass: string|string[]|Set<string>|{[key: string]: any};
234+
232235
/** Placeholder to be shown if no value has been selected. */
233236
@Input()
234237
get placeholder() { return this._placeholder; }

0 commit comments

Comments
 (0)