Skip to content

Commit 7824225

Browse files
committed
fix(material/timepicker): make it easier to style timepicker panel (#32711)
Adds a `panelClass` input to the timepicker so it's easier to style it. (cherry picked from commit 34bcffb)
1 parent 81b407d commit 7824225

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

goldens/material/timepicker/index.api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export class MatTimepicker<D> implements OnDestroy, MatOptionParentComponent {
5858
readonly options: InputSignal<readonly MatTimepickerOption<D>[] | null>;
5959
// (undocumented)
6060
protected _options: Signal<readonly MatOption<any>[]>;
61+
readonly panelClass: InputSignal<string | string[] | undefined>;
6162
readonly panelId: string;
6263
// (undocumented)
6364
protected _panelTemplate: Signal<TemplateRef<unknown>>;
@@ -67,7 +68,7 @@ export class MatTimepicker<D> implements OnDestroy, MatOptionParentComponent {
6768
// (undocumented)
6869
protected _timeOptions: readonly MatTimepickerOption<D>[];
6970
// (undocumented)
70-
static ɵcmp: i0.ɵɵComponentDeclaration<MatTimepicker<any>, "mat-timepicker", ["matTimepicker"], { "interval": { "alias": "interval"; "required": false; "isSignal": true; }; "options": { "alias": "options"; "required": false; "isSignal": true; }; "disableRipple": { "alias": "disableRipple"; "required": false; "isSignal": true; }; "ariaLabel": { "alias": "aria-label"; "required": false; "isSignal": true; }; "ariaLabelledby": { "alias": "aria-labelledby"; "required": false; "isSignal": true; }; }, { "selected": "selected"; "opened": "opened"; "closed": "closed"; }, never, never, true, never>;
71+
static ɵcmp: i0.ɵɵComponentDeclaration<MatTimepicker<any>, "mat-timepicker", ["matTimepicker"], { "interval": { "alias": "interval"; "required": false; "isSignal": true; }; "options": { "alias": "options"; "required": false; "isSignal": true; }; "disableRipple": { "alias": "disableRipple"; "required": false; "isSignal": true; }; "ariaLabel": { "alias": "aria-label"; "required": false; "isSignal": true; }; "ariaLabelledby": { "alias": "aria-labelledby"; "required": false; "isSignal": true; }; "panelClass": { "alias": "panelClass"; "required": false; "isSignal": true; }; }, { "selected": "selected"; "opened": "opened"; "closed": "closed"; }, never, never, true, never>;
7172
// (undocumented)
7273
static ɵfac: i0.ɵɵFactoryDeclaration<MatTimepicker<any>, never>;
7374
}

src/material/timepicker/timepicker.spec.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,17 @@ describe('MatTimepicker', () => {
904904
fixture.detectChanges();
905905
expect(input.hasAttribute('aria-activedescendant')).toBe(false);
906906
});
907+
908+
it('should be able to set classes on the panel', () => {
909+
const fixture = TestBed.createComponent(StandaloneTimepicker);
910+
fixture.componentInstance.panelClass.set(['foo', 'bar']);
911+
fixture.detectChanges();
912+
getInput(fixture).click();
913+
fixture.detectChanges();
914+
const classList = fixture.nativeElement.querySelector('.cdk-overlay-pane').classList;
915+
expect(classList).toContain('foo');
916+
expect(classList).toContain('bar');
917+
});
907918
});
908919

909920
describe('forms integration', () => {
@@ -1415,7 +1426,8 @@ describe('MatTimepicker', () => {
14151426
[interval]="interval()"
14161427
[options]="customOptions()"
14171428
[aria-label]="ariaLabel()"
1418-
[aria-labelledby]="ariaLabelledby()"/>
1429+
[aria-labelledby]="ariaLabelledby()"
1430+
[panelClass]="panelClass()"/>
14191431
<mat-timepicker-toggle
14201432
[for]="picker"
14211433
[aria-label]="toggleAriaLabel()"
@@ -1439,6 +1451,7 @@ class StandaloneTimepicker {
14391451
readonly toggleTabIndex = signal<number>(0);
14401452
readonly customOptions = signal<MatTimepickerOption<Date>[] | null>(null);
14411453
readonly openOnClick = signal(true);
1454+
readonly panelClass = signal<string[]>([]);
14421455
readonly openedSpy = jasmine.createSpy('opened');
14431456
readonly closedSpy = jasmine.createSpy('closed');
14441457
readonly selectedSpy = jasmine.createSpy('selected');

src/material/timepicker/timepicker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ export class MatTimepicker<D> implements OnDestroy, MatOptionParentComponent {
212212
/** Whether the timepicker is currently disabled. */
213213
readonly disabled: Signal<boolean> = computed(() => !!this._input()?.disabled());
214214

215+
/** Classes to be passed to the timepicker panel. */
216+
readonly panelClass = input<string | string[]>();
217+
215218
constructor() {
216219
if (typeof ngDevMode === 'undefined' || ngDevMode) {
217220
validateAdapter(this._dateAdapter, this._dateFormats);
@@ -383,6 +386,7 @@ export class MatTimepicker<D> implements OnDestroy, MatOptionParentComponent {
383386
direction: this._dir || 'ltr',
384387
hasBackdrop: false,
385388
disableAnimations: this._animationsDisabled,
389+
panelClass: this.panelClass(),
386390
});
387391

388392
this._overlayRef.detachments().subscribe(() => this.close());

0 commit comments

Comments
 (0)