-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(datepicker): add aria-* attrs and keyboard bindings to datepicker input #3542
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
$mat-datepicker-trigger-icon-size: 24px !default; | ||
|
||
|
||
.mat-datepicker-trigger { | ||
display: inline-block; | ||
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24px" height="24px" viewBox="0 0 24 24" fill="currentColor"><path d="M0 0h24v24H0z" fill="none"/><path d="M19 3h-1V1h-2v2H8V1H6v2H5c-1.11 0-1.99.9-1.99 2L3 19c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V8h14v11zM7 10h5v5H7z"/></svg>') no-repeat; | ||
background-size: contain; | ||
height: $mat-datepicker-trigger-icon-size; | ||
width: $mat-datepicker-trigger-icon-size; | ||
vertical-align: middle; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {ChangeDetectionStrategy, Component, Input, ViewEncapsulation} from '@angular/core'; | ||
import {MdDatepicker} from './datepicker'; | ||
|
||
|
||
@Component({ | ||
moduleId: module.id, | ||
selector: 'md-datepicker-trigger, mat-datepicker-trigger', | ||
template: '', | ||
styleUrls: ['datepicker-trigger.css'], | ||
host: { | ||
'[class.mat-datepicker-trigger]': 'true', | ||
'(click)': '_open($event)', | ||
}, | ||
encapsulation: ViewEncapsulation.None, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class MdDatepickerTrigger { | ||
@Input('for') datepicker: MdDatepicker; | ||
|
||
_open(event: Event): void { | ||
if (this.datepicker) { | ||
this.datepicker.open(); | ||
event.stopPropagation(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,9 @@ import {MdDatepickerInput} from './datepicker-input'; | |
import {CalendarLocale} from '../core/datetime/calendar-locale'; | ||
|
||
|
||
let datepickerUid = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add comment about what this is? We should also probably prefix with an underscore to be consistent with other counters. |
||
|
||
|
||
/** Component responsible for managing the datepicker popup/dialog. */ | ||
@Component({ | ||
moduleId: module.id, | ||
|
@@ -62,6 +65,10 @@ export class MdDatepicker implements OnDestroy { | |
|
||
@Output() selectedChanged = new EventEmitter<SimpleDate>(); | ||
|
||
opened = false; | ||
|
||
id = `md-datepicker-${datepickerUid++}`; | ||
|
||
get _selected(): SimpleDate { | ||
return this._datepickerInput ? this._datepickerInput.value : null; | ||
} | ||
|
@@ -112,6 +119,9 @@ export class MdDatepicker implements OnDestroy { | |
* @param touchUi Whether to use the touch UI. | ||
*/ | ||
open(): void { | ||
if (this.opened) { | ||
return; | ||
} | ||
if (!this._datepickerInput) { | ||
throw new MdError('Attempted to open an MdDatepicker with no associated input.'); | ||
} | ||
|
@@ -121,10 +131,14 @@ export class MdDatepicker implements OnDestroy { | |
} | ||
|
||
this.touchUi ? this._openAsDialog() : this._openAsPopup(); | ||
this.opened = true; | ||
} | ||
|
||
/** Close the calendar. */ | ||
close(): void { | ||
if (!this.opened) { | ||
return; | ||
} | ||
if (this._popupRef && this._popupRef.hasAttached()) { | ||
this._popupRef.detach(); | ||
} | ||
|
@@ -135,6 +149,7 @@ export class MdDatepicker implements OnDestroy { | |
if (this._calendarPortal && this._calendarPortal.isAttached) { | ||
this._calendarPortal.detach(); | ||
} | ||
this.opened = false; | ||
} | ||
|
||
/** Open the calendar as a dialog. */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -291,6 +291,8 @@ export class MdInputContainer implements AfterContentInit { | |
|
||
@ContentChildren(MdHint) _hintChildren: QueryList<MdHint>; | ||
|
||
@ViewChild('underline') _underlineRef: ElementRef; | ||
|
||
ngAfterContentInit() { | ||
if (!this._mdInputChild) { | ||
throw new MdInputContainerMissingMdInputError(); | ||
|
@@ -381,4 +383,8 @@ export class MdInputContainer implements AfterContentInit { | |
|
||
this._mdInputChild.ariaDescribedby = ids.join(' '); | ||
} | ||
|
||
getPopupConnectionElementRef(): ElementRef { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't we decide to remove this? |
||
return this._underlineRef; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we renamed this to
mdDatepickerToggle
? Rebase error?