Skip to content

Commit c28cd09

Browse files
committed
docs(material/datepicker): show API docs for mat-calendar and add an … (#22794)
* docs(material/datepicker): show API docs for mat-calendar and add an example of an inline calendar * docs(material/datepicker): address feedback (cherry picked from commit 763b7eb)
1 parent 6927a8b commit c28cd09

File tree

7 files changed

+52
-19
lines changed

7 files changed

+52
-19
lines changed

src/components-examples/material/datepicker/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ng_module(
2020
"//src/cdk/testing/testbed",
2121
"//src/material-moment-adapter",
2222
"//src/material/button",
23+
"//src/material/card",
2324
"//src/material/core",
2425
"//src/material/datepicker",
2526
"//src/material/datepicker/testing",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.demo-inline-calendar-card {
2+
width: 300px;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<mat-card class="demo-inline-calendar-card">
2+
<mat-calendar (selectedChange)="selected = $event"></mat-calendar>
3+
</mat-card>
4+
<p>Selected date: {{selected}}</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {Component} from '@angular/core';
2+
3+
/** @title Datepicker inline calendar example */
4+
@Component({
5+
selector: 'datepicker-inline-calendar-example',
6+
templateUrl: 'datepicker-inline-calendar-example.html',
7+
styleUrls: ['datepicker-inline-calendar-example.css'],
8+
})
9+
export class DatepickerInlineCalendarExample {
10+
selected: Date | null;
11+
}

src/components-examples/material/datepicker/index.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
import {CommonModule} from '@angular/common';
22
import {NgModule} from '@angular/core';
3-
import {ReactiveFormsModule, FormsModule} from '@angular/forms';
3+
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
44
import {MatButtonModule} from '@angular/material/button';
5+
import {MatCardModule} from '@angular/material/card';
56
import {MatNativeDateModule} from '@angular/material/core';
67
import {MatDatepickerModule} from '@angular/material/datepicker';
78
import {MatIconModule} from '@angular/material/icon';
89
import {MatInputModule} from '@angular/material/input';
10+
import {
11+
DateRangePickerComparisonExample
12+
} from './date-range-picker-comparison/date-range-picker-comparison-example';
13+
import {
14+
DateRangePickerFormsExample
15+
} from './date-range-picker-forms/date-range-picker-forms-example';
16+
import {
17+
DateRangePickerOverviewExample
18+
} from './date-range-picker-overview/date-range-picker-overview-example';
19+
import {
20+
DateRangePickerSelectionStrategyExample
21+
} from './date-range-picker-selection-strategy/date-range-picker-selection-strategy-example';
22+
import {DatepickerActionsExample} from './datepicker-actions/datepicker-actions-example';
923

1024
import {DatepickerApiExample} from './datepicker-api/datepicker-api-example';
1125
import {DatepickerColorExample} from './datepicker-color/datepicker-color-example';
@@ -19,6 +33,10 @@ import {DatepickerDisabledExample} from './datepicker-disabled/datepicker-disabl
1933
import {DatepickerEventsExample} from './datepicker-events/datepicker-events-example';
2034
import {DatepickerFilterExample} from './datepicker-filter/datepicker-filter-example';
2135
import {DatepickerFormatsExample} from './datepicker-formats/datepicker-formats-example';
36+
import {DatepickerHarnessExample} from './datepicker-harness/datepicker-harness-example';
37+
import {
38+
DatepickerInlineCalendarExample
39+
} from './datepicker-inline-calendar/datepicker-inline-calendar-example';
2240
import {DatepickerLocaleExample} from './datepicker-locale/datepicker-locale-example';
2341
import {DatepickerMinMaxExample} from './datepicker-min-max/datepicker-min-max-example';
2442
import {DatepickerMomentExample} from './datepicker-moment/datepicker-moment-example';
@@ -29,20 +47,6 @@ import {DatepickerValueExample} from './datepicker-value/datepicker-value-exampl
2947
import {
3048
DatepickerViewsSelectionExample
3149
} from './datepicker-views-selection/datepicker-views-selection-example';
32-
import {
33-
DateRangePickerOverviewExample
34-
} from './date-range-picker-overview/date-range-picker-overview-example';
35-
import {
36-
DateRangePickerFormsExample
37-
} from './date-range-picker-forms/date-range-picker-forms-example';
38-
import {
39-
DateRangePickerComparisonExample
40-
} from './date-range-picker-comparison/date-range-picker-comparison-example';
41-
import {
42-
DateRangePickerSelectionStrategyExample
43-
} from './date-range-picker-selection-strategy/date-range-picker-selection-strategy-example';
44-
import {DatepickerHarnessExample} from './datepicker-harness/datepicker-harness-example';
45-
import {DatepickerActionsExample} from './datepicker-actions/datepicker-actions-example';
4650

4751
export {
4852
DatepickerApiExample,
@@ -55,6 +59,7 @@ export {
5559
DatepickerFilterExample,
5660
DatepickerFormatsExample,
5761
DatepickerHarnessExample,
62+
DatepickerInlineCalendarExample,
5863
DatepickerLocaleExample,
5964
DatepickerMinMaxExample,
6065
DatepickerMomentExample,
@@ -82,6 +87,7 @@ const EXAMPLES = [
8287
DatepickerFilterExample,
8388
DatepickerFormatsExample,
8489
DatepickerHarnessExample,
90+
DatepickerInlineCalendarExample,
8591
DatepickerLocaleExample,
8692
DatepickerMinMaxExample,
8793
DatepickerMomentExample,
@@ -102,6 +108,7 @@ const EXAMPLES = [
102108
imports: [
103109
CommonModule,
104110
MatButtonModule,
111+
MatCardModule,
105112
MatDatepickerModule,
106113
MatInputModule,
107114
MatIconModule,

src/material/datepicker/calendar.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,7 @@ export class MatCalendarHeader<D> {
175175
}
176176
}
177177

178-
/**
179-
* A calendar that is used as part of the datepicker.
180-
* @docs-private
181-
*/
178+
/** A calendar that is used as part of the datepicker. */
182179
@Component({
183180
selector: 'mat-calendar',
184181
templateUrl: 'calendar.html',
@@ -381,6 +378,7 @@ export class MatCalendar<D> implements AfterContentInit, AfterViewChecked, OnDes
381378
this.stateChanges.next();
382379
}
383380

381+
/** Focuses the active date. */
384382
focusActiveCell() {
385383
this._getCurrentViewComponent()._focusActiveCell(false);
386384
}

src/material/datepicker/datepicker.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,15 @@ The calendar popup can be programmatically controlled using the `open` and `clos
258258

259259
<!-- example(datepicker-api) -->
260260

261+
### Using `mat-calendar` inline
262+
263+
If you want to allow the user to select a date from a calendar that is inlined on the page rather
264+
than contained in a popup, you can use `<mat-calendar>` directly. The calendar's height is
265+
determined automatically based on the width and the number of dates that need to be shown for a
266+
month. If you want to make the calendar larger or smaller, adjust the width rather than the height.
267+
268+
<!-- example(datepicker-inline-calendar) -->
269+
261270
### Internationalization
262271

263272
Internationalization of the datepicker is configured via four aspects:

0 commit comments

Comments
 (0)