Skip to content

Commit 13f3141

Browse files
committed
color docs
1 parent 915a2b7 commit 13f3141

File tree

6 files changed

+44
-8
lines changed

6 files changed

+44
-8
lines changed

src/demo-app/datepicker/datepicker-demo.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ <h2>Options</h2>
1414
</mat-form-field>
1515
</p>
1616
<p>
17-
<mat-form-field>
17+
<mat-form-field color="accent">
1818
<mat-label>Min date</mat-label>
1919
<input matInput [matDatepicker]="minDatePicker" [(ngModel)]="minDate"
2020
[disabled]="inputDisabled">
2121
<mat-datepicker-toggle matSuffix [for]="minDatePicker"></mat-datepicker-toggle>
2222
<mat-datepicker #minDatePicker [touchUi]="touch" [disabled]="datepickerDisabled"></mat-datepicker>
2323
</mat-form-field>
24-
<mat-form-field>
24+
<mat-form-field color="accent">
2525
<mat-label>Max date</mat-label>
2626
<input matInput [matDatepicker]="maxDatePicker" [(ngModel)]="maxDate"
2727
[disabled]="inputDisabled">
@@ -30,7 +30,7 @@ <h2>Options</h2>
3030
</mat-form-field>
3131
</p>
3232
<p>
33-
<mat-form-field>
33+
<mat-form-field color="accent">
3434
<mat-label>Start at date</mat-label>
3535
<input matInput [matDatepicker]="startAtPicker" [(ngModel)]="startAt"
3636
[disabled]="inputDisabled">

src/lib/datepicker/datepicker.md

+8
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ As with other types of `<input>`, the datepicker works with `@angular/forms` dir
9999

100100
<!-- example(datepicker-value) -->
101101

102+
### Changing the datepicker colors
103+
104+
The datepicker popup will automatically inherit the color palette (`primary`, `accent`, or `warn`)
105+
from the `mat-form-field` it is attached to. If you would like to specify a different palette for
106+
the popup you can do so by setting the `color` property on `mat-datepicker`.
107+
108+
<!-- example(datepicker-color) -->
109+
102110
### Date validation
103111

104112
There are three properties that add date validation to the datepicker input. The first two are the

src/lib/datepicker/datepicker.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,15 @@ export class MatDatepicker<D> implements OnDestroy, CanColor {
153153
@Input() startView: 'month' | 'year' = 'month';
154154

155155
/** Color palette to use on the datepicker's calendar. */
156-
@Input() color: ThemePalette;
156+
@Input()
157+
get color(): ThemePalette {
158+
return this._color ||
159+
(this._datepickerInput ? this._datepickerInput ._getThemePalette() : undefined);
160+
}
161+
set color(value: ThemePalette) {
162+
this._color = value;
163+
}
164+
_color: ThemePalette;
157165

158166
/**
159167
* Whether the calendar UI is in touch mode. In touch mode the calendar opens in a dialog rather
@@ -464,13 +472,10 @@ export class MatDatepicker<D> implements OnDestroy, CanColor {
464472

465473
/** Passes the current theme color along to the calendar overlay. */
466474
private _setColor(): void {
467-
const input = this._datepickerInput;
468-
const color = this.color || (input ? input._getThemePalette() : undefined);
469-
475+
const color = this.color;
470476
if (this._popupComponentRef) {
471477
this._popupComponentRef.instance.color = color;
472478
}
473-
474479
if (this._dialogRef) {
475480
this._dialogRef.componentInstance.color = color;
476481
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/** No CSS for this example */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<mat-form-field color="accent">
2+
<mat-label>Inherited calendar color</mat-label>
3+
<input matInput [matDatepicker]="picker1">
4+
<mat-datepicker-toggle matSuffix [for]="picker1"></mat-datepicker-toggle>
5+
<mat-datepicker #picker1></mat-datepicker>
6+
</mat-form-field>
7+
8+
<mat-form-field color="accent">
9+
<mat-label>Custom calendar color</mat-label>
10+
<input matInput [matDatepicker]="picker2">
11+
<mat-datepicker-toggle matSuffix [for]="picker2"></mat-datepicker-toggle>
12+
<mat-datepicker #picker2 color="primary"></mat-datepicker>
13+
</mat-form-field>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {Component} from '@angular/core';
2+
3+
/** @title Datepicker palette colors */
4+
@Component({
5+
selector: 'datepicker-color-example',
6+
templateUrl: 'datepicker-color-example.html',
7+
styleUrls: ['datepicker-color-example.css'],
8+
})
9+
export class DatepickerColorExample {}

0 commit comments

Comments
 (0)