Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 8 additions & 29 deletions src/lib/datepicker/datepicker.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
The datepicker allows users to enter a date either through text input, or by choosing a date from
the calendar. It is made up of several components and directives that work together:

<!-- TODO: INSERT OVERVIEW EXAMPLE HERE -->
<!-- example(datepicker-overview) -->

### Current state
Currently the datepicker is in the beginning stages and supports basic date selection functionality.
Expand Down Expand Up @@ -51,14 +51,7 @@ open to the month or year containing today's date. This behavior can be overridd
`startAt` property of `md-datepicker`. In this case the calendar will open to the month or year
containing the `startAt` date.

```ts
startDate = new Date(1990, 0, 1);
```

```html
...
<md-datepicker startView="year" [startAt]="startDate"></md-datepicker>
```
<!-- example(datepicker-start-view) -->

### Date validation
There are three properties that add date validation to the datepicker input. The first two are the
Expand All @@ -67,6 +60,8 @@ disable all dates on the calendar popup before or after the respective values an
from advancing the calendar past the `month` or `year` (depending on current view) containing the
`min` or `max` date.

<!-- example(datepicker-min-max) -->

The second way to add date validation is using the `mdDatepickerFilter` property of the datepicker
input. This property accepts a function of `<D> => boolean` (where `<D>` is the date type used by
the datepicker, see section on
Expand All @@ -77,16 +72,7 @@ difference between using `mdDatepickerFilter` vs using `min` or `max` is that fi
dates before or after a certain point, will not prevent the user from advancing the calendar past
that point.

```ts
myFilter = (d: Date) => d.getFullYear() > 2005
minDate = new Date(2000, 0, 1);
maxDate = new Date(2020, 11, 31);
```

```html
<input [mdDatepicker]="d" [mdDatepickerFilter]="myFilter" [min]="minDate" [max]="maxDate" ngModel>
<md-datepicker #d></md-datepicker>
```
<!-- example(datepicker-filter) -->

In this example the user can back past 2005, but all of the dates before then will be unselectable.
They will not be able to go further back in the calendar than 2000. If they manually type in a date
Expand All @@ -103,20 +89,13 @@ devices that don't have as much screen real estate and need bigger click targets
`md-datepicker` has a `touchUi` property that can be set to `true` in order to enable a more touch
friendly UI where the calendar opens in a large dialog.

<!-- example(datepicker-touch) -->

### Manually opening and closing the calendar
The calendar popup can be programmatically controlled using the `open` and `close` methods on the
`md-datepicker`. It also has an `opened` property that reflects the status of the popup.

```ts
@Component({...})
export class MyComponent implements AfterViewInit {
@ViewChild(MdDatepicker) dp: MdDatepicker<Date>;

ngAfterViewInit() {
dp.open();
}
}
```
<!-- example(datepicker-api) -->

### Internationalization
In order to support internationalization, the datepicker supports customization of the following
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/** No CSS for this example */
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<md-input-container class="example-full-width">
<input mdInput [mdDatepicker]="picker" placeholder="Choose a date">
</md-input-container>
<md-datepicker #picker></md-datepicker>
<button md-raised-button (click)="picker.open()">Open</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {Component} from '@angular/core';

@Component({
selector: 'datepicker-api-example',
templateUrl: 'datepicker-api-example.html',
styleUrls: ['datepicker-api-example.css'],
})
export class DatepickerApiExample {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/** No CSS for this example */
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<md-input-container class="example-full-width">
<input mdInput [mdDatepickerFilter]="myFilter" [mdDatepicker]="picker" placeholder="Choose a date">
<button mdSuffix [mdDatepickerToggle]="picker"></button>
</md-input-container>
<md-datepicker #picker></md-datepicker>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {Component} from '@angular/core';

@Component({
selector: 'datepicker-filter-example',
templateUrl: 'datepicker-filter-example.html',
styleUrls: ['datepicker-filter-example.css'],
})
export class DatepickerFilterExample {
myFilter = (d: Date): boolean => {
const day = d.getDay();
// Prevent Saturday and Sunday from being selected.
return day !== 0 && day !== 6;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/** No CSS for this example */
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<md-input-container class="example-full-width">
<input mdInput [min]="minDate" [max]="maxDate" [mdDatepicker]="picker" placeholder="Choose a date">
<button mdSuffix [mdDatepickerToggle]="picker"></button>
</md-input-container>
<md-datepicker #picker></md-datepicker>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {Component} from '@angular/core';

@Component({
selector: 'datepicker-min-max-example',
templateUrl: 'datepicker-min-max-example.html',
styleUrls: ['datepicker-min-max-example.css'],
})
export class DatepickerMinMaxExample {
minDate = new Date(2000, 0, 1);
maxDate = new Date(2020, 0, 1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/** No CSS for this example */
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<md-input-container>
<input mdInput [mdDatepicker]="picker" placeholder="Choose a date">
<button mdSuffix [mdDatepickerToggle]="picker"></button>
</md-input-container>
<md-datepicker #picker startView="year" [startAt]="startDate"></md-datepicker>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {Component} from '@angular/core';

@Component({
selector: 'datepicker-start-view-example',
templateUrl: 'datepicker-start-view-example.html',
styleUrls: ['datepicker-start-view-example.css'],
})
export class DatepickerStartViewExample {
startDate = new Date(1990, 0, 1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/** No CSS for this example */
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<md-input-container class="example-full-width">
<input mdInput [mdDatepicker]="picker" placeholder="Choose a date">
<button mdSuffix [mdDatepickerToggle]="picker"></button>
</md-input-container>
<md-datepicker touchUi="true" #picker></md-datepicker>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {Component} from '@angular/core';

@Component({
selector: 'datepicker-touch-example',
templateUrl: 'datepicker-touch-example.html',
styleUrls: ['datepicker-touch-example.css'],
})
export class DatepickerTouchExample {
}
16 changes: 16 additions & 0 deletions src/material-examples/example-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ import {InputErrorsExample} from './input-errors/input-errors-example';
import {InputFormExample} from './input-form/input-form-example';
import {InputPrefixSuffixExample} from './input-prefix-suffix/input-prefix-suffix-example';
import {InputHintExample} from './input-hint/input-hint-example';
import {DatepickerStartViewExample} from './datepicker-start-view/datepicker-start-view-example';
import {DatepickerMinMaxExample} from './datepicker-min-max/datepicker-min-max-example';
import {DatepickerFilterExample} from './datepicker-filter/datepicker-filter-example';
import {DatepickerTouchExample} from './datepicker-touch/datepicker-touch-example';
import {DatepickerApiExample} from './datepicker-api/datepicker-api-example';

import {
MdAutocompleteModule, MdButtonModule, MdButtonToggleModule, MdCardModule, MdCheckboxModule,
MdChipsModule, MdDatepickerModule, MdDialogModule, MdGridListModule, MdIconModule, MdInputModule,
Expand Down Expand Up @@ -114,6 +120,11 @@ export const EXAMPLE_COMPONENTS = {
'checkbox-configurable': {title: 'Configurable checkbox', component: CheckboxConfigurableExample},
'checkbox-overview': {title: 'Basic checkboxes', component: CheckboxOverviewExample},
'datepicker-overview': {title: 'Basic datepicker', component: DatepickerOverviewExample},
'datepicker-start-view': {title: 'Start View', component: DatepickerStartViewExample},
'datepicker-min-max': {title: 'Min/Max Validation', component: DatepickerMinMaxExample},
'datepicker-filter': {title: 'Filter Validation', component: DatepickerFilterExample},
'datepicker-touch': {title: 'Touch', component: DatepickerTouchExample},
'datepicker-api': {title: 'API', component: DatepickerApiExample},
'dialog-overview': {
title: 'Basic dialog',
component: DialogOverviewExample,
Expand Down Expand Up @@ -241,6 +252,11 @@ export const EXAMPLE_LIST = [
CheckboxConfigurableExample,
CheckboxOverviewExample,
DatepickerOverviewExample,
DatepickerStartViewExample,
DatepickerMinMaxExample,
DatepickerFilterExample,
DatepickerTouchExample,
DatepickerApiExample,
DialogOverviewExample,
DialogOverviewExampleDialog,
DialogResultExample,
Expand Down