datepicker.es5.js 139 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722
  1. /**
  2. * @license
  3. * Copyright Google LLC All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. import { Injectable, NgModule, ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, forwardRef, Inject, Input, Optional, Output, ViewChild, ViewEncapsulation, ElementRef, NgZone, InjectionToken, ViewContainerRef, Directive, Attribute, ContentChild, ɵɵdefineInjectable } from '@angular/core';
  9. import { Subject, merge, Subscription, of } from 'rxjs';
  10. import { take, filter } from 'rxjs/operators';
  11. import { DOWN_ARROW, END, ENTER, HOME, LEFT_ARROW, PAGE_DOWN, PAGE_UP, RIGHT_ARROW, UP_ARROW, SPACE, ESCAPE } from '@angular/cdk/keycodes';
  12. import { DateAdapter, MAT_DATE_FORMATS, mixinColor } from '@angular/material/core';
  13. import { Directionality } from '@angular/cdk/bidi';
  14. import { ComponentPortal, PortalModule } from '@angular/cdk/portal';
  15. import { animate, state, style, transition, trigger } from '@angular/animations';
  16. import { __extends } from 'tslib';
  17. import { coerceBooleanProperty } from '@angular/cdk/coercion';
  18. import { Overlay, OverlayConfig, OverlayModule } from '@angular/cdk/overlay';
  19. import { DOCUMENT, CommonModule } from '@angular/common';
  20. import { MatDialog, MatDialogModule } from '@angular/material/dialog';
  21. import { NG_VALIDATORS, NG_VALUE_ACCESSOR, Validators } from '@angular/forms';
  22. import { MatFormField } from '@angular/material/form-field';
  23. import { MAT_INPUT_VALUE_ACCESSOR } from '@angular/material/input';
  24. import { MatButtonModule } from '@angular/material/button';
  25. import { A11yModule } from '@angular/cdk/a11y';
  26. /**
  27. * @fileoverview added by tsickle
  28. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  29. */
  30. /**
  31. * \@docs-private
  32. * @param {?} provider
  33. * @return {?}
  34. */
  35. function createMissingDateImplError(provider) {
  36. return Error("MatDatepicker: No provider found for " + provider + ". You must import one of the following " +
  37. "modules at your application root: MatNativeDateModule, MatMomentDateModule, or provide a " +
  38. "custom implementation.");
  39. }
  40. /**
  41. * @fileoverview added by tsickle
  42. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  43. */
  44. /**
  45. * Datepicker data that requires internationalization.
  46. */
  47. var MatDatepickerIntl = /** @class */ (function () {
  48. function MatDatepickerIntl() {
  49. /**
  50. * Stream that emits whenever the labels here are changed. Use this to notify
  51. * components if the labels have changed after initialization.
  52. */
  53. this.changes = new Subject();
  54. /**
  55. * A label for the calendar popup (used by screen readers).
  56. */
  57. this.calendarLabel = 'Calendar';
  58. /**
  59. * A label for the button used to open the calendar popup (used by screen readers).
  60. */
  61. this.openCalendarLabel = 'Open calendar';
  62. /**
  63. * A label for the previous month button (used by screen readers).
  64. */
  65. this.prevMonthLabel = 'Previous month';
  66. /**
  67. * A label for the next month button (used by screen readers).
  68. */
  69. this.nextMonthLabel = 'Next month';
  70. /**
  71. * A label for the previous year button (used by screen readers).
  72. */
  73. this.prevYearLabel = 'Previous year';
  74. /**
  75. * A label for the next year button (used by screen readers).
  76. */
  77. this.nextYearLabel = 'Next year';
  78. /**
  79. * A label for the previous multi-year button (used by screen readers).
  80. */
  81. this.prevMultiYearLabel = 'Previous 20 years';
  82. /**
  83. * A label for the next multi-year button (used by screen readers).
  84. */
  85. this.nextMultiYearLabel = 'Next 20 years';
  86. /**
  87. * A label for the 'switch to month view' button (used by screen readers).
  88. */
  89. this.switchToMonthViewLabel = 'Choose date';
  90. /**
  91. * A label for the 'switch to year view' button (used by screen readers).
  92. */
  93. this.switchToMultiYearViewLabel = 'Choose month and year';
  94. }
  95. MatDatepickerIntl.decorators = [
  96. { type: Injectable, args: [{ providedIn: 'root' },] },
  97. ];
  98. /** @nocollapse */ MatDatepickerIntl.ngInjectableDef = ɵɵdefineInjectable({ factory: function MatDatepickerIntl_Factory() { return new MatDatepickerIntl(); }, token: MatDatepickerIntl, providedIn: "root" });
  99. return MatDatepickerIntl;
  100. }());
  101. /**
  102. * @fileoverview added by tsickle
  103. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  104. */
  105. /**
  106. * An internal class that represents the data corresponding to a single calendar cell.
  107. * \@docs-private
  108. */
  109. var /**
  110. * An internal class that represents the data corresponding to a single calendar cell.
  111. * \@docs-private
  112. */
  113. MatCalendarCell = /** @class */ (function () {
  114. function MatCalendarCell(value, displayValue, ariaLabel, enabled, cssClasses) {
  115. this.value = value;
  116. this.displayValue = displayValue;
  117. this.ariaLabel = ariaLabel;
  118. this.enabled = enabled;
  119. this.cssClasses = cssClasses;
  120. }
  121. return MatCalendarCell;
  122. }());
  123. /**
  124. * An internal component used to display calendar data in a table.
  125. * \@docs-private
  126. */
  127. var MatCalendarBody = /** @class */ (function () {
  128. function MatCalendarBody(_elementRef, _ngZone) {
  129. this._elementRef = _elementRef;
  130. this._ngZone = _ngZone;
  131. /**
  132. * The number of columns in the table.
  133. */
  134. this.numCols = 7;
  135. /**
  136. * The cell number of the active cell in the table.
  137. */
  138. this.activeCell = 0;
  139. /**
  140. * The aspect ratio (width / height) to use for the cells in the table. This aspect ratio will be
  141. * maintained even as the table resizes.
  142. */
  143. this.cellAspectRatio = 1;
  144. /**
  145. * Emits when a new value is selected.
  146. */
  147. this.selectedValueChange = new EventEmitter();
  148. }
  149. /**
  150. * @param {?} cell
  151. * @return {?}
  152. */
  153. MatCalendarBody.prototype._cellClicked = /**
  154. * @param {?} cell
  155. * @return {?}
  156. */
  157. function (cell) {
  158. if (cell.enabled) {
  159. this.selectedValueChange.emit(cell.value);
  160. }
  161. };
  162. /**
  163. * @param {?} changes
  164. * @return {?}
  165. */
  166. MatCalendarBody.prototype.ngOnChanges = /**
  167. * @param {?} changes
  168. * @return {?}
  169. */
  170. function (changes) {
  171. /** @type {?} */
  172. var columnChanges = changes['numCols'];
  173. var _a = this, rows = _a.rows, numCols = _a.numCols;
  174. if (changes['rows'] || columnChanges) {
  175. this._firstRowOffset = rows && rows.length && rows[0].length ? numCols - rows[0].length : 0;
  176. }
  177. if (changes['cellAspectRatio'] || columnChanges || !this._cellPadding) {
  178. this._cellPadding = 50 * this.cellAspectRatio / numCols + "%";
  179. }
  180. if (columnChanges || !this._cellWidth) {
  181. this._cellWidth = 100 / numCols + "%";
  182. }
  183. };
  184. /**
  185. * @param {?} rowIndex
  186. * @param {?} colIndex
  187. * @return {?}
  188. */
  189. MatCalendarBody.prototype._isActiveCell = /**
  190. * @param {?} rowIndex
  191. * @param {?} colIndex
  192. * @return {?}
  193. */
  194. function (rowIndex, colIndex) {
  195. /** @type {?} */
  196. var cellNumber = rowIndex * this.numCols + colIndex;
  197. // Account for the fact that the first row may not have as many cells.
  198. if (rowIndex) {
  199. cellNumber -= this._firstRowOffset;
  200. }
  201. return cellNumber == this.activeCell;
  202. };
  203. /** Focuses the active cell after the microtask queue is empty. */
  204. /**
  205. * Focuses the active cell after the microtask queue is empty.
  206. * @return {?}
  207. */
  208. MatCalendarBody.prototype._focusActiveCell = /**
  209. * Focuses the active cell after the microtask queue is empty.
  210. * @return {?}
  211. */
  212. function () {
  213. var _this = this;
  214. this._ngZone.runOutsideAngular((/**
  215. * @return {?}
  216. */
  217. function () {
  218. _this._ngZone.onStable.asObservable().pipe(take(1)).subscribe((/**
  219. * @return {?}
  220. */
  221. function () {
  222. /** @type {?} */
  223. var activeCell = _this._elementRef.nativeElement.querySelector('.mat-calendar-body-active');
  224. if (activeCell) {
  225. activeCell.focus();
  226. }
  227. }));
  228. }));
  229. };
  230. MatCalendarBody.decorators = [
  231. { type: Component, args: [{selector: '[mat-calendar-body]',
  232. template: "<tr *ngIf=\"_firstRowOffset < labelMinRequiredCells\" aria-hidden=\"true\"><td class=\"mat-calendar-body-label\" [attr.colspan]=\"numCols\" [style.paddingTop]=\"_cellPadding\" [style.paddingBottom]=\"_cellPadding\">{{label}}</td></tr><tr *ngFor=\"let row of rows; let rowIndex = index\" role=\"row\"><td *ngIf=\"rowIndex === 0 && _firstRowOffset\" aria-hidden=\"true\" class=\"mat-calendar-body-label\" [attr.colspan]=\"_firstRowOffset\" [style.paddingTop]=\"_cellPadding\" [style.paddingBottom]=\"_cellPadding\">{{_firstRowOffset >= labelMinRequiredCells ? label : ''}}</td><td *ngFor=\"let item of row; let colIndex = index\" role=\"gridcell\" class=\"mat-calendar-body-cell\" [ngClass]=\"item.cssClasses\" [tabindex]=\"_isActiveCell(rowIndex, colIndex) ? 0 : -1\" [class.mat-calendar-body-disabled]=\"!item.enabled\" [class.mat-calendar-body-active]=\"_isActiveCell(rowIndex, colIndex)\" [attr.aria-label]=\"item.ariaLabel\" [attr.aria-disabled]=\"!item.enabled || null\" [attr.aria-selected]=\"selectedValue === item.value\" (click)=\"_cellClicked(item)\" [style.width]=\"_cellWidth\" [style.paddingTop]=\"_cellPadding\" role=\"button\" [style.paddingBottom]=\"_cellPadding\"><div class=\"mat-calendar-body-cell-content\" [class.mat-calendar-body-selected]=\"selectedValue === item.value\" [class.mat-calendar-body-today]=\"todayValue === item.value\">{{item.displayValue}}</div></td></tr>",
  233. styles: [".mat-calendar-body{min-width:224px}.mat-calendar-body-label{height:0;line-height:0;text-align:left;padding-left:4.71429%;padding-right:4.71429%}.mat-calendar-body-cell{position:relative;height:0;line-height:0;text-align:center;outline:0;cursor:pointer}.mat-calendar-body-disabled{cursor:default}.mat-calendar-body-cell-content{position:absolute;top:5%;left:5%;display:flex;align-items:center;justify-content:center;box-sizing:border-box;width:90%;height:90%;line-height:1;border-width:1px;border-style:solid;border-radius:999px}@media (-ms-high-contrast:active){.mat-calendar-body-cell-content{border:none}}@media (-ms-high-contrast:active){.mat-calendar-body-selected,.mat-datepicker-popup:not(:empty){outline:solid 1px}.mat-calendar-body-today{outline:dotted 1px}.cdk-keyboard-focused .mat-calendar-body-active>.mat-calendar-body-cell-content:not(.mat-calendar-body-selected),.cdk-program-focused .mat-calendar-body-active>.mat-calendar-body-cell-content:not(.mat-calendar-body-selected){outline:dotted 2px}}[dir=rtl] .mat-calendar-body-label{text-align:right}"],
  234. host: {
  235. 'class': 'mat-calendar-body',
  236. 'role': 'grid',
  237. 'aria-readonly': 'true'
  238. },
  239. exportAs: 'matCalendarBody',
  240. encapsulation: ViewEncapsulation.None,
  241. changeDetection: ChangeDetectionStrategy.OnPush,
  242. },] },
  243. ];
  244. /** @nocollapse */
  245. MatCalendarBody.ctorParameters = function () { return [
  246. { type: ElementRef },
  247. { type: NgZone }
  248. ]; };
  249. MatCalendarBody.propDecorators = {
  250. label: [{ type: Input }],
  251. rows: [{ type: Input }],
  252. todayValue: [{ type: Input }],
  253. selectedValue: [{ type: Input }],
  254. labelMinRequiredCells: [{ type: Input }],
  255. numCols: [{ type: Input }],
  256. activeCell: [{ type: Input }],
  257. cellAspectRatio: [{ type: Input }],
  258. selectedValueChange: [{ type: Output }]
  259. };
  260. return MatCalendarBody;
  261. }());
  262. /**
  263. * @fileoverview added by tsickle
  264. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  265. */
  266. /** @type {?} */
  267. var DAYS_PER_WEEK = 7;
  268. /**
  269. * An internal component used to display a single month in the datepicker.
  270. * \@docs-private
  271. * @template D
  272. */
  273. var MatMonthView = /** @class */ (function () {
  274. function MatMonthView(_changeDetectorRef, _dateFormats, _dateAdapter, _dir) {
  275. this._changeDetectorRef = _changeDetectorRef;
  276. this._dateFormats = _dateFormats;
  277. this._dateAdapter = _dateAdapter;
  278. this._dir = _dir;
  279. /**
  280. * Emits when a new date is selected.
  281. */
  282. this.selectedChange = new EventEmitter();
  283. /**
  284. * Emits when any date is selected.
  285. */
  286. this._userSelection = new EventEmitter();
  287. /**
  288. * Emits when any date is activated.
  289. */
  290. this.activeDateChange = new EventEmitter();
  291. if (!this._dateAdapter) {
  292. throw createMissingDateImplError('DateAdapter');
  293. }
  294. if (!this._dateFormats) {
  295. throw createMissingDateImplError('MAT_DATE_FORMATS');
  296. }
  297. this._activeDate = this._dateAdapter.today();
  298. }
  299. Object.defineProperty(MatMonthView.prototype, "activeDate", {
  300. /**
  301. * The date to display in this month view (everything other than the month and year is ignored).
  302. */
  303. get: /**
  304. * The date to display in this month view (everything other than the month and year is ignored).
  305. * @return {?}
  306. */
  307. function () { return this._activeDate; },
  308. set: /**
  309. * @param {?} value
  310. * @return {?}
  311. */
  312. function (value) {
  313. /** @type {?} */
  314. var oldActiveDate = this._activeDate;
  315. /** @type {?} */
  316. var validDate = this._getValidDateOrNull(this._dateAdapter.deserialize(value)) || this._dateAdapter.today();
  317. this._activeDate = this._dateAdapter.clampDate(validDate, this.minDate, this.maxDate);
  318. if (!this._hasSameMonthAndYear(oldActiveDate, this._activeDate)) {
  319. this._init();
  320. }
  321. },
  322. enumerable: true,
  323. configurable: true
  324. });
  325. Object.defineProperty(MatMonthView.prototype, "selected", {
  326. /** The currently selected date. */
  327. get: /**
  328. * The currently selected date.
  329. * @return {?}
  330. */
  331. function () { return this._selected; },
  332. set: /**
  333. * @param {?} value
  334. * @return {?}
  335. */
  336. function (value) {
  337. this._selected = this._getValidDateOrNull(this._dateAdapter.deserialize(value));
  338. this._selectedDate = this._getDateInCurrentMonth(this._selected);
  339. },
  340. enumerable: true,
  341. configurable: true
  342. });
  343. Object.defineProperty(MatMonthView.prototype, "minDate", {
  344. /** The minimum selectable date. */
  345. get: /**
  346. * The minimum selectable date.
  347. * @return {?}
  348. */
  349. function () { return this._minDate; },
  350. set: /**
  351. * @param {?} value
  352. * @return {?}
  353. */
  354. function (value) {
  355. this._minDate = this._getValidDateOrNull(this._dateAdapter.deserialize(value));
  356. },
  357. enumerable: true,
  358. configurable: true
  359. });
  360. Object.defineProperty(MatMonthView.prototype, "maxDate", {
  361. /** The maximum selectable date. */
  362. get: /**
  363. * The maximum selectable date.
  364. * @return {?}
  365. */
  366. function () { return this._maxDate; },
  367. set: /**
  368. * @param {?} value
  369. * @return {?}
  370. */
  371. function (value) {
  372. this._maxDate = this._getValidDateOrNull(this._dateAdapter.deserialize(value));
  373. },
  374. enumerable: true,
  375. configurable: true
  376. });
  377. /**
  378. * @return {?}
  379. */
  380. MatMonthView.prototype.ngAfterContentInit = /**
  381. * @return {?}
  382. */
  383. function () {
  384. this._init();
  385. };
  386. /** Handles when a new date is selected. */
  387. /**
  388. * Handles when a new date is selected.
  389. * @param {?} date
  390. * @return {?}
  391. */
  392. MatMonthView.prototype._dateSelected = /**
  393. * Handles when a new date is selected.
  394. * @param {?} date
  395. * @return {?}
  396. */
  397. function (date) {
  398. if (this._selectedDate != date) {
  399. /** @type {?} */
  400. var selectedYear = this._dateAdapter.getYear(this.activeDate);
  401. /** @type {?} */
  402. var selectedMonth = this._dateAdapter.getMonth(this.activeDate);
  403. /** @type {?} */
  404. var selectedDate = this._dateAdapter.createDate(selectedYear, selectedMonth, date);
  405. this.selectedChange.emit(selectedDate);
  406. }
  407. this._userSelection.emit();
  408. };
  409. /** Handles keydown events on the calendar body when calendar is in month view. */
  410. /**
  411. * Handles keydown events on the calendar body when calendar is in month view.
  412. * @param {?} event
  413. * @return {?}
  414. */
  415. MatMonthView.prototype._handleCalendarBodyKeydown = /**
  416. * Handles keydown events on the calendar body when calendar is in month view.
  417. * @param {?} event
  418. * @return {?}
  419. */
  420. function (event) {
  421. // TODO(mmalerba): We currently allow keyboard navigation to disabled dates, but just prevent
  422. // disabled ones from being selected. This may not be ideal, we should look into whether
  423. // navigation should skip over disabled dates, and if so, how to implement that efficiently.
  424. // TODO(mmalerba): We currently allow keyboard navigation to disabled dates, but just prevent
  425. // disabled ones from being selected. This may not be ideal, we should look into whether
  426. // navigation should skip over disabled dates, and if so, how to implement that efficiently.
  427. /** @type {?} */
  428. var oldActiveDate = this._activeDate;
  429. /** @type {?} */
  430. var isRtl = this._isRtl();
  431. switch (event.keyCode) {
  432. case LEFT_ARROW:
  433. this.activeDate = this._dateAdapter.addCalendarDays(this._activeDate, isRtl ? 1 : -1);
  434. break;
  435. case RIGHT_ARROW:
  436. this.activeDate = this._dateAdapter.addCalendarDays(this._activeDate, isRtl ? -1 : 1);
  437. break;
  438. case UP_ARROW:
  439. this.activeDate = this._dateAdapter.addCalendarDays(this._activeDate, -7);
  440. break;
  441. case DOWN_ARROW:
  442. this.activeDate = this._dateAdapter.addCalendarDays(this._activeDate, 7);
  443. break;
  444. case HOME:
  445. this.activeDate = this._dateAdapter.addCalendarDays(this._activeDate, 1 - this._dateAdapter.getDate(this._activeDate));
  446. break;
  447. case END:
  448. this.activeDate = this._dateAdapter.addCalendarDays(this._activeDate, (this._dateAdapter.getNumDaysInMonth(this._activeDate) -
  449. this._dateAdapter.getDate(this._activeDate)));
  450. break;
  451. case PAGE_UP:
  452. this.activeDate = event.altKey ?
  453. this._dateAdapter.addCalendarYears(this._activeDate, -1) :
  454. this._dateAdapter.addCalendarMonths(this._activeDate, -1);
  455. break;
  456. case PAGE_DOWN:
  457. this.activeDate = event.altKey ?
  458. this._dateAdapter.addCalendarYears(this._activeDate, 1) :
  459. this._dateAdapter.addCalendarMonths(this._activeDate, 1);
  460. break;
  461. case ENTER:
  462. case SPACE:
  463. if (!this.dateFilter || this.dateFilter(this._activeDate)) {
  464. this._dateSelected(this._dateAdapter.getDate(this._activeDate));
  465. this._userSelection.emit();
  466. // Prevent unexpected default actions such as form submission.
  467. event.preventDefault();
  468. }
  469. return;
  470. default:
  471. // Don't prevent default or focus active cell on keys that we don't explicitly handle.
  472. return;
  473. }
  474. if (this._dateAdapter.compareDate(oldActiveDate, this.activeDate)) {
  475. this.activeDateChange.emit(this.activeDate);
  476. }
  477. this._focusActiveCell();
  478. // Prevent unexpected default actions such as form submission.
  479. event.preventDefault();
  480. };
  481. /** Initializes this month view. */
  482. /**
  483. * Initializes this month view.
  484. * @return {?}
  485. */
  486. MatMonthView.prototype._init = /**
  487. * Initializes this month view.
  488. * @return {?}
  489. */
  490. function () {
  491. this._selectedDate = this._getDateInCurrentMonth(this.selected);
  492. this._todayDate = this._getDateInCurrentMonth(this._dateAdapter.today());
  493. this._monthLabel =
  494. this._dateAdapter.getMonthNames('short')[this._dateAdapter.getMonth(this.activeDate)]
  495. .toLocaleUpperCase();
  496. /** @type {?} */
  497. var firstOfMonth = this._dateAdapter.createDate(this._dateAdapter.getYear(this.activeDate), this._dateAdapter.getMonth(this.activeDate), 1);
  498. this._firstWeekOffset =
  499. (DAYS_PER_WEEK + this._dateAdapter.getDayOfWeek(firstOfMonth) -
  500. this._dateAdapter.getFirstDayOfWeek()) % DAYS_PER_WEEK;
  501. this._initWeekdays();
  502. this._createWeekCells();
  503. this._changeDetectorRef.markForCheck();
  504. };
  505. /** Focuses the active cell after the microtask queue is empty. */
  506. /**
  507. * Focuses the active cell after the microtask queue is empty.
  508. * @return {?}
  509. */
  510. MatMonthView.prototype._focusActiveCell = /**
  511. * Focuses the active cell after the microtask queue is empty.
  512. * @return {?}
  513. */
  514. function () {
  515. this._matCalendarBody._focusActiveCell();
  516. };
  517. /** Initializes the weekdays. */
  518. /**
  519. * Initializes the weekdays.
  520. * @private
  521. * @return {?}
  522. */
  523. MatMonthView.prototype._initWeekdays = /**
  524. * Initializes the weekdays.
  525. * @private
  526. * @return {?}
  527. */
  528. function () {
  529. /** @type {?} */
  530. var firstDayOfWeek = this._dateAdapter.getFirstDayOfWeek();
  531. /** @type {?} */
  532. var narrowWeekdays = this._dateAdapter.getDayOfWeekNames('narrow');
  533. /** @type {?} */
  534. var longWeekdays = this._dateAdapter.getDayOfWeekNames('long');
  535. // Rotate the labels for days of the week based on the configured first day of the week.
  536. /** @type {?} */
  537. var weekdays = longWeekdays.map((/**
  538. * @param {?} long
  539. * @param {?} i
  540. * @return {?}
  541. */
  542. function (long, i) {
  543. return { long: long, narrow: narrowWeekdays[i] };
  544. }));
  545. this._weekdays = weekdays.slice(firstDayOfWeek).concat(weekdays.slice(0, firstDayOfWeek));
  546. };
  547. /** Creates MatCalendarCells for the dates in this month. */
  548. /**
  549. * Creates MatCalendarCells for the dates in this month.
  550. * @private
  551. * @return {?}
  552. */
  553. MatMonthView.prototype._createWeekCells = /**
  554. * Creates MatCalendarCells for the dates in this month.
  555. * @private
  556. * @return {?}
  557. */
  558. function () {
  559. /** @type {?} */
  560. var daysInMonth = this._dateAdapter.getNumDaysInMonth(this.activeDate);
  561. /** @type {?} */
  562. var dateNames = this._dateAdapter.getDateNames();
  563. this._weeks = [[]];
  564. for (var i = 0, cell = this._firstWeekOffset; i < daysInMonth; i++, cell++) {
  565. if (cell == DAYS_PER_WEEK) {
  566. this._weeks.push([]);
  567. cell = 0;
  568. }
  569. /** @type {?} */
  570. var date = this._dateAdapter.createDate(this._dateAdapter.getYear(this.activeDate), this._dateAdapter.getMonth(this.activeDate), i + 1);
  571. /** @type {?} */
  572. var enabled = this._shouldEnableDate(date);
  573. /** @type {?} */
  574. var ariaLabel = this._dateAdapter.format(date, this._dateFormats.display.dateA11yLabel);
  575. /** @type {?} */
  576. var cellClasses = this.dateClass ? this.dateClass(date) : undefined;
  577. this._weeks[this._weeks.length - 1]
  578. .push(new MatCalendarCell(i + 1, dateNames[i], ariaLabel, enabled, cellClasses));
  579. }
  580. };
  581. /** Date filter for the month */
  582. /**
  583. * Date filter for the month
  584. * @private
  585. * @param {?} date
  586. * @return {?}
  587. */
  588. MatMonthView.prototype._shouldEnableDate = /**
  589. * Date filter for the month
  590. * @private
  591. * @param {?} date
  592. * @return {?}
  593. */
  594. function (date) {
  595. return !!date &&
  596. (!this.dateFilter || this.dateFilter(date)) &&
  597. (!this.minDate || this._dateAdapter.compareDate(date, this.minDate) >= 0) &&
  598. (!this.maxDate || this._dateAdapter.compareDate(date, this.maxDate) <= 0);
  599. };
  600. /**
  601. * Gets the date in this month that the given Date falls on.
  602. * Returns null if the given Date is in another month.
  603. */
  604. /**
  605. * Gets the date in this month that the given Date falls on.
  606. * Returns null if the given Date is in another month.
  607. * @private
  608. * @param {?} date
  609. * @return {?}
  610. */
  611. MatMonthView.prototype._getDateInCurrentMonth = /**
  612. * Gets the date in this month that the given Date falls on.
  613. * Returns null if the given Date is in another month.
  614. * @private
  615. * @param {?} date
  616. * @return {?}
  617. */
  618. function (date) {
  619. return date && this._hasSameMonthAndYear(date, this.activeDate) ?
  620. this._dateAdapter.getDate(date) : null;
  621. };
  622. /** Checks whether the 2 dates are non-null and fall within the same month of the same year. */
  623. /**
  624. * Checks whether the 2 dates are non-null and fall within the same month of the same year.
  625. * @private
  626. * @param {?} d1
  627. * @param {?} d2
  628. * @return {?}
  629. */
  630. MatMonthView.prototype._hasSameMonthAndYear = /**
  631. * Checks whether the 2 dates are non-null and fall within the same month of the same year.
  632. * @private
  633. * @param {?} d1
  634. * @param {?} d2
  635. * @return {?}
  636. */
  637. function (d1, d2) {
  638. return !!(d1 && d2 && this._dateAdapter.getMonth(d1) == this._dateAdapter.getMonth(d2) &&
  639. this._dateAdapter.getYear(d1) == this._dateAdapter.getYear(d2));
  640. };
  641. /**
  642. * @param obj The object to check.
  643. * @returns The given object if it is both a date instance and valid, otherwise null.
  644. */
  645. /**
  646. * @private
  647. * @param {?} obj The object to check.
  648. * @return {?} The given object if it is both a date instance and valid, otherwise null.
  649. */
  650. MatMonthView.prototype._getValidDateOrNull = /**
  651. * @private
  652. * @param {?} obj The object to check.
  653. * @return {?} The given object if it is both a date instance and valid, otherwise null.
  654. */
  655. function (obj) {
  656. return (this._dateAdapter.isDateInstance(obj) && this._dateAdapter.isValid(obj)) ? obj : null;
  657. };
  658. /** Determines whether the user has the RTL layout direction. */
  659. /**
  660. * Determines whether the user has the RTL layout direction.
  661. * @private
  662. * @return {?}
  663. */
  664. MatMonthView.prototype._isRtl = /**
  665. * Determines whether the user has the RTL layout direction.
  666. * @private
  667. * @return {?}
  668. */
  669. function () {
  670. return this._dir && this._dir.value === 'rtl';
  671. };
  672. MatMonthView.decorators = [
  673. { type: Component, args: [{selector: 'mat-month-view',
  674. template: "<table class=\"mat-calendar-table\" role=\"presentation\"><thead class=\"mat-calendar-table-header\"><tr><th *ngFor=\"let day of _weekdays\" [attr.aria-label]=\"day.long\">{{day.narrow}}</th></tr><tr><th class=\"mat-calendar-table-header-divider\" colspan=\"7\" aria-hidden=\"true\"></th></tr></thead><tbody mat-calendar-body [label]=\"_monthLabel\" [rows]=\"_weeks\" [todayValue]=\"_todayDate\" [selectedValue]=\"_selectedDate\" [labelMinRequiredCells]=\"3\" [activeCell]=\"_dateAdapter.getDate(activeDate) - 1\" (selectedValueChange)=\"_dateSelected($event)\" (keydown)=\"_handleCalendarBodyKeydown($event)\"></tbody></table>",
  675. exportAs: 'matMonthView',
  676. encapsulation: ViewEncapsulation.None,
  677. changeDetection: ChangeDetectionStrategy.OnPush
  678. },] },
  679. ];
  680. /** @nocollapse */
  681. MatMonthView.ctorParameters = function () { return [
  682. { type: ChangeDetectorRef },
  683. { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [MAT_DATE_FORMATS,] }] },
  684. { type: DateAdapter, decorators: [{ type: Optional }] },
  685. { type: Directionality, decorators: [{ type: Optional }] }
  686. ]; };
  687. MatMonthView.propDecorators = {
  688. activeDate: [{ type: Input }],
  689. selected: [{ type: Input }],
  690. minDate: [{ type: Input }],
  691. maxDate: [{ type: Input }],
  692. dateFilter: [{ type: Input }],
  693. dateClass: [{ type: Input }],
  694. selectedChange: [{ type: Output }],
  695. _userSelection: [{ type: Output }],
  696. activeDateChange: [{ type: Output }],
  697. _matCalendarBody: [{ type: ViewChild, args: [MatCalendarBody, { static: false },] }]
  698. };
  699. return MatMonthView;
  700. }());
  701. /**
  702. * @fileoverview added by tsickle
  703. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  704. */
  705. /** @type {?} */
  706. var yearsPerPage = 24;
  707. /** @type {?} */
  708. var yearsPerRow = 4;
  709. /**
  710. * An internal component used to display a year selector in the datepicker.
  711. * \@docs-private
  712. * @template D
  713. */
  714. var MatMultiYearView = /** @class */ (function () {
  715. function MatMultiYearView(_changeDetectorRef, _dateAdapter, _dir) {
  716. this._changeDetectorRef = _changeDetectorRef;
  717. this._dateAdapter = _dateAdapter;
  718. this._dir = _dir;
  719. /**
  720. * Emits when a new year is selected.
  721. */
  722. this.selectedChange = new EventEmitter();
  723. /**
  724. * Emits the selected year. This doesn't imply a change on the selected date
  725. */
  726. this.yearSelected = new EventEmitter();
  727. /**
  728. * Emits when any date is activated.
  729. */
  730. this.activeDateChange = new EventEmitter();
  731. if (!this._dateAdapter) {
  732. throw createMissingDateImplError('DateAdapter');
  733. }
  734. this._activeDate = this._dateAdapter.today();
  735. }
  736. Object.defineProperty(MatMultiYearView.prototype, "activeDate", {
  737. /** The date to display in this multi-year view (everything other than the year is ignored). */
  738. get: /**
  739. * The date to display in this multi-year view (everything other than the year is ignored).
  740. * @return {?}
  741. */
  742. function () { return this._activeDate; },
  743. set: /**
  744. * @param {?} value
  745. * @return {?}
  746. */
  747. function (value) {
  748. /** @type {?} */
  749. var oldActiveDate = this._activeDate;
  750. /** @type {?} */
  751. var validDate = this._getValidDateOrNull(this._dateAdapter.deserialize(value)) || this._dateAdapter.today();
  752. this._activeDate = this._dateAdapter.clampDate(validDate, this.minDate, this.maxDate);
  753. if (!isSameMultiYearView(this._dateAdapter, oldActiveDate, this._activeDate, this.minDate, this.maxDate)) {
  754. this._init();
  755. }
  756. },
  757. enumerable: true,
  758. configurable: true
  759. });
  760. Object.defineProperty(MatMultiYearView.prototype, "selected", {
  761. /** The currently selected date. */
  762. get: /**
  763. * The currently selected date.
  764. * @return {?}
  765. */
  766. function () { return this._selected; },
  767. set: /**
  768. * @param {?} value
  769. * @return {?}
  770. */
  771. function (value) {
  772. this._selected = this._getValidDateOrNull(this._dateAdapter.deserialize(value));
  773. this._selectedYear = this._selected && this._dateAdapter.getYear(this._selected);
  774. },
  775. enumerable: true,
  776. configurable: true
  777. });
  778. Object.defineProperty(MatMultiYearView.prototype, "minDate", {
  779. /** The minimum selectable date. */
  780. get: /**
  781. * The minimum selectable date.
  782. * @return {?}
  783. */
  784. function () { return this._minDate; },
  785. set: /**
  786. * @param {?} value
  787. * @return {?}
  788. */
  789. function (value) {
  790. this._minDate = this._getValidDateOrNull(this._dateAdapter.deserialize(value));
  791. },
  792. enumerable: true,
  793. configurable: true
  794. });
  795. Object.defineProperty(MatMultiYearView.prototype, "maxDate", {
  796. /** The maximum selectable date. */
  797. get: /**
  798. * The maximum selectable date.
  799. * @return {?}
  800. */
  801. function () { return this._maxDate; },
  802. set: /**
  803. * @param {?} value
  804. * @return {?}
  805. */
  806. function (value) {
  807. this._maxDate = this._getValidDateOrNull(this._dateAdapter.deserialize(value));
  808. },
  809. enumerable: true,
  810. configurable: true
  811. });
  812. /**
  813. * @return {?}
  814. */
  815. MatMultiYearView.prototype.ngAfterContentInit = /**
  816. * @return {?}
  817. */
  818. function () {
  819. this._init();
  820. };
  821. /** Initializes this multi-year view. */
  822. /**
  823. * Initializes this multi-year view.
  824. * @return {?}
  825. */
  826. MatMultiYearView.prototype._init = /**
  827. * Initializes this multi-year view.
  828. * @return {?}
  829. */
  830. function () {
  831. var _this = this;
  832. this._todayYear = this._dateAdapter.getYear(this._dateAdapter.today());
  833. // We want a range years such that we maximize the number of
  834. // enabled dates visible at once. This prevents issues where the minimum year
  835. // is the last item of a page OR the maximum year is the first item of a page.
  836. // The offset from the active year to the "slot" for the starting year is the
  837. // *actual* first rendered year in the multi-year view.
  838. /** @type {?} */
  839. var activeYear = this._dateAdapter.getYear(this._activeDate);
  840. /** @type {?} */
  841. var minYearOfPage = activeYear - getActiveOffset(this._dateAdapter, this.activeDate, this.minDate, this.maxDate);
  842. this._years = [];
  843. for (var i = 0, row = []; i < yearsPerPage; i++) {
  844. row.push(minYearOfPage + i);
  845. if (row.length == yearsPerRow) {
  846. this._years.push(row.map((/**
  847. * @param {?} year
  848. * @return {?}
  849. */
  850. function (year) { return _this._createCellForYear(year); })));
  851. row = [];
  852. }
  853. }
  854. this._changeDetectorRef.markForCheck();
  855. };
  856. /** Handles when a new year is selected. */
  857. /**
  858. * Handles when a new year is selected.
  859. * @param {?} year
  860. * @return {?}
  861. */
  862. MatMultiYearView.prototype._yearSelected = /**
  863. * Handles when a new year is selected.
  864. * @param {?} year
  865. * @return {?}
  866. */
  867. function (year) {
  868. this.yearSelected.emit(this._dateAdapter.createDate(year, 0, 1));
  869. /** @type {?} */
  870. var month = this._dateAdapter.getMonth(this.activeDate);
  871. /** @type {?} */
  872. var daysInMonth = this._dateAdapter.getNumDaysInMonth(this._dateAdapter.createDate(year, month, 1));
  873. this.selectedChange.emit(this._dateAdapter.createDate(year, month, Math.min(this._dateAdapter.getDate(this.activeDate), daysInMonth)));
  874. };
  875. /** Handles keydown events on the calendar body when calendar is in multi-year view. */
  876. /**
  877. * Handles keydown events on the calendar body when calendar is in multi-year view.
  878. * @param {?} event
  879. * @return {?}
  880. */
  881. MatMultiYearView.prototype._handleCalendarBodyKeydown = /**
  882. * Handles keydown events on the calendar body when calendar is in multi-year view.
  883. * @param {?} event
  884. * @return {?}
  885. */
  886. function (event) {
  887. /** @type {?} */
  888. var oldActiveDate = this._activeDate;
  889. /** @type {?} */
  890. var isRtl = this._isRtl();
  891. switch (event.keyCode) {
  892. case LEFT_ARROW:
  893. this.activeDate = this._dateAdapter.addCalendarYears(this._activeDate, isRtl ? 1 : -1);
  894. break;
  895. case RIGHT_ARROW:
  896. this.activeDate = this._dateAdapter.addCalendarYears(this._activeDate, isRtl ? -1 : 1);
  897. break;
  898. case UP_ARROW:
  899. this.activeDate = this._dateAdapter.addCalendarYears(this._activeDate, -yearsPerRow);
  900. break;
  901. case DOWN_ARROW:
  902. this.activeDate = this._dateAdapter.addCalendarYears(this._activeDate, yearsPerRow);
  903. break;
  904. case HOME:
  905. this.activeDate = this._dateAdapter.addCalendarYears(this._activeDate, -getActiveOffset(this._dateAdapter, this.activeDate, this.minDate, this.maxDate));
  906. break;
  907. case END:
  908. this.activeDate = this._dateAdapter.addCalendarYears(this._activeDate, yearsPerPage - getActiveOffset(this._dateAdapter, this.activeDate, this.minDate, this.maxDate) - 1);
  909. break;
  910. case PAGE_UP:
  911. this.activeDate =
  912. this._dateAdapter.addCalendarYears(this._activeDate, event.altKey ? -yearsPerPage * 10 : -yearsPerPage);
  913. break;
  914. case PAGE_DOWN:
  915. this.activeDate =
  916. this._dateAdapter.addCalendarYears(this._activeDate, event.altKey ? yearsPerPage * 10 : yearsPerPage);
  917. break;
  918. case ENTER:
  919. case SPACE:
  920. this._yearSelected(this._dateAdapter.getYear(this._activeDate));
  921. break;
  922. default:
  923. // Don't prevent default or focus active cell on keys that we don't explicitly handle.
  924. return;
  925. }
  926. if (this._dateAdapter.compareDate(oldActiveDate, this.activeDate)) {
  927. this.activeDateChange.emit(this.activeDate);
  928. }
  929. this._focusActiveCell();
  930. // Prevent unexpected default actions such as form submission.
  931. event.preventDefault();
  932. };
  933. /**
  934. * @return {?}
  935. */
  936. MatMultiYearView.prototype._getActiveCell = /**
  937. * @return {?}
  938. */
  939. function () {
  940. return getActiveOffset(this._dateAdapter, this.activeDate, this.minDate, this.maxDate);
  941. };
  942. /** Focuses the active cell after the microtask queue is empty. */
  943. /**
  944. * Focuses the active cell after the microtask queue is empty.
  945. * @return {?}
  946. */
  947. MatMultiYearView.prototype._focusActiveCell = /**
  948. * Focuses the active cell after the microtask queue is empty.
  949. * @return {?}
  950. */
  951. function () {
  952. this._matCalendarBody._focusActiveCell();
  953. };
  954. /** Creates an MatCalendarCell for the given year. */
  955. /**
  956. * Creates an MatCalendarCell for the given year.
  957. * @private
  958. * @param {?} year
  959. * @return {?}
  960. */
  961. MatMultiYearView.prototype._createCellForYear = /**
  962. * Creates an MatCalendarCell for the given year.
  963. * @private
  964. * @param {?} year
  965. * @return {?}
  966. */
  967. function (year) {
  968. /** @type {?} */
  969. var yearName = this._dateAdapter.getYearName(this._dateAdapter.createDate(year, 0, 1));
  970. return new MatCalendarCell(year, yearName, yearName, this._shouldEnableYear(year));
  971. };
  972. /** Whether the given year is enabled. */
  973. /**
  974. * Whether the given year is enabled.
  975. * @private
  976. * @param {?} year
  977. * @return {?}
  978. */
  979. MatMultiYearView.prototype._shouldEnableYear = /**
  980. * Whether the given year is enabled.
  981. * @private
  982. * @param {?} year
  983. * @return {?}
  984. */
  985. function (year) {
  986. // disable if the year is greater than maxDate lower than minDate
  987. if (year === undefined || year === null ||
  988. (this.maxDate && year > this._dateAdapter.getYear(this.maxDate)) ||
  989. (this.minDate && year < this._dateAdapter.getYear(this.minDate))) {
  990. return false;
  991. }
  992. // enable if it reaches here and there's no filter defined
  993. if (!this.dateFilter) {
  994. return true;
  995. }
  996. /** @type {?} */
  997. var firstOfYear = this._dateAdapter.createDate(year, 0, 1);
  998. // If any date in the year is enabled count the year as enabled.
  999. for (var date = firstOfYear; this._dateAdapter.getYear(date) == year; date = this._dateAdapter.addCalendarDays(date, 1)) {
  1000. if (this.dateFilter(date)) {
  1001. return true;
  1002. }
  1003. }
  1004. return false;
  1005. };
  1006. /**
  1007. * @param obj The object to check.
  1008. * @returns The given object if it is both a date instance and valid, otherwise null.
  1009. */
  1010. /**
  1011. * @private
  1012. * @param {?} obj The object to check.
  1013. * @return {?} The given object if it is both a date instance and valid, otherwise null.
  1014. */
  1015. MatMultiYearView.prototype._getValidDateOrNull = /**
  1016. * @private
  1017. * @param {?} obj The object to check.
  1018. * @return {?} The given object if it is both a date instance and valid, otherwise null.
  1019. */
  1020. function (obj) {
  1021. return (this._dateAdapter.isDateInstance(obj) && this._dateAdapter.isValid(obj)) ? obj : null;
  1022. };
  1023. /** Determines whether the user has the RTL layout direction. */
  1024. /**
  1025. * Determines whether the user has the RTL layout direction.
  1026. * @private
  1027. * @return {?}
  1028. */
  1029. MatMultiYearView.prototype._isRtl = /**
  1030. * Determines whether the user has the RTL layout direction.
  1031. * @private
  1032. * @return {?}
  1033. */
  1034. function () {
  1035. return this._dir && this._dir.value === 'rtl';
  1036. };
  1037. MatMultiYearView.decorators = [
  1038. { type: Component, args: [{selector: 'mat-multi-year-view',
  1039. template: "<table class=\"mat-calendar-table\" role=\"presentation\"><thead class=\"mat-calendar-table-header\"><tr><th class=\"mat-calendar-table-header-divider\" colspan=\"4\"></th></tr></thead><tbody mat-calendar-body [rows]=\"_years\" [todayValue]=\"_todayYear\" [selectedValue]=\"_selectedYear\" [numCols]=\"4\" [cellAspectRatio]=\"4 / 7\" [activeCell]=\"_getActiveCell()\" (selectedValueChange)=\"_yearSelected($event)\" (keydown)=\"_handleCalendarBodyKeydown($event)\"></tbody></table>",
  1040. exportAs: 'matMultiYearView',
  1041. encapsulation: ViewEncapsulation.None,
  1042. changeDetection: ChangeDetectionStrategy.OnPush
  1043. },] },
  1044. ];
  1045. /** @nocollapse */
  1046. MatMultiYearView.ctorParameters = function () { return [
  1047. { type: ChangeDetectorRef },
  1048. { type: DateAdapter, decorators: [{ type: Optional }] },
  1049. { type: Directionality, decorators: [{ type: Optional }] }
  1050. ]; };
  1051. MatMultiYearView.propDecorators = {
  1052. activeDate: [{ type: Input }],
  1053. selected: [{ type: Input }],
  1054. minDate: [{ type: Input }],
  1055. maxDate: [{ type: Input }],
  1056. dateFilter: [{ type: Input }],
  1057. selectedChange: [{ type: Output }],
  1058. yearSelected: [{ type: Output }],
  1059. activeDateChange: [{ type: Output }],
  1060. _matCalendarBody: [{ type: ViewChild, args: [MatCalendarBody, { static: false },] }]
  1061. };
  1062. return MatMultiYearView;
  1063. }());
  1064. /**
  1065. * @template D
  1066. * @param {?} dateAdapter
  1067. * @param {?} date1
  1068. * @param {?} date2
  1069. * @param {?} minDate
  1070. * @param {?} maxDate
  1071. * @return {?}
  1072. */
  1073. function isSameMultiYearView(dateAdapter, date1, date2, minDate, maxDate) {
  1074. /** @type {?} */
  1075. var year1 = dateAdapter.getYear(date1);
  1076. /** @type {?} */
  1077. var year2 = dateAdapter.getYear(date2);
  1078. /** @type {?} */
  1079. var startingYear = getStartingYear(dateAdapter, minDate, maxDate);
  1080. return Math.floor((year1 - startingYear) / yearsPerPage) ===
  1081. Math.floor((year2 - startingYear) / yearsPerPage);
  1082. }
  1083. /**
  1084. * When the multi-year view is first opened, the active year will be in view.
  1085. * So we compute how many years are between the active year and the *slot* where our
  1086. * "startingYear" will render when paged into view.
  1087. * @template D
  1088. * @param {?} dateAdapter
  1089. * @param {?} activeDate
  1090. * @param {?} minDate
  1091. * @param {?} maxDate
  1092. * @return {?}
  1093. */
  1094. function getActiveOffset(dateAdapter, activeDate, minDate, maxDate) {
  1095. /** @type {?} */
  1096. var activeYear = dateAdapter.getYear(activeDate);
  1097. return euclideanModulo((activeYear - getStartingYear(dateAdapter, minDate, maxDate)), yearsPerPage);
  1098. }
  1099. /**
  1100. * We pick a "starting" year such that either the maximum year would be at the end
  1101. * or the minimum year would be at the beginning of a page.
  1102. * @template D
  1103. * @param {?} dateAdapter
  1104. * @param {?} minDate
  1105. * @param {?} maxDate
  1106. * @return {?}
  1107. */
  1108. function getStartingYear(dateAdapter, minDate, maxDate) {
  1109. /** @type {?} */
  1110. var startingYear = 0;
  1111. if (maxDate) {
  1112. /** @type {?} */
  1113. var maxYear = dateAdapter.getYear(maxDate);
  1114. startingYear = maxYear - yearsPerPage + 1;
  1115. }
  1116. else if (minDate) {
  1117. startingYear = dateAdapter.getYear(minDate);
  1118. }
  1119. return startingYear;
  1120. }
  1121. /**
  1122. * Gets remainder that is non-negative, even if first number is negative
  1123. * @param {?} a
  1124. * @param {?} b
  1125. * @return {?}
  1126. */
  1127. function euclideanModulo(a, b) {
  1128. return (a % b + b) % b;
  1129. }
  1130. /**
  1131. * @fileoverview added by tsickle
  1132. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1133. */
  1134. /**
  1135. * An internal component used to display a single year in the datepicker.
  1136. * \@docs-private
  1137. * @template D
  1138. */
  1139. var MatYearView = /** @class */ (function () {
  1140. function MatYearView(_changeDetectorRef, _dateFormats, _dateAdapter, _dir) {
  1141. this._changeDetectorRef = _changeDetectorRef;
  1142. this._dateFormats = _dateFormats;
  1143. this._dateAdapter = _dateAdapter;
  1144. this._dir = _dir;
  1145. /**
  1146. * Emits when a new month is selected.
  1147. */
  1148. this.selectedChange = new EventEmitter();
  1149. /**
  1150. * Emits the selected month. This doesn't imply a change on the selected date
  1151. */
  1152. this.monthSelected = new EventEmitter();
  1153. /**
  1154. * Emits when any date is activated.
  1155. */
  1156. this.activeDateChange = new EventEmitter();
  1157. if (!this._dateAdapter) {
  1158. throw createMissingDateImplError('DateAdapter');
  1159. }
  1160. if (!this._dateFormats) {
  1161. throw createMissingDateImplError('MAT_DATE_FORMATS');
  1162. }
  1163. this._activeDate = this._dateAdapter.today();
  1164. }
  1165. Object.defineProperty(MatYearView.prototype, "activeDate", {
  1166. /** The date to display in this year view (everything other than the year is ignored). */
  1167. get: /**
  1168. * The date to display in this year view (everything other than the year is ignored).
  1169. * @return {?}
  1170. */
  1171. function () { return this._activeDate; },
  1172. set: /**
  1173. * @param {?} value
  1174. * @return {?}
  1175. */
  1176. function (value) {
  1177. /** @type {?} */
  1178. var oldActiveDate = this._activeDate;
  1179. /** @type {?} */
  1180. var validDate = this._getValidDateOrNull(this._dateAdapter.deserialize(value)) || this._dateAdapter.today();
  1181. this._activeDate = this._dateAdapter.clampDate(validDate, this.minDate, this.maxDate);
  1182. if (this._dateAdapter.getYear(oldActiveDate) !== this._dateAdapter.getYear(this._activeDate)) {
  1183. this._init();
  1184. }
  1185. },
  1186. enumerable: true,
  1187. configurable: true
  1188. });
  1189. Object.defineProperty(MatYearView.prototype, "selected", {
  1190. /** The currently selected date. */
  1191. get: /**
  1192. * The currently selected date.
  1193. * @return {?}
  1194. */
  1195. function () { return this._selected; },
  1196. set: /**
  1197. * @param {?} value
  1198. * @return {?}
  1199. */
  1200. function (value) {
  1201. this._selected = this._getValidDateOrNull(this._dateAdapter.deserialize(value));
  1202. this._selectedMonth = this._getMonthInCurrentYear(this._selected);
  1203. },
  1204. enumerable: true,
  1205. configurable: true
  1206. });
  1207. Object.defineProperty(MatYearView.prototype, "minDate", {
  1208. /** The minimum selectable date. */
  1209. get: /**
  1210. * The minimum selectable date.
  1211. * @return {?}
  1212. */
  1213. function () { return this._minDate; },
  1214. set: /**
  1215. * @param {?} value
  1216. * @return {?}
  1217. */
  1218. function (value) {
  1219. this._minDate = this._getValidDateOrNull(this._dateAdapter.deserialize(value));
  1220. },
  1221. enumerable: true,
  1222. configurable: true
  1223. });
  1224. Object.defineProperty(MatYearView.prototype, "maxDate", {
  1225. /** The maximum selectable date. */
  1226. get: /**
  1227. * The maximum selectable date.
  1228. * @return {?}
  1229. */
  1230. function () { return this._maxDate; },
  1231. set: /**
  1232. * @param {?} value
  1233. * @return {?}
  1234. */
  1235. function (value) {
  1236. this._maxDate = this._getValidDateOrNull(this._dateAdapter.deserialize(value));
  1237. },
  1238. enumerable: true,
  1239. configurable: true
  1240. });
  1241. /**
  1242. * @return {?}
  1243. */
  1244. MatYearView.prototype.ngAfterContentInit = /**
  1245. * @return {?}
  1246. */
  1247. function () {
  1248. this._init();
  1249. };
  1250. /** Handles when a new month is selected. */
  1251. /**
  1252. * Handles when a new month is selected.
  1253. * @param {?} month
  1254. * @return {?}
  1255. */
  1256. MatYearView.prototype._monthSelected = /**
  1257. * Handles when a new month is selected.
  1258. * @param {?} month
  1259. * @return {?}
  1260. */
  1261. function (month) {
  1262. /** @type {?} */
  1263. var normalizedDate = this._dateAdapter.createDate(this._dateAdapter.getYear(this.activeDate), month, 1);
  1264. this.monthSelected.emit(normalizedDate);
  1265. /** @type {?} */
  1266. var daysInMonth = this._dateAdapter.getNumDaysInMonth(normalizedDate);
  1267. this.selectedChange.emit(this._dateAdapter.createDate(this._dateAdapter.getYear(this.activeDate), month, Math.min(this._dateAdapter.getDate(this.activeDate), daysInMonth)));
  1268. };
  1269. /** Handles keydown events on the calendar body when calendar is in year view. */
  1270. /**
  1271. * Handles keydown events on the calendar body when calendar is in year view.
  1272. * @param {?} event
  1273. * @return {?}
  1274. */
  1275. MatYearView.prototype._handleCalendarBodyKeydown = /**
  1276. * Handles keydown events on the calendar body when calendar is in year view.
  1277. * @param {?} event
  1278. * @return {?}
  1279. */
  1280. function (event) {
  1281. // TODO(mmalerba): We currently allow keyboard navigation to disabled dates, but just prevent
  1282. // disabled ones from being selected. This may not be ideal, we should look into whether
  1283. // navigation should skip over disabled dates, and if so, how to implement that efficiently.
  1284. // TODO(mmalerba): We currently allow keyboard navigation to disabled dates, but just prevent
  1285. // disabled ones from being selected. This may not be ideal, we should look into whether
  1286. // navigation should skip over disabled dates, and if so, how to implement that efficiently.
  1287. /** @type {?} */
  1288. var oldActiveDate = this._activeDate;
  1289. /** @type {?} */
  1290. var isRtl = this._isRtl();
  1291. switch (event.keyCode) {
  1292. case LEFT_ARROW:
  1293. this.activeDate = this._dateAdapter.addCalendarMonths(this._activeDate, isRtl ? 1 : -1);
  1294. break;
  1295. case RIGHT_ARROW:
  1296. this.activeDate = this._dateAdapter.addCalendarMonths(this._activeDate, isRtl ? -1 : 1);
  1297. break;
  1298. case UP_ARROW:
  1299. this.activeDate = this._dateAdapter.addCalendarMonths(this._activeDate, -4);
  1300. break;
  1301. case DOWN_ARROW:
  1302. this.activeDate = this._dateAdapter.addCalendarMonths(this._activeDate, 4);
  1303. break;
  1304. case HOME:
  1305. this.activeDate = this._dateAdapter.addCalendarMonths(this._activeDate, -this._dateAdapter.getMonth(this._activeDate));
  1306. break;
  1307. case END:
  1308. this.activeDate = this._dateAdapter.addCalendarMonths(this._activeDate, 11 - this._dateAdapter.getMonth(this._activeDate));
  1309. break;
  1310. case PAGE_UP:
  1311. this.activeDate =
  1312. this._dateAdapter.addCalendarYears(this._activeDate, event.altKey ? -10 : -1);
  1313. break;
  1314. case PAGE_DOWN:
  1315. this.activeDate =
  1316. this._dateAdapter.addCalendarYears(this._activeDate, event.altKey ? 10 : 1);
  1317. break;
  1318. case ENTER:
  1319. case SPACE:
  1320. this._monthSelected(this._dateAdapter.getMonth(this._activeDate));
  1321. break;
  1322. default:
  1323. // Don't prevent default or focus active cell on keys that we don't explicitly handle.
  1324. return;
  1325. }
  1326. if (this._dateAdapter.compareDate(oldActiveDate, this.activeDate)) {
  1327. this.activeDateChange.emit(this.activeDate);
  1328. }
  1329. this._focusActiveCell();
  1330. // Prevent unexpected default actions such as form submission.
  1331. event.preventDefault();
  1332. };
  1333. /** Initializes this year view. */
  1334. /**
  1335. * Initializes this year view.
  1336. * @return {?}
  1337. */
  1338. MatYearView.prototype._init = /**
  1339. * Initializes this year view.
  1340. * @return {?}
  1341. */
  1342. function () {
  1343. var _this = this;
  1344. this._selectedMonth = this._getMonthInCurrentYear(this.selected);
  1345. this._todayMonth = this._getMonthInCurrentYear(this._dateAdapter.today());
  1346. this._yearLabel = this._dateAdapter.getYearName(this.activeDate);
  1347. /** @type {?} */
  1348. var monthNames = this._dateAdapter.getMonthNames('short');
  1349. // First row of months only contains 5 elements so we can fit the year label on the same row.
  1350. this._months = [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]].map((/**
  1351. * @param {?} row
  1352. * @return {?}
  1353. */
  1354. function (row) { return row.map((/**
  1355. * @param {?} month
  1356. * @return {?}
  1357. */
  1358. function (month) { return _this._createCellForMonth(month, monthNames[month]); })); }));
  1359. this._changeDetectorRef.markForCheck();
  1360. };
  1361. /** Focuses the active cell after the microtask queue is empty. */
  1362. /**
  1363. * Focuses the active cell after the microtask queue is empty.
  1364. * @return {?}
  1365. */
  1366. MatYearView.prototype._focusActiveCell = /**
  1367. * Focuses the active cell after the microtask queue is empty.
  1368. * @return {?}
  1369. */
  1370. function () {
  1371. this._matCalendarBody._focusActiveCell();
  1372. };
  1373. /**
  1374. * Gets the month in this year that the given Date falls on.
  1375. * Returns null if the given Date is in another year.
  1376. */
  1377. /**
  1378. * Gets the month in this year that the given Date falls on.
  1379. * Returns null if the given Date is in another year.
  1380. * @private
  1381. * @param {?} date
  1382. * @return {?}
  1383. */
  1384. MatYearView.prototype._getMonthInCurrentYear = /**
  1385. * Gets the month in this year that the given Date falls on.
  1386. * Returns null if the given Date is in another year.
  1387. * @private
  1388. * @param {?} date
  1389. * @return {?}
  1390. */
  1391. function (date) {
  1392. return date && this._dateAdapter.getYear(date) == this._dateAdapter.getYear(this.activeDate) ?
  1393. this._dateAdapter.getMonth(date) : null;
  1394. };
  1395. /** Creates an MatCalendarCell for the given month. */
  1396. /**
  1397. * Creates an MatCalendarCell for the given month.
  1398. * @private
  1399. * @param {?} month
  1400. * @param {?} monthName
  1401. * @return {?}
  1402. */
  1403. MatYearView.prototype._createCellForMonth = /**
  1404. * Creates an MatCalendarCell for the given month.
  1405. * @private
  1406. * @param {?} month
  1407. * @param {?} monthName
  1408. * @return {?}
  1409. */
  1410. function (month, monthName) {
  1411. /** @type {?} */
  1412. var ariaLabel = this._dateAdapter.format(this._dateAdapter.createDate(this._dateAdapter.getYear(this.activeDate), month, 1), this._dateFormats.display.monthYearA11yLabel);
  1413. return new MatCalendarCell(month, monthName.toLocaleUpperCase(), ariaLabel, this._shouldEnableMonth(month));
  1414. };
  1415. /** Whether the given month is enabled. */
  1416. /**
  1417. * Whether the given month is enabled.
  1418. * @private
  1419. * @param {?} month
  1420. * @return {?}
  1421. */
  1422. MatYearView.prototype._shouldEnableMonth = /**
  1423. * Whether the given month is enabled.
  1424. * @private
  1425. * @param {?} month
  1426. * @return {?}
  1427. */
  1428. function (month) {
  1429. /** @type {?} */
  1430. var activeYear = this._dateAdapter.getYear(this.activeDate);
  1431. if (month === undefined || month === null ||
  1432. this._isYearAndMonthAfterMaxDate(activeYear, month) ||
  1433. this._isYearAndMonthBeforeMinDate(activeYear, month)) {
  1434. return false;
  1435. }
  1436. if (!this.dateFilter) {
  1437. return true;
  1438. }
  1439. /** @type {?} */
  1440. var firstOfMonth = this._dateAdapter.createDate(activeYear, month, 1);
  1441. // If any date in the month is enabled count the month as enabled.
  1442. for (var date = firstOfMonth; this._dateAdapter.getMonth(date) == month; date = this._dateAdapter.addCalendarDays(date, 1)) {
  1443. if (this.dateFilter(date)) {
  1444. return true;
  1445. }
  1446. }
  1447. return false;
  1448. };
  1449. /**
  1450. * Tests whether the combination month/year is after this.maxDate, considering
  1451. * just the month and year of this.maxDate
  1452. */
  1453. /**
  1454. * Tests whether the combination month/year is after this.maxDate, considering
  1455. * just the month and year of this.maxDate
  1456. * @private
  1457. * @param {?} year
  1458. * @param {?} month
  1459. * @return {?}
  1460. */
  1461. MatYearView.prototype._isYearAndMonthAfterMaxDate = /**
  1462. * Tests whether the combination month/year is after this.maxDate, considering
  1463. * just the month and year of this.maxDate
  1464. * @private
  1465. * @param {?} year
  1466. * @param {?} month
  1467. * @return {?}
  1468. */
  1469. function (year, month) {
  1470. if (this.maxDate) {
  1471. /** @type {?} */
  1472. var maxYear = this._dateAdapter.getYear(this.maxDate);
  1473. /** @type {?} */
  1474. var maxMonth = this._dateAdapter.getMonth(this.maxDate);
  1475. return year > maxYear || (year === maxYear && month > maxMonth);
  1476. }
  1477. return false;
  1478. };
  1479. /**
  1480. * Tests whether the combination month/year is before this.minDate, considering
  1481. * just the month and year of this.minDate
  1482. */
  1483. /**
  1484. * Tests whether the combination month/year is before this.minDate, considering
  1485. * just the month and year of this.minDate
  1486. * @private
  1487. * @param {?} year
  1488. * @param {?} month
  1489. * @return {?}
  1490. */
  1491. MatYearView.prototype._isYearAndMonthBeforeMinDate = /**
  1492. * Tests whether the combination month/year is before this.minDate, considering
  1493. * just the month and year of this.minDate
  1494. * @private
  1495. * @param {?} year
  1496. * @param {?} month
  1497. * @return {?}
  1498. */
  1499. function (year, month) {
  1500. if (this.minDate) {
  1501. /** @type {?} */
  1502. var minYear = this._dateAdapter.getYear(this.minDate);
  1503. /** @type {?} */
  1504. var minMonth = this._dateAdapter.getMonth(this.minDate);
  1505. return year < minYear || (year === minYear && month < minMonth);
  1506. }
  1507. return false;
  1508. };
  1509. /**
  1510. * @param obj The object to check.
  1511. * @returns The given object if it is both a date instance and valid, otherwise null.
  1512. */
  1513. /**
  1514. * @private
  1515. * @param {?} obj The object to check.
  1516. * @return {?} The given object if it is both a date instance and valid, otherwise null.
  1517. */
  1518. MatYearView.prototype._getValidDateOrNull = /**
  1519. * @private
  1520. * @param {?} obj The object to check.
  1521. * @return {?} The given object if it is both a date instance and valid, otherwise null.
  1522. */
  1523. function (obj) {
  1524. return (this._dateAdapter.isDateInstance(obj) && this._dateAdapter.isValid(obj)) ? obj : null;
  1525. };
  1526. /** Determines whether the user has the RTL layout direction. */
  1527. /**
  1528. * Determines whether the user has the RTL layout direction.
  1529. * @private
  1530. * @return {?}
  1531. */
  1532. MatYearView.prototype._isRtl = /**
  1533. * Determines whether the user has the RTL layout direction.
  1534. * @private
  1535. * @return {?}
  1536. */
  1537. function () {
  1538. return this._dir && this._dir.value === 'rtl';
  1539. };
  1540. MatYearView.decorators = [
  1541. { type: Component, args: [{selector: 'mat-year-view',
  1542. template: "<table class=\"mat-calendar-table\" role=\"presentation\"><thead class=\"mat-calendar-table-header\"><tr><th class=\"mat-calendar-table-header-divider\" colspan=\"4\"></th></tr></thead><tbody mat-calendar-body [label]=\"_yearLabel\" [rows]=\"_months\" [todayValue]=\"_todayMonth\" [selectedValue]=\"_selectedMonth\" [labelMinRequiredCells]=\"2\" [numCols]=\"4\" [cellAspectRatio]=\"4 / 7\" [activeCell]=\"_dateAdapter.getMonth(activeDate)\" (selectedValueChange)=\"_monthSelected($event)\" (keydown)=\"_handleCalendarBodyKeydown($event)\"></tbody></table>",
  1543. exportAs: 'matYearView',
  1544. encapsulation: ViewEncapsulation.None,
  1545. changeDetection: ChangeDetectionStrategy.OnPush
  1546. },] },
  1547. ];
  1548. /** @nocollapse */
  1549. MatYearView.ctorParameters = function () { return [
  1550. { type: ChangeDetectorRef },
  1551. { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [MAT_DATE_FORMATS,] }] },
  1552. { type: DateAdapter, decorators: [{ type: Optional }] },
  1553. { type: Directionality, decorators: [{ type: Optional }] }
  1554. ]; };
  1555. MatYearView.propDecorators = {
  1556. activeDate: [{ type: Input }],
  1557. selected: [{ type: Input }],
  1558. minDate: [{ type: Input }],
  1559. maxDate: [{ type: Input }],
  1560. dateFilter: [{ type: Input }],
  1561. selectedChange: [{ type: Output }],
  1562. monthSelected: [{ type: Output }],
  1563. activeDateChange: [{ type: Output }],
  1564. _matCalendarBody: [{ type: ViewChild, args: [MatCalendarBody, { static: false },] }]
  1565. };
  1566. return MatYearView;
  1567. }());
  1568. /**
  1569. * @fileoverview added by tsickle
  1570. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1571. */
  1572. /**
  1573. * Default header for MatCalendar
  1574. * @template D
  1575. */
  1576. var MatCalendarHeader = /** @class */ (function () {
  1577. function MatCalendarHeader(_intl, calendar, _dateAdapter, _dateFormats, changeDetectorRef) {
  1578. this._intl = _intl;
  1579. this.calendar = calendar;
  1580. this._dateAdapter = _dateAdapter;
  1581. this._dateFormats = _dateFormats;
  1582. this.calendar.stateChanges.subscribe((/**
  1583. * @return {?}
  1584. */
  1585. function () { return changeDetectorRef.markForCheck(); }));
  1586. }
  1587. Object.defineProperty(MatCalendarHeader.prototype, "periodButtonText", {
  1588. /** The label for the current calendar view. */
  1589. get: /**
  1590. * The label for the current calendar view.
  1591. * @return {?}
  1592. */
  1593. function () {
  1594. if (this.calendar.currentView == 'month') {
  1595. return this._dateAdapter
  1596. .format(this.calendar.activeDate, this._dateFormats.display.monthYearLabel)
  1597. .toLocaleUpperCase();
  1598. }
  1599. if (this.calendar.currentView == 'year') {
  1600. return this._dateAdapter.getYearName(this.calendar.activeDate);
  1601. }
  1602. // The offset from the active year to the "slot" for the starting year is the
  1603. // *actual* first rendered year in the multi-year view, and the last year is
  1604. // just yearsPerPage - 1 away.
  1605. /** @type {?} */
  1606. var activeYear = this._dateAdapter.getYear(this.calendar.activeDate);
  1607. /** @type {?} */
  1608. var minYearOfPage = activeYear - getActiveOffset(this._dateAdapter, this.calendar.activeDate, this.calendar.minDate, this.calendar.maxDate);
  1609. /** @type {?} */
  1610. var maxYearOfPage = minYearOfPage + yearsPerPage - 1;
  1611. return minYearOfPage + " \u2013 " + maxYearOfPage;
  1612. },
  1613. enumerable: true,
  1614. configurable: true
  1615. });
  1616. Object.defineProperty(MatCalendarHeader.prototype, "periodButtonLabel", {
  1617. get: /**
  1618. * @return {?}
  1619. */
  1620. function () {
  1621. return this.calendar.currentView == 'month' ?
  1622. this._intl.switchToMultiYearViewLabel : this._intl.switchToMonthViewLabel;
  1623. },
  1624. enumerable: true,
  1625. configurable: true
  1626. });
  1627. Object.defineProperty(MatCalendarHeader.prototype, "prevButtonLabel", {
  1628. /** The label for the previous button. */
  1629. get: /**
  1630. * The label for the previous button.
  1631. * @return {?}
  1632. */
  1633. function () {
  1634. return {
  1635. 'month': this._intl.prevMonthLabel,
  1636. 'year': this._intl.prevYearLabel,
  1637. 'multi-year': this._intl.prevMultiYearLabel
  1638. }[this.calendar.currentView];
  1639. },
  1640. enumerable: true,
  1641. configurable: true
  1642. });
  1643. Object.defineProperty(MatCalendarHeader.prototype, "nextButtonLabel", {
  1644. /** The label for the next button. */
  1645. get: /**
  1646. * The label for the next button.
  1647. * @return {?}
  1648. */
  1649. function () {
  1650. return {
  1651. 'month': this._intl.nextMonthLabel,
  1652. 'year': this._intl.nextYearLabel,
  1653. 'multi-year': this._intl.nextMultiYearLabel
  1654. }[this.calendar.currentView];
  1655. },
  1656. enumerable: true,
  1657. configurable: true
  1658. });
  1659. /** Handles user clicks on the period label. */
  1660. /**
  1661. * Handles user clicks on the period label.
  1662. * @return {?}
  1663. */
  1664. MatCalendarHeader.prototype.currentPeriodClicked = /**
  1665. * Handles user clicks on the period label.
  1666. * @return {?}
  1667. */
  1668. function () {
  1669. this.calendar.currentView = this.calendar.currentView == 'month' ? 'multi-year' : 'month';
  1670. };
  1671. /** Handles user clicks on the previous button. */
  1672. /**
  1673. * Handles user clicks on the previous button.
  1674. * @return {?}
  1675. */
  1676. MatCalendarHeader.prototype.previousClicked = /**
  1677. * Handles user clicks on the previous button.
  1678. * @return {?}
  1679. */
  1680. function () {
  1681. this.calendar.activeDate = this.calendar.currentView == 'month' ?
  1682. this._dateAdapter.addCalendarMonths(this.calendar.activeDate, -1) :
  1683. this._dateAdapter.addCalendarYears(this.calendar.activeDate, this.calendar.currentView == 'year' ? -1 : -yearsPerPage);
  1684. };
  1685. /** Handles user clicks on the next button. */
  1686. /**
  1687. * Handles user clicks on the next button.
  1688. * @return {?}
  1689. */
  1690. MatCalendarHeader.prototype.nextClicked = /**
  1691. * Handles user clicks on the next button.
  1692. * @return {?}
  1693. */
  1694. function () {
  1695. this.calendar.activeDate = this.calendar.currentView == 'month' ?
  1696. this._dateAdapter.addCalendarMonths(this.calendar.activeDate, 1) :
  1697. this._dateAdapter.addCalendarYears(this.calendar.activeDate, this.calendar.currentView == 'year' ? 1 : yearsPerPage);
  1698. };
  1699. /** Whether the previous period button is enabled. */
  1700. /**
  1701. * Whether the previous period button is enabled.
  1702. * @return {?}
  1703. */
  1704. MatCalendarHeader.prototype.previousEnabled = /**
  1705. * Whether the previous period button is enabled.
  1706. * @return {?}
  1707. */
  1708. function () {
  1709. if (!this.calendar.minDate) {
  1710. return true;
  1711. }
  1712. return !this.calendar.minDate ||
  1713. !this._isSameView(this.calendar.activeDate, this.calendar.minDate);
  1714. };
  1715. /** Whether the next period button is enabled. */
  1716. /**
  1717. * Whether the next period button is enabled.
  1718. * @return {?}
  1719. */
  1720. MatCalendarHeader.prototype.nextEnabled = /**
  1721. * Whether the next period button is enabled.
  1722. * @return {?}
  1723. */
  1724. function () {
  1725. return !this.calendar.maxDate ||
  1726. !this._isSameView(this.calendar.activeDate, this.calendar.maxDate);
  1727. };
  1728. /** Whether the two dates represent the same view in the current view mode (month or year). */
  1729. /**
  1730. * Whether the two dates represent the same view in the current view mode (month or year).
  1731. * @private
  1732. * @param {?} date1
  1733. * @param {?} date2
  1734. * @return {?}
  1735. */
  1736. MatCalendarHeader.prototype._isSameView = /**
  1737. * Whether the two dates represent the same view in the current view mode (month or year).
  1738. * @private
  1739. * @param {?} date1
  1740. * @param {?} date2
  1741. * @return {?}
  1742. */
  1743. function (date1, date2) {
  1744. if (this.calendar.currentView == 'month') {
  1745. return this._dateAdapter.getYear(date1) == this._dateAdapter.getYear(date2) &&
  1746. this._dateAdapter.getMonth(date1) == this._dateAdapter.getMonth(date2);
  1747. }
  1748. if (this.calendar.currentView == 'year') {
  1749. return this._dateAdapter.getYear(date1) == this._dateAdapter.getYear(date2);
  1750. }
  1751. // Otherwise we are in 'multi-year' view.
  1752. return isSameMultiYearView(this._dateAdapter, date1, date2, this.calendar.minDate, this.calendar.maxDate);
  1753. };
  1754. MatCalendarHeader.decorators = [
  1755. { type: Component, args: [{selector: 'mat-calendar-header',
  1756. template: "<div class=\"mat-calendar-header\"><div class=\"mat-calendar-controls\"><button mat-button type=\"button\" class=\"mat-calendar-period-button\" (click)=\"currentPeriodClicked()\" [attr.aria-label]=\"periodButtonLabel\" cdkAriaLive=\"polite\">{{periodButtonText}}<div class=\"mat-calendar-arrow\" [class.mat-calendar-invert]=\"calendar.currentView != 'month'\"></div></button><div class=\"mat-calendar-spacer\"></div><ng-content></ng-content><button mat-icon-button type=\"button\" class=\"mat-calendar-previous-button\" [disabled]=\"!previousEnabled()\" (click)=\"previousClicked()\" [attr.aria-label]=\"prevButtonLabel\"></button> <button mat-icon-button type=\"button\" class=\"mat-calendar-next-button\" [disabled]=\"!nextEnabled()\" (click)=\"nextClicked()\" [attr.aria-label]=\"nextButtonLabel\"></button></div></div>",
  1757. exportAs: 'matCalendarHeader',
  1758. encapsulation: ViewEncapsulation.None,
  1759. changeDetection: ChangeDetectionStrategy.OnPush,
  1760. },] },
  1761. ];
  1762. /** @nocollapse */
  1763. MatCalendarHeader.ctorParameters = function () { return [
  1764. { type: MatDatepickerIntl },
  1765. { type: MatCalendar, decorators: [{ type: Inject, args: [forwardRef((/**
  1766. * @return {?}
  1767. */
  1768. function () { return MatCalendar; })),] }] },
  1769. { type: DateAdapter, decorators: [{ type: Optional }] },
  1770. { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [MAT_DATE_FORMATS,] }] },
  1771. { type: ChangeDetectorRef }
  1772. ]; };
  1773. return MatCalendarHeader;
  1774. }());
  1775. /**
  1776. * A calendar that is used as part of the datepicker.
  1777. * \@docs-private
  1778. * @template D
  1779. */
  1780. var MatCalendar = /** @class */ (function () {
  1781. function MatCalendar(_intl, _dateAdapter, _dateFormats, _changeDetectorRef) {
  1782. var _this = this;
  1783. this._dateAdapter = _dateAdapter;
  1784. this._dateFormats = _dateFormats;
  1785. this._changeDetectorRef = _changeDetectorRef;
  1786. /**
  1787. * Used for scheduling that focus should be moved to the active cell on the next tick.
  1788. * We need to schedule it, rather than do it immediately, because we have to wait
  1789. * for Angular to re-evaluate the view children.
  1790. */
  1791. this._moveFocusOnNextTick = false;
  1792. /**
  1793. * Whether the calendar should be started in month or year view.
  1794. */
  1795. this.startView = 'month';
  1796. /**
  1797. * Emits when the currently selected date changes.
  1798. */
  1799. this.selectedChange = new EventEmitter();
  1800. /**
  1801. * Emits the year chosen in multiyear view.
  1802. * This doesn't imply a change on the selected date.
  1803. */
  1804. this.yearSelected = new EventEmitter();
  1805. /**
  1806. * Emits the month chosen in year view.
  1807. * This doesn't imply a change on the selected date.
  1808. */
  1809. this.monthSelected = new EventEmitter();
  1810. /**
  1811. * Emits when any date is selected.
  1812. */
  1813. this._userSelection = new EventEmitter();
  1814. /**
  1815. * Emits whenever there is a state change that the header may need to respond to.
  1816. */
  1817. this.stateChanges = new Subject();
  1818. if (!this._dateAdapter) {
  1819. throw createMissingDateImplError('DateAdapter');
  1820. }
  1821. if (!this._dateFormats) {
  1822. throw createMissingDateImplError('MAT_DATE_FORMATS');
  1823. }
  1824. this._intlChanges = _intl.changes.subscribe((/**
  1825. * @return {?}
  1826. */
  1827. function () {
  1828. _changeDetectorRef.markForCheck();
  1829. _this.stateChanges.next();
  1830. }));
  1831. }
  1832. Object.defineProperty(MatCalendar.prototype, "startAt", {
  1833. /** A date representing the period (month or year) to start the calendar in. */
  1834. get: /**
  1835. * A date representing the period (month or year) to start the calendar in.
  1836. * @return {?}
  1837. */
  1838. function () { return this._startAt; },
  1839. set: /**
  1840. * @param {?} value
  1841. * @return {?}
  1842. */
  1843. function (value) {
  1844. this._startAt = this._getValidDateOrNull(this._dateAdapter.deserialize(value));
  1845. },
  1846. enumerable: true,
  1847. configurable: true
  1848. });
  1849. Object.defineProperty(MatCalendar.prototype, "selected", {
  1850. /** The currently selected date. */
  1851. get: /**
  1852. * The currently selected date.
  1853. * @return {?}
  1854. */
  1855. function () { return this._selected; },
  1856. set: /**
  1857. * @param {?} value
  1858. * @return {?}
  1859. */
  1860. function (value) {
  1861. this._selected = this._getValidDateOrNull(this._dateAdapter.deserialize(value));
  1862. },
  1863. enumerable: true,
  1864. configurable: true
  1865. });
  1866. Object.defineProperty(MatCalendar.prototype, "minDate", {
  1867. /** The minimum selectable date. */
  1868. get: /**
  1869. * The minimum selectable date.
  1870. * @return {?}
  1871. */
  1872. function () { return this._minDate; },
  1873. set: /**
  1874. * @param {?} value
  1875. * @return {?}
  1876. */
  1877. function (value) {
  1878. this._minDate = this._getValidDateOrNull(this._dateAdapter.deserialize(value));
  1879. },
  1880. enumerable: true,
  1881. configurable: true
  1882. });
  1883. Object.defineProperty(MatCalendar.prototype, "maxDate", {
  1884. /** The maximum selectable date. */
  1885. get: /**
  1886. * The maximum selectable date.
  1887. * @return {?}
  1888. */
  1889. function () { return this._maxDate; },
  1890. set: /**
  1891. * @param {?} value
  1892. * @return {?}
  1893. */
  1894. function (value) {
  1895. this._maxDate = this._getValidDateOrNull(this._dateAdapter.deserialize(value));
  1896. },
  1897. enumerable: true,
  1898. configurable: true
  1899. });
  1900. Object.defineProperty(MatCalendar.prototype, "activeDate", {
  1901. /**
  1902. * The current active date. This determines which time period is shown and which date is
  1903. * highlighted when using keyboard navigation.
  1904. */
  1905. get: /**
  1906. * The current active date. This determines which time period is shown and which date is
  1907. * highlighted when using keyboard navigation.
  1908. * @return {?}
  1909. */
  1910. function () { return this._clampedActiveDate; },
  1911. set: /**
  1912. * @param {?} value
  1913. * @return {?}
  1914. */
  1915. function (value) {
  1916. this._clampedActiveDate = this._dateAdapter.clampDate(value, this.minDate, this.maxDate);
  1917. this.stateChanges.next();
  1918. this._changeDetectorRef.markForCheck();
  1919. },
  1920. enumerable: true,
  1921. configurable: true
  1922. });
  1923. Object.defineProperty(MatCalendar.prototype, "currentView", {
  1924. /** Whether the calendar is in month view. */
  1925. get: /**
  1926. * Whether the calendar is in month view.
  1927. * @return {?}
  1928. */
  1929. function () { return this._currentView; },
  1930. set: /**
  1931. * @param {?} value
  1932. * @return {?}
  1933. */
  1934. function (value) {
  1935. this._currentView = value;
  1936. this._moveFocusOnNextTick = true;
  1937. this._changeDetectorRef.markForCheck();
  1938. },
  1939. enumerable: true,
  1940. configurable: true
  1941. });
  1942. /**
  1943. * @return {?}
  1944. */
  1945. MatCalendar.prototype.ngAfterContentInit = /**
  1946. * @return {?}
  1947. */
  1948. function () {
  1949. this._calendarHeaderPortal = new ComponentPortal(this.headerComponent || MatCalendarHeader);
  1950. this.activeDate = this.startAt || this._dateAdapter.today();
  1951. // Assign to the private property since we don't want to move focus on init.
  1952. this._currentView = this.startView;
  1953. };
  1954. /**
  1955. * @return {?}
  1956. */
  1957. MatCalendar.prototype.ngAfterViewChecked = /**
  1958. * @return {?}
  1959. */
  1960. function () {
  1961. if (this._moveFocusOnNextTick) {
  1962. this._moveFocusOnNextTick = false;
  1963. this.focusActiveCell();
  1964. }
  1965. };
  1966. /**
  1967. * @return {?}
  1968. */
  1969. MatCalendar.prototype.ngOnDestroy = /**
  1970. * @return {?}
  1971. */
  1972. function () {
  1973. this._intlChanges.unsubscribe();
  1974. this.stateChanges.complete();
  1975. };
  1976. /**
  1977. * @param {?} changes
  1978. * @return {?}
  1979. */
  1980. MatCalendar.prototype.ngOnChanges = /**
  1981. * @param {?} changes
  1982. * @return {?}
  1983. */
  1984. function (changes) {
  1985. /** @type {?} */
  1986. var change = changes['minDate'] || changes['maxDate'] || changes['dateFilter'];
  1987. if (change && !change.firstChange) {
  1988. /** @type {?} */
  1989. var view = this._getCurrentViewComponent();
  1990. if (view) {
  1991. // We need to `detectChanges` manually here, because the `minDate`, `maxDate` etc. are
  1992. // passed down to the view via data bindings which won't be up-to-date when we call `_init`.
  1993. this._changeDetectorRef.detectChanges();
  1994. view._init();
  1995. }
  1996. }
  1997. this.stateChanges.next();
  1998. };
  1999. /**
  2000. * @return {?}
  2001. */
  2002. MatCalendar.prototype.focusActiveCell = /**
  2003. * @return {?}
  2004. */
  2005. function () {
  2006. this._getCurrentViewComponent()._focusActiveCell();
  2007. };
  2008. /** Updates today's date after an update of the active date */
  2009. /**
  2010. * Updates today's date after an update of the active date
  2011. * @return {?}
  2012. */
  2013. MatCalendar.prototype.updateTodaysDate = /**
  2014. * Updates today's date after an update of the active date
  2015. * @return {?}
  2016. */
  2017. function () {
  2018. /** @type {?} */
  2019. var view = this.currentView == 'month' ? this.monthView :
  2020. (this.currentView == 'year' ? this.yearView : this.multiYearView);
  2021. view.ngAfterContentInit();
  2022. };
  2023. /** Handles date selection in the month view. */
  2024. /**
  2025. * Handles date selection in the month view.
  2026. * @param {?} date
  2027. * @return {?}
  2028. */
  2029. MatCalendar.prototype._dateSelected = /**
  2030. * Handles date selection in the month view.
  2031. * @param {?} date
  2032. * @return {?}
  2033. */
  2034. function (date) {
  2035. if (!this._dateAdapter.sameDate(date, this.selected)) {
  2036. this.selectedChange.emit(date);
  2037. }
  2038. };
  2039. /** Handles year selection in the multiyear view. */
  2040. /**
  2041. * Handles year selection in the multiyear view.
  2042. * @param {?} normalizedYear
  2043. * @return {?}
  2044. */
  2045. MatCalendar.prototype._yearSelectedInMultiYearView = /**
  2046. * Handles year selection in the multiyear view.
  2047. * @param {?} normalizedYear
  2048. * @return {?}
  2049. */
  2050. function (normalizedYear) {
  2051. this.yearSelected.emit(normalizedYear);
  2052. };
  2053. /** Handles month selection in the year view. */
  2054. /**
  2055. * Handles month selection in the year view.
  2056. * @param {?} normalizedMonth
  2057. * @return {?}
  2058. */
  2059. MatCalendar.prototype._monthSelectedInYearView = /**
  2060. * Handles month selection in the year view.
  2061. * @param {?} normalizedMonth
  2062. * @return {?}
  2063. */
  2064. function (normalizedMonth) {
  2065. this.monthSelected.emit(normalizedMonth);
  2066. };
  2067. /**
  2068. * @return {?}
  2069. */
  2070. MatCalendar.prototype._userSelected = /**
  2071. * @return {?}
  2072. */
  2073. function () {
  2074. this._userSelection.emit();
  2075. };
  2076. /** Handles year/month selection in the multi-year/year views. */
  2077. /**
  2078. * Handles year/month selection in the multi-year/year views.
  2079. * @param {?} date
  2080. * @param {?} view
  2081. * @return {?}
  2082. */
  2083. MatCalendar.prototype._goToDateInView = /**
  2084. * Handles year/month selection in the multi-year/year views.
  2085. * @param {?} date
  2086. * @param {?} view
  2087. * @return {?}
  2088. */
  2089. function (date, view) {
  2090. this.activeDate = date;
  2091. this.currentView = view;
  2092. };
  2093. /**
  2094. * @param obj The object to check.
  2095. * @returns The given object if it is both a date instance and valid, otherwise null.
  2096. */
  2097. /**
  2098. * @private
  2099. * @param {?} obj The object to check.
  2100. * @return {?} The given object if it is both a date instance and valid, otherwise null.
  2101. */
  2102. MatCalendar.prototype._getValidDateOrNull = /**
  2103. * @private
  2104. * @param {?} obj The object to check.
  2105. * @return {?} The given object if it is both a date instance and valid, otherwise null.
  2106. */
  2107. function (obj) {
  2108. return (this._dateAdapter.isDateInstance(obj) && this._dateAdapter.isValid(obj)) ? obj : null;
  2109. };
  2110. /** Returns the component instance that corresponds to the current calendar view. */
  2111. /**
  2112. * Returns the component instance that corresponds to the current calendar view.
  2113. * @private
  2114. * @return {?}
  2115. */
  2116. MatCalendar.prototype._getCurrentViewComponent = /**
  2117. * Returns the component instance that corresponds to the current calendar view.
  2118. * @private
  2119. * @return {?}
  2120. */
  2121. function () {
  2122. return this.monthView || this.yearView || this.multiYearView;
  2123. };
  2124. MatCalendar.decorators = [
  2125. { type: Component, args: [{selector: 'mat-calendar',
  2126. template: "<ng-template [cdkPortalOutlet]=\"_calendarHeaderPortal\"></ng-template><div class=\"mat-calendar-content\" [ngSwitch]=\"currentView\" cdkMonitorSubtreeFocus tabindex=\"-1\"><mat-month-view *ngSwitchCase=\"'month'\" [(activeDate)]=\"activeDate\" [selected]=\"selected\" [dateFilter]=\"dateFilter\" [maxDate]=\"maxDate\" [minDate]=\"minDate\" [dateClass]=\"dateClass\" (selectedChange)=\"_dateSelected($event)\" (_userSelection)=\"_userSelected()\"></mat-month-view><mat-year-view *ngSwitchCase=\"'year'\" [(activeDate)]=\"activeDate\" [selected]=\"selected\" [dateFilter]=\"dateFilter\" [maxDate]=\"maxDate\" [minDate]=\"minDate\" (monthSelected)=\"_monthSelectedInYearView($event)\" (selectedChange)=\"_goToDateInView($event, 'month')\"></mat-year-view><mat-multi-year-view *ngSwitchCase=\"'multi-year'\" [(activeDate)]=\"activeDate\" [selected]=\"selected\" [dateFilter]=\"dateFilter\" [maxDate]=\"maxDate\" [minDate]=\"minDate\" (yearSelected)=\"_yearSelectedInMultiYearView($event)\" (selectedChange)=\"_goToDateInView($event, 'year')\"></mat-multi-year-view></div>",
  2127. styles: [".mat-calendar{display:block}.mat-calendar-header{padding:8px 8px 0 8px}.mat-calendar-content{padding:0 8px 8px 8px;outline:0}.mat-calendar-controls{display:flex;margin:5% calc(33% / 7 - 16px)}.mat-calendar-spacer{flex:1 1 auto}.mat-calendar-period-button{min-width:0}.mat-calendar-arrow{display:inline-block;width:0;height:0;border-left:5px solid transparent;border-right:5px solid transparent;border-top-width:5px;border-top-style:solid;margin:0 0 0 5px;vertical-align:middle}.mat-calendar-arrow.mat-calendar-invert{transform:rotate(180deg)}[dir=rtl] .mat-calendar-arrow{margin:0 5px 0 0}.mat-calendar-next-button,.mat-calendar-previous-button{position:relative}.mat-calendar-next-button::after,.mat-calendar-previous-button::after{top:0;left:0;right:0;bottom:0;position:absolute;content:'';margin:15.5px;border:0 solid currentColor;border-top-width:2px}[dir=rtl] .mat-calendar-next-button,[dir=rtl] .mat-calendar-previous-button{transform:rotate(180deg)}.mat-calendar-previous-button::after{border-left-width:2px;transform:translateX(2px) rotate(-45deg)}.mat-calendar-next-button::after{border-right-width:2px;transform:translateX(-2px) rotate(45deg)}.mat-calendar-table{border-spacing:0;border-collapse:collapse;width:100%}.mat-calendar-table-header th{text-align:center;padding:0 0 8px 0}.mat-calendar-table-header-divider{position:relative;height:1px}.mat-calendar-table-header-divider::after{content:'';position:absolute;top:0;left:-8px;right:-8px;height:1px}"],
  2128. host: {
  2129. 'class': 'mat-calendar',
  2130. },
  2131. exportAs: 'matCalendar',
  2132. encapsulation: ViewEncapsulation.None,
  2133. changeDetection: ChangeDetectionStrategy.OnPush,
  2134. },] },
  2135. ];
  2136. /** @nocollapse */
  2137. MatCalendar.ctorParameters = function () { return [
  2138. { type: MatDatepickerIntl },
  2139. { type: DateAdapter, decorators: [{ type: Optional }] },
  2140. { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [MAT_DATE_FORMATS,] }] },
  2141. { type: ChangeDetectorRef }
  2142. ]; };
  2143. MatCalendar.propDecorators = {
  2144. headerComponent: [{ type: Input }],
  2145. startAt: [{ type: Input }],
  2146. startView: [{ type: Input }],
  2147. selected: [{ type: Input }],
  2148. minDate: [{ type: Input }],
  2149. maxDate: [{ type: Input }],
  2150. dateFilter: [{ type: Input }],
  2151. dateClass: [{ type: Input }],
  2152. selectedChange: [{ type: Output }],
  2153. yearSelected: [{ type: Output }],
  2154. monthSelected: [{ type: Output }],
  2155. _userSelection: [{ type: Output }],
  2156. monthView: [{ type: ViewChild, args: [MatMonthView, { static: false },] }],
  2157. yearView: [{ type: ViewChild, args: [MatYearView, { static: false },] }],
  2158. multiYearView: [{ type: ViewChild, args: [MatMultiYearView, { static: false },] }]
  2159. };
  2160. return MatCalendar;
  2161. }());
  2162. /**
  2163. * @fileoverview added by tsickle
  2164. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2165. */
  2166. /**
  2167. * Animations used by the Material datepicker.
  2168. * \@docs-private
  2169. * @type {?}
  2170. */
  2171. var matDatepickerAnimations = {
  2172. /**
  2173. * Transforms the height of the datepicker's calendar.
  2174. */
  2175. transformPanel: trigger('transformPanel', [
  2176. state('void', style({
  2177. opacity: 0,
  2178. transform: 'scale(1, 0.8)'
  2179. })),
  2180. transition('void => enter', animate('120ms cubic-bezier(0, 0, 0.2, 1)', style({
  2181. opacity: 1,
  2182. transform: 'scale(1, 1)'
  2183. }))),
  2184. transition('* => void', animate('100ms linear', style({ opacity: 0 })))
  2185. ]),
  2186. /**
  2187. * Fades in the content of the calendar.
  2188. */
  2189. fadeInCalendar: trigger('fadeInCalendar', [
  2190. state('void', style({ opacity: 0 })),
  2191. state('enter', style({ opacity: 1 })),
  2192. // TODO(crisbeto): this animation should be removed since it isn't quite on spec, but we
  2193. // need to keep it until #12440 gets in, otherwise the exit animation will look glitchy.
  2194. transition('void => *', animate('120ms 100ms cubic-bezier(0.55, 0, 0.55, 0.2)'))
  2195. ])
  2196. };
  2197. /**
  2198. * @fileoverview added by tsickle
  2199. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2200. */
  2201. /**
  2202. * Used to generate a unique ID for each datepicker instance.
  2203. * @type {?}
  2204. */
  2205. var datepickerUid = 0;
  2206. /**
  2207. * Injection token that determines the scroll handling while the calendar is open.
  2208. * @type {?}
  2209. */
  2210. var MAT_DATEPICKER_SCROLL_STRATEGY = new InjectionToken('mat-datepicker-scroll-strategy');
  2211. /**
  2212. * \@docs-private
  2213. * @param {?} overlay
  2214. * @return {?}
  2215. */
  2216. function MAT_DATEPICKER_SCROLL_STRATEGY_FACTORY(overlay) {
  2217. return (/**
  2218. * @return {?}
  2219. */
  2220. function () { return overlay.scrollStrategies.reposition(); });
  2221. }
  2222. /**
  2223. * \@docs-private
  2224. * @type {?}
  2225. */
  2226. var MAT_DATEPICKER_SCROLL_STRATEGY_FACTORY_PROVIDER = {
  2227. provide: MAT_DATEPICKER_SCROLL_STRATEGY,
  2228. deps: [Overlay],
  2229. useFactory: MAT_DATEPICKER_SCROLL_STRATEGY_FACTORY,
  2230. };
  2231. // Boilerplate for applying mixins to MatDatepickerContent.
  2232. /**
  2233. * \@docs-private
  2234. */
  2235. var
  2236. // Boilerplate for applying mixins to MatDatepickerContent.
  2237. /**
  2238. * \@docs-private
  2239. */
  2240. MatDatepickerContentBase = /** @class */ (function () {
  2241. function MatDatepickerContentBase(_elementRef) {
  2242. this._elementRef = _elementRef;
  2243. }
  2244. return MatDatepickerContentBase;
  2245. }());
  2246. /** @type {?} */
  2247. var _MatDatepickerContentMixinBase = mixinColor(MatDatepickerContentBase);
  2248. /**
  2249. * Component used as the content for the datepicker dialog and popup. We use this instead of using
  2250. * MatCalendar directly as the content so we can control the initial focus. This also gives us a
  2251. * place to put additional features of the popup that are not part of the calendar itself in the
  2252. * future. (e.g. confirmation buttons).
  2253. * \@docs-private
  2254. * @template D
  2255. */
  2256. var MatDatepickerContent = /** @class */ (function (_super) {
  2257. __extends(MatDatepickerContent, _super);
  2258. function MatDatepickerContent(elementRef) {
  2259. return _super.call(this, elementRef) || this;
  2260. }
  2261. /**
  2262. * @return {?}
  2263. */
  2264. MatDatepickerContent.prototype.ngAfterViewInit = /**
  2265. * @return {?}
  2266. */
  2267. function () {
  2268. this._calendar.focusActiveCell();
  2269. };
  2270. MatDatepickerContent.decorators = [
  2271. { type: Component, args: [{selector: 'mat-datepicker-content',
  2272. template: "<mat-calendar cdkTrapFocus [id]=\"datepicker.id\" [ngClass]=\"datepicker.panelClass\" [startAt]=\"datepicker.startAt\" [startView]=\"datepicker.startView\" [minDate]=\"datepicker._minDate\" [maxDate]=\"datepicker._maxDate\" [dateFilter]=\"datepicker._dateFilter\" [headerComponent]=\"datepicker.calendarHeaderComponent\" [selected]=\"datepicker._selected\" [dateClass]=\"datepicker.dateClass\" [@fadeInCalendar]=\"'enter'\" (selectedChange)=\"datepicker.select($event)\" (yearSelected)=\"datepicker._selectYear($event)\" (monthSelected)=\"datepicker._selectMonth($event)\" (_userSelection)=\"datepicker.close()\"></mat-calendar>",
  2273. styles: [".mat-datepicker-content{display:block;border-radius:4px}.mat-datepicker-content .mat-calendar{width:296px;height:354px}.mat-datepicker-content-touch{display:block;max-height:80vh;overflow:auto;margin:-24px}.mat-datepicker-content-touch .mat-calendar{min-width:250px;min-height:312px;max-width:750px;max-height:788px}@media all and (orientation:landscape){.mat-datepicker-content-touch .mat-calendar{width:64vh;height:80vh}}@media all and (orientation:portrait){.mat-datepicker-content-touch .mat-calendar{width:80vw;height:100vw}}"],
  2274. host: {
  2275. 'class': 'mat-datepicker-content',
  2276. '[@transformPanel]': '"enter"',
  2277. '[class.mat-datepicker-content-touch]': 'datepicker.touchUi',
  2278. },
  2279. animations: [
  2280. matDatepickerAnimations.transformPanel,
  2281. matDatepickerAnimations.fadeInCalendar,
  2282. ],
  2283. exportAs: 'matDatepickerContent',
  2284. encapsulation: ViewEncapsulation.None,
  2285. changeDetection: ChangeDetectionStrategy.OnPush,
  2286. inputs: ['color'],
  2287. },] },
  2288. ];
  2289. /** @nocollapse */
  2290. MatDatepickerContent.ctorParameters = function () { return [
  2291. { type: ElementRef }
  2292. ]; };
  2293. MatDatepickerContent.propDecorators = {
  2294. _calendar: [{ type: ViewChild, args: [MatCalendar, { static: false },] }]
  2295. };
  2296. return MatDatepickerContent;
  2297. }(_MatDatepickerContentMixinBase));
  2298. // TODO(mmalerba): We use a component instead of a directive here so the user can use implicit
  2299. // template reference variables (e.g. #d vs #d="matDatepicker"). We can change this to a directive
  2300. // if angular adds support for `exportAs: '$implicit'` on directives.
  2301. /**
  2302. * Component responsible for managing the datepicker popup/dialog.
  2303. * @template D
  2304. */
  2305. var MatDatepicker = /** @class */ (function () {
  2306. function MatDatepicker(_dialog, _overlay, _ngZone, _viewContainerRef, scrollStrategy, _dateAdapter, _dir, _document) {
  2307. this._dialog = _dialog;
  2308. this._overlay = _overlay;
  2309. this._ngZone = _ngZone;
  2310. this._viewContainerRef = _viewContainerRef;
  2311. this._dateAdapter = _dateAdapter;
  2312. this._dir = _dir;
  2313. this._document = _document;
  2314. /**
  2315. * The view that the calendar should start in.
  2316. */
  2317. this.startView = 'month';
  2318. this._touchUi = false;
  2319. /**
  2320. * Emits selected year in multiyear view.
  2321. * This doesn't imply a change on the selected date.
  2322. */
  2323. this.yearSelected = new EventEmitter();
  2324. /**
  2325. * Emits selected month in year view.
  2326. * This doesn't imply a change on the selected date.
  2327. */
  2328. this.monthSelected = new EventEmitter();
  2329. /**
  2330. * Emits when the datepicker has been opened.
  2331. */
  2332. this.openedStream = new EventEmitter();
  2333. /**
  2334. * Emits when the datepicker has been closed.
  2335. */
  2336. this.closedStream = new EventEmitter();
  2337. this._opened = false;
  2338. /**
  2339. * The id for the datepicker calendar.
  2340. */
  2341. this.id = "mat-datepicker-" + datepickerUid++;
  2342. this._validSelected = null;
  2343. /**
  2344. * The element that was focused before the datepicker was opened.
  2345. */
  2346. this._focusedElementBeforeOpen = null;
  2347. /**
  2348. * Subscription to value changes in the associated input element.
  2349. */
  2350. this._inputSubscription = Subscription.EMPTY;
  2351. /**
  2352. * Emits when the datepicker is disabled.
  2353. */
  2354. this._disabledChange = new Subject();
  2355. /**
  2356. * Emits new selected date when selected date changes.
  2357. */
  2358. this._selectedChanged = new Subject();
  2359. if (!this._dateAdapter) {
  2360. throw createMissingDateImplError('DateAdapter');
  2361. }
  2362. this._scrollStrategy = scrollStrategy;
  2363. }
  2364. Object.defineProperty(MatDatepicker.prototype, "startAt", {
  2365. /** The date to open the calendar to initially. */
  2366. get: /**
  2367. * The date to open the calendar to initially.
  2368. * @return {?}
  2369. */
  2370. function () {
  2371. // If an explicit startAt is set we start there, otherwise we start at whatever the currently
  2372. // selected value is.
  2373. return this._startAt || (this._datepickerInput ? this._datepickerInput.value : null);
  2374. },
  2375. set: /**
  2376. * @param {?} value
  2377. * @return {?}
  2378. */
  2379. function (value) {
  2380. this._startAt = this._getValidDateOrNull(this._dateAdapter.deserialize(value));
  2381. },
  2382. enumerable: true,
  2383. configurable: true
  2384. });
  2385. Object.defineProperty(MatDatepicker.prototype, "color", {
  2386. /** Color palette to use on the datepicker's calendar. */
  2387. get: /**
  2388. * Color palette to use on the datepicker's calendar.
  2389. * @return {?}
  2390. */
  2391. function () {
  2392. return this._color ||
  2393. (this._datepickerInput ? this._datepickerInput._getThemePalette() : undefined);
  2394. },
  2395. set: /**
  2396. * @param {?} value
  2397. * @return {?}
  2398. */
  2399. function (value) {
  2400. this._color = value;
  2401. },
  2402. enumerable: true,
  2403. configurable: true
  2404. });
  2405. Object.defineProperty(MatDatepicker.prototype, "touchUi", {
  2406. /**
  2407. * Whether the calendar UI is in touch mode. In touch mode the calendar opens in a dialog rather
  2408. * than a popup and elements have more padding to allow for bigger touch targets.
  2409. */
  2410. get: /**
  2411. * Whether the calendar UI is in touch mode. In touch mode the calendar opens in a dialog rather
  2412. * than a popup and elements have more padding to allow for bigger touch targets.
  2413. * @return {?}
  2414. */
  2415. function () { return this._touchUi; },
  2416. set: /**
  2417. * @param {?} value
  2418. * @return {?}
  2419. */
  2420. function (value) {
  2421. this._touchUi = coerceBooleanProperty(value);
  2422. },
  2423. enumerable: true,
  2424. configurable: true
  2425. });
  2426. Object.defineProperty(MatDatepicker.prototype, "disabled", {
  2427. /** Whether the datepicker pop-up should be disabled. */
  2428. get: /**
  2429. * Whether the datepicker pop-up should be disabled.
  2430. * @return {?}
  2431. */
  2432. function () {
  2433. return this._disabled === undefined && this._datepickerInput ?
  2434. this._datepickerInput.disabled : !!this._disabled;
  2435. },
  2436. set: /**
  2437. * @param {?} value
  2438. * @return {?}
  2439. */
  2440. function (value) {
  2441. /** @type {?} */
  2442. var newValue = coerceBooleanProperty(value);
  2443. if (newValue !== this._disabled) {
  2444. this._disabled = newValue;
  2445. this._disabledChange.next(newValue);
  2446. }
  2447. },
  2448. enumerable: true,
  2449. configurable: true
  2450. });
  2451. Object.defineProperty(MatDatepicker.prototype, "opened", {
  2452. /** Whether the calendar is open. */
  2453. get: /**
  2454. * Whether the calendar is open.
  2455. * @return {?}
  2456. */
  2457. function () { return this._opened; },
  2458. set: /**
  2459. * @param {?} value
  2460. * @return {?}
  2461. */
  2462. function (value) { value ? this.open() : this.close(); },
  2463. enumerable: true,
  2464. configurable: true
  2465. });
  2466. Object.defineProperty(MatDatepicker.prototype, "_selected", {
  2467. /** The currently selected date. */
  2468. get: /**
  2469. * The currently selected date.
  2470. * @return {?}
  2471. */
  2472. function () { return this._validSelected; },
  2473. set: /**
  2474. * @param {?} value
  2475. * @return {?}
  2476. */
  2477. function (value) { this._validSelected = value; },
  2478. enumerable: true,
  2479. configurable: true
  2480. });
  2481. Object.defineProperty(MatDatepicker.prototype, "_minDate", {
  2482. /** The minimum selectable date. */
  2483. get: /**
  2484. * The minimum selectable date.
  2485. * @return {?}
  2486. */
  2487. function () {
  2488. return this._datepickerInput && this._datepickerInput.min;
  2489. },
  2490. enumerable: true,
  2491. configurable: true
  2492. });
  2493. Object.defineProperty(MatDatepicker.prototype, "_maxDate", {
  2494. /** The maximum selectable date. */
  2495. get: /**
  2496. * The maximum selectable date.
  2497. * @return {?}
  2498. */
  2499. function () {
  2500. return this._datepickerInput && this._datepickerInput.max;
  2501. },
  2502. enumerable: true,
  2503. configurable: true
  2504. });
  2505. Object.defineProperty(MatDatepicker.prototype, "_dateFilter", {
  2506. get: /**
  2507. * @return {?}
  2508. */
  2509. function () {
  2510. return this._datepickerInput && this._datepickerInput._dateFilter;
  2511. },
  2512. enumerable: true,
  2513. configurable: true
  2514. });
  2515. /**
  2516. * @return {?}
  2517. */
  2518. MatDatepicker.prototype.ngOnDestroy = /**
  2519. * @return {?}
  2520. */
  2521. function () {
  2522. this.close();
  2523. this._inputSubscription.unsubscribe();
  2524. this._disabledChange.complete();
  2525. if (this._popupRef) {
  2526. this._popupRef.dispose();
  2527. this._popupComponentRef = null;
  2528. }
  2529. };
  2530. /** Selects the given date */
  2531. /**
  2532. * Selects the given date
  2533. * @param {?} date
  2534. * @return {?}
  2535. */
  2536. MatDatepicker.prototype.select = /**
  2537. * Selects the given date
  2538. * @param {?} date
  2539. * @return {?}
  2540. */
  2541. function (date) {
  2542. /** @type {?} */
  2543. var oldValue = this._selected;
  2544. this._selected = date;
  2545. if (!this._dateAdapter.sameDate(oldValue, this._selected)) {
  2546. this._selectedChanged.next(date);
  2547. }
  2548. };
  2549. /** Emits the selected year in multiyear view */
  2550. /**
  2551. * Emits the selected year in multiyear view
  2552. * @param {?} normalizedYear
  2553. * @return {?}
  2554. */
  2555. MatDatepicker.prototype._selectYear = /**
  2556. * Emits the selected year in multiyear view
  2557. * @param {?} normalizedYear
  2558. * @return {?}
  2559. */
  2560. function (normalizedYear) {
  2561. this.yearSelected.emit(normalizedYear);
  2562. };
  2563. /** Emits selected month in year view */
  2564. /**
  2565. * Emits selected month in year view
  2566. * @param {?} normalizedMonth
  2567. * @return {?}
  2568. */
  2569. MatDatepicker.prototype._selectMonth = /**
  2570. * Emits selected month in year view
  2571. * @param {?} normalizedMonth
  2572. * @return {?}
  2573. */
  2574. function (normalizedMonth) {
  2575. this.monthSelected.emit(normalizedMonth);
  2576. };
  2577. /**
  2578. * Register an input with this datepicker.
  2579. * @param input The datepicker input to register with this datepicker.
  2580. */
  2581. /**
  2582. * Register an input with this datepicker.
  2583. * @param {?} input The datepicker input to register with this datepicker.
  2584. * @return {?}
  2585. */
  2586. MatDatepicker.prototype._registerInput = /**
  2587. * Register an input with this datepicker.
  2588. * @param {?} input The datepicker input to register with this datepicker.
  2589. * @return {?}
  2590. */
  2591. function (input) {
  2592. var _this = this;
  2593. if (this._datepickerInput) {
  2594. throw Error('A MatDatepicker can only be associated with a single input.');
  2595. }
  2596. this._datepickerInput = input;
  2597. this._inputSubscription =
  2598. this._datepickerInput._valueChange.subscribe((/**
  2599. * @param {?} value
  2600. * @return {?}
  2601. */
  2602. function (value) { return _this._selected = value; }));
  2603. };
  2604. /** Open the calendar. */
  2605. /**
  2606. * Open the calendar.
  2607. * @return {?}
  2608. */
  2609. MatDatepicker.prototype.open = /**
  2610. * Open the calendar.
  2611. * @return {?}
  2612. */
  2613. function () {
  2614. if (this._opened || this.disabled) {
  2615. return;
  2616. }
  2617. if (!this._datepickerInput) {
  2618. throw Error('Attempted to open an MatDatepicker with no associated input.');
  2619. }
  2620. if (this._document) {
  2621. this._focusedElementBeforeOpen = this._document.activeElement;
  2622. }
  2623. this.touchUi ? this._openAsDialog() : this._openAsPopup();
  2624. this._opened = true;
  2625. this.openedStream.emit();
  2626. };
  2627. /** Close the calendar. */
  2628. /**
  2629. * Close the calendar.
  2630. * @return {?}
  2631. */
  2632. MatDatepicker.prototype.close = /**
  2633. * Close the calendar.
  2634. * @return {?}
  2635. */
  2636. function () {
  2637. var _this = this;
  2638. if (!this._opened) {
  2639. return;
  2640. }
  2641. if (this._popupRef && this._popupRef.hasAttached()) {
  2642. this._popupRef.detach();
  2643. }
  2644. if (this._dialogRef) {
  2645. this._dialogRef.close();
  2646. this._dialogRef = null;
  2647. }
  2648. if (this._calendarPortal && this._calendarPortal.isAttached) {
  2649. this._calendarPortal.detach();
  2650. }
  2651. /** @type {?} */
  2652. var completeClose = (/**
  2653. * @return {?}
  2654. */
  2655. function () {
  2656. // The `_opened` could've been reset already if
  2657. // we got two events in quick succession.
  2658. if (_this._opened) {
  2659. _this._opened = false;
  2660. _this.closedStream.emit();
  2661. _this._focusedElementBeforeOpen = null;
  2662. }
  2663. });
  2664. if (this._focusedElementBeforeOpen &&
  2665. typeof this._focusedElementBeforeOpen.focus === 'function') {
  2666. // Because IE moves focus asynchronously, we can't count on it being restored before we've
  2667. // marked the datepicker as closed. If the event fires out of sequence and the element that
  2668. // we're refocusing opens the datepicker on focus, the user could be stuck with not being
  2669. // able to close the calendar at all. We work around it by making the logic, that marks
  2670. // the datepicker as closed, async as well.
  2671. this._focusedElementBeforeOpen.focus();
  2672. setTimeout(completeClose);
  2673. }
  2674. else {
  2675. completeClose();
  2676. }
  2677. };
  2678. /** Open the calendar as a dialog. */
  2679. /**
  2680. * Open the calendar as a dialog.
  2681. * @private
  2682. * @return {?}
  2683. */
  2684. MatDatepicker.prototype._openAsDialog = /**
  2685. * Open the calendar as a dialog.
  2686. * @private
  2687. * @return {?}
  2688. */
  2689. function () {
  2690. var _this = this;
  2691. // Usually this would be handled by `open` which ensures that we can only have one overlay
  2692. // open at a time, however since we reset the variables in async handlers some overlays
  2693. // may slip through if the user opens and closes multiple times in quick succession (e.g.
  2694. // by holding down the enter key).
  2695. if (this._dialogRef) {
  2696. this._dialogRef.close();
  2697. }
  2698. this._dialogRef = this._dialog.open(MatDatepickerContent, {
  2699. direction: this._dir ? this._dir.value : 'ltr',
  2700. viewContainerRef: this._viewContainerRef,
  2701. panelClass: 'mat-datepicker-dialog',
  2702. });
  2703. this._dialogRef.afterClosed().subscribe((/**
  2704. * @return {?}
  2705. */
  2706. function () { return _this.close(); }));
  2707. this._dialogRef.componentInstance.datepicker = this;
  2708. this._setColor();
  2709. };
  2710. /** Open the calendar as a popup. */
  2711. /**
  2712. * Open the calendar as a popup.
  2713. * @private
  2714. * @return {?}
  2715. */
  2716. MatDatepicker.prototype._openAsPopup = /**
  2717. * Open the calendar as a popup.
  2718. * @private
  2719. * @return {?}
  2720. */
  2721. function () {
  2722. var _this = this;
  2723. if (!this._calendarPortal) {
  2724. this._calendarPortal = new ComponentPortal(MatDatepickerContent, this._viewContainerRef);
  2725. }
  2726. if (!this._popupRef) {
  2727. this._createPopup();
  2728. }
  2729. if (!this._popupRef.hasAttached()) {
  2730. this._popupComponentRef = this._popupRef.attach(this._calendarPortal);
  2731. this._popupComponentRef.instance.datepicker = this;
  2732. this._setColor();
  2733. // Update the position once the calendar has rendered.
  2734. this._ngZone.onStable.asObservable().pipe(take(1)).subscribe((/**
  2735. * @return {?}
  2736. */
  2737. function () {
  2738. _this._popupRef.updatePosition();
  2739. }));
  2740. }
  2741. };
  2742. /** Create the popup. */
  2743. /**
  2744. * Create the popup.
  2745. * @private
  2746. * @return {?}
  2747. */
  2748. MatDatepicker.prototype._createPopup = /**
  2749. * Create the popup.
  2750. * @private
  2751. * @return {?}
  2752. */
  2753. function () {
  2754. var _this = this;
  2755. /** @type {?} */
  2756. var overlayConfig = new OverlayConfig({
  2757. positionStrategy: this._createPopupPositionStrategy(),
  2758. hasBackdrop: true,
  2759. backdropClass: 'mat-overlay-transparent-backdrop',
  2760. direction: this._dir,
  2761. scrollStrategy: this._scrollStrategy(),
  2762. panelClass: 'mat-datepicker-popup',
  2763. });
  2764. this._popupRef = this._overlay.create(overlayConfig);
  2765. this._popupRef.overlayElement.setAttribute('role', 'dialog');
  2766. merge(this._popupRef.backdropClick(), this._popupRef.detachments(), this._popupRef.keydownEvents().pipe(filter((/**
  2767. * @param {?} event
  2768. * @return {?}
  2769. */
  2770. function (event) {
  2771. // Closing on alt + up is only valid when there's an input associated with the datepicker.
  2772. return event.keyCode === ESCAPE ||
  2773. (_this._datepickerInput && event.altKey && event.keyCode === UP_ARROW);
  2774. })))).subscribe((/**
  2775. * @param {?} event
  2776. * @return {?}
  2777. */
  2778. function (event) {
  2779. if (event) {
  2780. event.preventDefault();
  2781. }
  2782. _this.close();
  2783. }));
  2784. };
  2785. /** Create the popup PositionStrategy. */
  2786. /**
  2787. * Create the popup PositionStrategy.
  2788. * @private
  2789. * @return {?}
  2790. */
  2791. MatDatepicker.prototype._createPopupPositionStrategy = /**
  2792. * Create the popup PositionStrategy.
  2793. * @private
  2794. * @return {?}
  2795. */
  2796. function () {
  2797. return this._overlay.position()
  2798. .flexibleConnectedTo(this._datepickerInput.getConnectedOverlayOrigin())
  2799. .withTransformOriginOn('.mat-datepicker-content')
  2800. .withFlexibleDimensions(false)
  2801. .withViewportMargin(8)
  2802. .withLockedPosition()
  2803. .withPositions([
  2804. {
  2805. originX: 'start',
  2806. originY: 'bottom',
  2807. overlayX: 'start',
  2808. overlayY: 'top'
  2809. },
  2810. {
  2811. originX: 'start',
  2812. originY: 'top',
  2813. overlayX: 'start',
  2814. overlayY: 'bottom'
  2815. },
  2816. {
  2817. originX: 'end',
  2818. originY: 'bottom',
  2819. overlayX: 'end',
  2820. overlayY: 'top'
  2821. },
  2822. {
  2823. originX: 'end',
  2824. originY: 'top',
  2825. overlayX: 'end',
  2826. overlayY: 'bottom'
  2827. }
  2828. ]);
  2829. };
  2830. /**
  2831. * @param obj The object to check.
  2832. * @returns The given object if it is both a date instance and valid, otherwise null.
  2833. */
  2834. /**
  2835. * @private
  2836. * @param {?} obj The object to check.
  2837. * @return {?} The given object if it is both a date instance and valid, otherwise null.
  2838. */
  2839. MatDatepicker.prototype._getValidDateOrNull = /**
  2840. * @private
  2841. * @param {?} obj The object to check.
  2842. * @return {?} The given object if it is both a date instance and valid, otherwise null.
  2843. */
  2844. function (obj) {
  2845. return (this._dateAdapter.isDateInstance(obj) && this._dateAdapter.isValid(obj)) ? obj : null;
  2846. };
  2847. /** Passes the current theme color along to the calendar overlay. */
  2848. /**
  2849. * Passes the current theme color along to the calendar overlay.
  2850. * @private
  2851. * @return {?}
  2852. */
  2853. MatDatepicker.prototype._setColor = /**
  2854. * Passes the current theme color along to the calendar overlay.
  2855. * @private
  2856. * @return {?}
  2857. */
  2858. function () {
  2859. /** @type {?} */
  2860. var color = this.color;
  2861. if (this._popupComponentRef) {
  2862. this._popupComponentRef.instance.color = color;
  2863. }
  2864. if (this._dialogRef) {
  2865. this._dialogRef.componentInstance.color = color;
  2866. }
  2867. };
  2868. MatDatepicker.decorators = [
  2869. { type: Component, args: [{selector: 'mat-datepicker',
  2870. template: '',
  2871. exportAs: 'matDatepicker',
  2872. changeDetection: ChangeDetectionStrategy.OnPush,
  2873. encapsulation: ViewEncapsulation.None,
  2874. },] },
  2875. ];
  2876. /** @nocollapse */
  2877. MatDatepicker.ctorParameters = function () { return [
  2878. { type: MatDialog },
  2879. { type: Overlay },
  2880. { type: NgZone },
  2881. { type: ViewContainerRef },
  2882. { type: undefined, decorators: [{ type: Inject, args: [MAT_DATEPICKER_SCROLL_STRATEGY,] }] },
  2883. { type: DateAdapter, decorators: [{ type: Optional }] },
  2884. { type: Directionality, decorators: [{ type: Optional }] },
  2885. { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [DOCUMENT,] }] }
  2886. ]; };
  2887. MatDatepicker.propDecorators = {
  2888. calendarHeaderComponent: [{ type: Input }],
  2889. startAt: [{ type: Input }],
  2890. startView: [{ type: Input }],
  2891. color: [{ type: Input }],
  2892. touchUi: [{ type: Input }],
  2893. disabled: [{ type: Input }],
  2894. yearSelected: [{ type: Output }],
  2895. monthSelected: [{ type: Output }],
  2896. panelClass: [{ type: Input }],
  2897. dateClass: [{ type: Input }],
  2898. openedStream: [{ type: Output, args: ['opened',] }],
  2899. closedStream: [{ type: Output, args: ['closed',] }],
  2900. opened: [{ type: Input }]
  2901. };
  2902. return MatDatepicker;
  2903. }());
  2904. /**
  2905. * @fileoverview added by tsickle
  2906. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2907. */
  2908. /**
  2909. * \@docs-private
  2910. * @type {?}
  2911. */
  2912. var MAT_DATEPICKER_VALUE_ACCESSOR = {
  2913. provide: NG_VALUE_ACCESSOR,
  2914. useExisting: forwardRef((/**
  2915. * @return {?}
  2916. */
  2917. function () { return MatDatepickerInput; })),
  2918. multi: true
  2919. };
  2920. /**
  2921. * \@docs-private
  2922. * @type {?}
  2923. */
  2924. var MAT_DATEPICKER_VALIDATORS = {
  2925. provide: NG_VALIDATORS,
  2926. useExisting: forwardRef((/**
  2927. * @return {?}
  2928. */
  2929. function () { return MatDatepickerInput; })),
  2930. multi: true
  2931. };
  2932. /**
  2933. * An event used for datepicker input and change events. We don't always have access to a native
  2934. * input or change event because the event may have been triggered by the user clicking on the
  2935. * calendar popup. For consistency, we always use MatDatepickerInputEvent instead.
  2936. * @template D
  2937. */
  2938. var /**
  2939. * An event used for datepicker input and change events. We don't always have access to a native
  2940. * input or change event because the event may have been triggered by the user clicking on the
  2941. * calendar popup. For consistency, we always use MatDatepickerInputEvent instead.
  2942. * @template D
  2943. */
  2944. MatDatepickerInputEvent = /** @class */ (function () {
  2945. function MatDatepickerInputEvent(target, targetElement) {
  2946. this.target = target;
  2947. this.targetElement = targetElement;
  2948. this.value = this.target.value;
  2949. }
  2950. return MatDatepickerInputEvent;
  2951. }());
  2952. /**
  2953. * Directive used to connect an input to a MatDatepicker.
  2954. * @template D
  2955. */
  2956. var MatDatepickerInput = /** @class */ (function () {
  2957. function MatDatepickerInput(_elementRef, _dateAdapter, _dateFormats, _formField) {
  2958. var _this = this;
  2959. this._elementRef = _elementRef;
  2960. this._dateAdapter = _dateAdapter;
  2961. this._dateFormats = _dateFormats;
  2962. this._formField = _formField;
  2963. /**
  2964. * Emits when a `change` event is fired on this `<input>`.
  2965. */
  2966. this.dateChange = new EventEmitter();
  2967. /**
  2968. * Emits when an `input` event is fired on this `<input>`.
  2969. */
  2970. this.dateInput = new EventEmitter();
  2971. /**
  2972. * Emits when the value changes (either due to user input or programmatic change).
  2973. */
  2974. this._valueChange = new EventEmitter();
  2975. /**
  2976. * Emits when the disabled state has changed
  2977. */
  2978. this._disabledChange = new EventEmitter();
  2979. this._onTouched = (/**
  2980. * @return {?}
  2981. */
  2982. function () { });
  2983. this._cvaOnChange = (/**
  2984. * @return {?}
  2985. */
  2986. function () { });
  2987. this._validatorOnChange = (/**
  2988. * @return {?}
  2989. */
  2990. function () { });
  2991. this._datepickerSubscription = Subscription.EMPTY;
  2992. this._localeSubscription = Subscription.EMPTY;
  2993. /**
  2994. * The form control validator for whether the input parses.
  2995. */
  2996. this._parseValidator = (/**
  2997. * @return {?}
  2998. */
  2999. function () {
  3000. return _this._lastValueValid ?
  3001. null : { 'matDatepickerParse': { 'text': _this._elementRef.nativeElement.value } };
  3002. });
  3003. /**
  3004. * The form control validator for the min date.
  3005. */
  3006. this._minValidator = (/**
  3007. * @param {?} control
  3008. * @return {?}
  3009. */
  3010. function (control) {
  3011. /** @type {?} */
  3012. var controlValue = _this._getValidDateOrNull(_this._dateAdapter.deserialize(control.value));
  3013. return (!_this.min || !controlValue ||
  3014. _this._dateAdapter.compareDate(_this.min, controlValue) <= 0) ?
  3015. null : { 'matDatepickerMin': { 'min': _this.min, 'actual': controlValue } };
  3016. });
  3017. /**
  3018. * The form control validator for the max date.
  3019. */
  3020. this._maxValidator = (/**
  3021. * @param {?} control
  3022. * @return {?}
  3023. */
  3024. function (control) {
  3025. /** @type {?} */
  3026. var controlValue = _this._getValidDateOrNull(_this._dateAdapter.deserialize(control.value));
  3027. return (!_this.max || !controlValue ||
  3028. _this._dateAdapter.compareDate(_this.max, controlValue) >= 0) ?
  3029. null : { 'matDatepickerMax': { 'max': _this.max, 'actual': controlValue } };
  3030. });
  3031. /**
  3032. * The form control validator for the date filter.
  3033. */
  3034. this._filterValidator = (/**
  3035. * @param {?} control
  3036. * @return {?}
  3037. */
  3038. function (control) {
  3039. /** @type {?} */
  3040. var controlValue = _this._getValidDateOrNull(_this._dateAdapter.deserialize(control.value));
  3041. return !_this._dateFilter || !controlValue || _this._dateFilter(controlValue) ?
  3042. null : { 'matDatepickerFilter': true };
  3043. });
  3044. /**
  3045. * The combined form control validator for this input.
  3046. */
  3047. this._validator = Validators.compose([this._parseValidator, this._minValidator, this._maxValidator, this._filterValidator]);
  3048. /**
  3049. * Whether the last value set on the input was valid.
  3050. */
  3051. this._lastValueValid = false;
  3052. if (!this._dateAdapter) {
  3053. throw createMissingDateImplError('DateAdapter');
  3054. }
  3055. if (!this._dateFormats) {
  3056. throw createMissingDateImplError('MAT_DATE_FORMATS');
  3057. }
  3058. // Update the displayed date when the locale changes.
  3059. this._localeSubscription = _dateAdapter.localeChanges.subscribe((/**
  3060. * @return {?}
  3061. */
  3062. function () {
  3063. _this.value = _this.value;
  3064. }));
  3065. }
  3066. Object.defineProperty(MatDatepickerInput.prototype, "matDatepicker", {
  3067. /** The datepicker that this input is associated with. */
  3068. set: /**
  3069. * The datepicker that this input is associated with.
  3070. * @param {?} value
  3071. * @return {?}
  3072. */
  3073. function (value) {
  3074. var _this = this;
  3075. if (!value) {
  3076. return;
  3077. }
  3078. this._datepicker = value;
  3079. this._datepicker._registerInput(this);
  3080. this._datepickerSubscription.unsubscribe();
  3081. this._datepickerSubscription = this._datepicker._selectedChanged.subscribe((/**
  3082. * @param {?} selected
  3083. * @return {?}
  3084. */
  3085. function (selected) {
  3086. _this.value = selected;
  3087. _this._cvaOnChange(selected);
  3088. _this._onTouched();
  3089. _this.dateInput.emit(new MatDatepickerInputEvent(_this, _this._elementRef.nativeElement));
  3090. _this.dateChange.emit(new MatDatepickerInputEvent(_this, _this._elementRef.nativeElement));
  3091. }));
  3092. },
  3093. enumerable: true,
  3094. configurable: true
  3095. });
  3096. Object.defineProperty(MatDatepickerInput.prototype, "matDatepickerFilter", {
  3097. /** Function that can be used to filter out dates within the datepicker. */
  3098. set: /**
  3099. * Function that can be used to filter out dates within the datepicker.
  3100. * @param {?} value
  3101. * @return {?}
  3102. */
  3103. function (value) {
  3104. this._dateFilter = value;
  3105. this._validatorOnChange();
  3106. },
  3107. enumerable: true,
  3108. configurable: true
  3109. });
  3110. Object.defineProperty(MatDatepickerInput.prototype, "value", {
  3111. /** The value of the input. */
  3112. get: /**
  3113. * The value of the input.
  3114. * @return {?}
  3115. */
  3116. function () { return this._value; },
  3117. set: /**
  3118. * @param {?} value
  3119. * @return {?}
  3120. */
  3121. function (value) {
  3122. value = this._dateAdapter.deserialize(value);
  3123. this._lastValueValid = !value || this._dateAdapter.isValid(value);
  3124. value = this._getValidDateOrNull(value);
  3125. /** @type {?} */
  3126. var oldDate = this.value;
  3127. this._value = value;
  3128. this._formatValue(value);
  3129. if (!this._dateAdapter.sameDate(oldDate, value)) {
  3130. this._valueChange.emit(value);
  3131. }
  3132. },
  3133. enumerable: true,
  3134. configurable: true
  3135. });
  3136. Object.defineProperty(MatDatepickerInput.prototype, "min", {
  3137. /** The minimum valid date. */
  3138. get: /**
  3139. * The minimum valid date.
  3140. * @return {?}
  3141. */
  3142. function () { return this._min; },
  3143. set: /**
  3144. * @param {?} value
  3145. * @return {?}
  3146. */
  3147. function (value) {
  3148. this._min = this._getValidDateOrNull(this._dateAdapter.deserialize(value));
  3149. this._validatorOnChange();
  3150. },
  3151. enumerable: true,
  3152. configurable: true
  3153. });
  3154. Object.defineProperty(MatDatepickerInput.prototype, "max", {
  3155. /** The maximum valid date. */
  3156. get: /**
  3157. * The maximum valid date.
  3158. * @return {?}
  3159. */
  3160. function () { return this._max; },
  3161. set: /**
  3162. * @param {?} value
  3163. * @return {?}
  3164. */
  3165. function (value) {
  3166. this._max = this._getValidDateOrNull(this._dateAdapter.deserialize(value));
  3167. this._validatorOnChange();
  3168. },
  3169. enumerable: true,
  3170. configurable: true
  3171. });
  3172. Object.defineProperty(MatDatepickerInput.prototype, "disabled", {
  3173. /** Whether the datepicker-input is disabled. */
  3174. get: /**
  3175. * Whether the datepicker-input is disabled.
  3176. * @return {?}
  3177. */
  3178. function () { return !!this._disabled; },
  3179. set: /**
  3180. * @param {?} value
  3181. * @return {?}
  3182. */
  3183. function (value) {
  3184. /** @type {?} */
  3185. var newValue = coerceBooleanProperty(value);
  3186. /** @type {?} */
  3187. var element = this._elementRef.nativeElement;
  3188. if (this._disabled !== newValue) {
  3189. this._disabled = newValue;
  3190. this._disabledChange.emit(newValue);
  3191. }
  3192. // We need to null check the `blur` method, because it's undefined during SSR.
  3193. if (newValue && element.blur) {
  3194. // Normally, native input elements automatically blur if they turn disabled. This behavior
  3195. // is problematic, because it would mean that it triggers another change detection cycle,
  3196. // which then causes a changed after checked error if the input element was focused before.
  3197. element.blur();
  3198. }
  3199. },
  3200. enumerable: true,
  3201. configurable: true
  3202. });
  3203. /**
  3204. * @return {?}
  3205. */
  3206. MatDatepickerInput.prototype.ngOnDestroy = /**
  3207. * @return {?}
  3208. */
  3209. function () {
  3210. this._datepickerSubscription.unsubscribe();
  3211. this._localeSubscription.unsubscribe();
  3212. this._valueChange.complete();
  3213. this._disabledChange.complete();
  3214. };
  3215. /** @docs-private */
  3216. /**
  3217. * \@docs-private
  3218. * @param {?} fn
  3219. * @return {?}
  3220. */
  3221. MatDatepickerInput.prototype.registerOnValidatorChange = /**
  3222. * \@docs-private
  3223. * @param {?} fn
  3224. * @return {?}
  3225. */
  3226. function (fn) {
  3227. this._validatorOnChange = fn;
  3228. };
  3229. /** @docs-private */
  3230. /**
  3231. * \@docs-private
  3232. * @param {?} c
  3233. * @return {?}
  3234. */
  3235. MatDatepickerInput.prototype.validate = /**
  3236. * \@docs-private
  3237. * @param {?} c
  3238. * @return {?}
  3239. */
  3240. function (c) {
  3241. return this._validator ? this._validator(c) : null;
  3242. };
  3243. /**
  3244. * @deprecated
  3245. * @breaking-change 8.0.0 Use `getConnectedOverlayOrigin` instead
  3246. */
  3247. /**
  3248. * @deprecated
  3249. * \@breaking-change 8.0.0 Use `getConnectedOverlayOrigin` instead
  3250. * @return {?}
  3251. */
  3252. MatDatepickerInput.prototype.getPopupConnectionElementRef = /**
  3253. * @deprecated
  3254. * \@breaking-change 8.0.0 Use `getConnectedOverlayOrigin` instead
  3255. * @return {?}
  3256. */
  3257. function () {
  3258. return this.getConnectedOverlayOrigin();
  3259. };
  3260. /**
  3261. * Gets the element that the datepicker popup should be connected to.
  3262. * @return The element to connect the popup to.
  3263. */
  3264. /**
  3265. * Gets the element that the datepicker popup should be connected to.
  3266. * @return {?} The element to connect the popup to.
  3267. */
  3268. MatDatepickerInput.prototype.getConnectedOverlayOrigin = /**
  3269. * Gets the element that the datepicker popup should be connected to.
  3270. * @return {?} The element to connect the popup to.
  3271. */
  3272. function () {
  3273. return this._formField ? this._formField.getConnectedOverlayOrigin() : this._elementRef;
  3274. };
  3275. // Implemented as part of ControlValueAccessor.
  3276. // Implemented as part of ControlValueAccessor.
  3277. /**
  3278. * @param {?} value
  3279. * @return {?}
  3280. */
  3281. MatDatepickerInput.prototype.writeValue =
  3282. // Implemented as part of ControlValueAccessor.
  3283. /**
  3284. * @param {?} value
  3285. * @return {?}
  3286. */
  3287. function (value) {
  3288. this.value = value;
  3289. };
  3290. // Implemented as part of ControlValueAccessor.
  3291. // Implemented as part of ControlValueAccessor.
  3292. /**
  3293. * @param {?} fn
  3294. * @return {?}
  3295. */
  3296. MatDatepickerInput.prototype.registerOnChange =
  3297. // Implemented as part of ControlValueAccessor.
  3298. /**
  3299. * @param {?} fn
  3300. * @return {?}
  3301. */
  3302. function (fn) {
  3303. this._cvaOnChange = fn;
  3304. };
  3305. // Implemented as part of ControlValueAccessor.
  3306. // Implemented as part of ControlValueAccessor.
  3307. /**
  3308. * @param {?} fn
  3309. * @return {?}
  3310. */
  3311. MatDatepickerInput.prototype.registerOnTouched =
  3312. // Implemented as part of ControlValueAccessor.
  3313. /**
  3314. * @param {?} fn
  3315. * @return {?}
  3316. */
  3317. function (fn) {
  3318. this._onTouched = fn;
  3319. };
  3320. // Implemented as part of ControlValueAccessor.
  3321. // Implemented as part of ControlValueAccessor.
  3322. /**
  3323. * @param {?} isDisabled
  3324. * @return {?}
  3325. */
  3326. MatDatepickerInput.prototype.setDisabledState =
  3327. // Implemented as part of ControlValueAccessor.
  3328. /**
  3329. * @param {?} isDisabled
  3330. * @return {?}
  3331. */
  3332. function (isDisabled) {
  3333. this.disabled = isDisabled;
  3334. };
  3335. /**
  3336. * @param {?} event
  3337. * @return {?}
  3338. */
  3339. MatDatepickerInput.prototype._onKeydown = /**
  3340. * @param {?} event
  3341. * @return {?}
  3342. */
  3343. function (event) {
  3344. /** @type {?} */
  3345. var isAltDownArrow = event.altKey && event.keyCode === DOWN_ARROW;
  3346. if (this._datepicker && isAltDownArrow && !this._elementRef.nativeElement.readOnly) {
  3347. this._datepicker.open();
  3348. event.preventDefault();
  3349. }
  3350. };
  3351. /**
  3352. * @param {?} value
  3353. * @return {?}
  3354. */
  3355. MatDatepickerInput.prototype._onInput = /**
  3356. * @param {?} value
  3357. * @return {?}
  3358. */
  3359. function (value) {
  3360. /** @type {?} */
  3361. var date = this._dateAdapter.parse(value, this._dateFormats.parse.dateInput);
  3362. this._lastValueValid = !date || this._dateAdapter.isValid(date);
  3363. date = this._getValidDateOrNull(date);
  3364. if (!this._dateAdapter.sameDate(date, this._value)) {
  3365. this._value = date;
  3366. this._cvaOnChange(date);
  3367. this._valueChange.emit(date);
  3368. this.dateInput.emit(new MatDatepickerInputEvent(this, this._elementRef.nativeElement));
  3369. }
  3370. else {
  3371. this._validatorOnChange();
  3372. }
  3373. };
  3374. /**
  3375. * @return {?}
  3376. */
  3377. MatDatepickerInput.prototype._onChange = /**
  3378. * @return {?}
  3379. */
  3380. function () {
  3381. this.dateChange.emit(new MatDatepickerInputEvent(this, this._elementRef.nativeElement));
  3382. };
  3383. /** Returns the palette used by the input's form field, if any. */
  3384. /**
  3385. * Returns the palette used by the input's form field, if any.
  3386. * @return {?}
  3387. */
  3388. MatDatepickerInput.prototype._getThemePalette = /**
  3389. * Returns the palette used by the input's form field, if any.
  3390. * @return {?}
  3391. */
  3392. function () {
  3393. return this._formField ? this._formField.color : undefined;
  3394. };
  3395. /** Handles blur events on the input. */
  3396. /**
  3397. * Handles blur events on the input.
  3398. * @return {?}
  3399. */
  3400. MatDatepickerInput.prototype._onBlur = /**
  3401. * Handles blur events on the input.
  3402. * @return {?}
  3403. */
  3404. function () {
  3405. // Reformat the input only if we have a valid value.
  3406. if (this.value) {
  3407. this._formatValue(this.value);
  3408. }
  3409. this._onTouched();
  3410. };
  3411. /** Formats a value and sets it on the input element. */
  3412. /**
  3413. * Formats a value and sets it on the input element.
  3414. * @private
  3415. * @param {?} value
  3416. * @return {?}
  3417. */
  3418. MatDatepickerInput.prototype._formatValue = /**
  3419. * Formats a value and sets it on the input element.
  3420. * @private
  3421. * @param {?} value
  3422. * @return {?}
  3423. */
  3424. function (value) {
  3425. this._elementRef.nativeElement.value =
  3426. value ? this._dateAdapter.format(value, this._dateFormats.display.dateInput) : '';
  3427. };
  3428. /**
  3429. * @param obj The object to check.
  3430. * @returns The given object if it is both a date instance and valid, otherwise null.
  3431. */
  3432. /**
  3433. * @private
  3434. * @param {?} obj The object to check.
  3435. * @return {?} The given object if it is both a date instance and valid, otherwise null.
  3436. */
  3437. MatDatepickerInput.prototype._getValidDateOrNull = /**
  3438. * @private
  3439. * @param {?} obj The object to check.
  3440. * @return {?} The given object if it is both a date instance and valid, otherwise null.
  3441. */
  3442. function (obj) {
  3443. return (this._dateAdapter.isDateInstance(obj) && this._dateAdapter.isValid(obj)) ? obj : null;
  3444. };
  3445. MatDatepickerInput.decorators = [
  3446. { type: Directive, args: [{
  3447. selector: 'input[matDatepicker]',
  3448. providers: [
  3449. MAT_DATEPICKER_VALUE_ACCESSOR,
  3450. MAT_DATEPICKER_VALIDATORS,
  3451. { provide: MAT_INPUT_VALUE_ACCESSOR, useExisting: MatDatepickerInput },
  3452. ],
  3453. host: {
  3454. '[attr.aria-haspopup]': '_datepicker ? "dialog" : null',
  3455. '[attr.aria-owns]': '(_datepicker?.opened && _datepicker.id) || null',
  3456. '[attr.min]': 'min ? _dateAdapter.toIso8601(min) : null',
  3457. '[attr.max]': 'max ? _dateAdapter.toIso8601(max) : null',
  3458. '[disabled]': 'disabled',
  3459. '(input)': '_onInput($event.target.value)',
  3460. '(change)': '_onChange()',
  3461. '(blur)': '_onBlur()',
  3462. '(keydown)': '_onKeydown($event)',
  3463. },
  3464. exportAs: 'matDatepickerInput',
  3465. },] },
  3466. ];
  3467. /** @nocollapse */
  3468. MatDatepickerInput.ctorParameters = function () { return [
  3469. { type: ElementRef },
  3470. { type: DateAdapter, decorators: [{ type: Optional }] },
  3471. { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [MAT_DATE_FORMATS,] }] },
  3472. { type: MatFormField, decorators: [{ type: Optional }] }
  3473. ]; };
  3474. MatDatepickerInput.propDecorators = {
  3475. matDatepicker: [{ type: Input }],
  3476. matDatepickerFilter: [{ type: Input }],
  3477. value: [{ type: Input }],
  3478. min: [{ type: Input }],
  3479. max: [{ type: Input }],
  3480. disabled: [{ type: Input }],
  3481. dateChange: [{ type: Output }],
  3482. dateInput: [{ type: Output }]
  3483. };
  3484. return MatDatepickerInput;
  3485. }());
  3486. /**
  3487. * @fileoverview added by tsickle
  3488. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3489. */
  3490. /**
  3491. * Can be used to override the icon of a `matDatepickerToggle`.
  3492. */
  3493. var MatDatepickerToggleIcon = /** @class */ (function () {
  3494. function MatDatepickerToggleIcon() {
  3495. }
  3496. MatDatepickerToggleIcon.decorators = [
  3497. { type: Directive, args: [{
  3498. selector: '[matDatepickerToggleIcon]'
  3499. },] },
  3500. ];
  3501. return MatDatepickerToggleIcon;
  3502. }());
  3503. /**
  3504. * @template D
  3505. */
  3506. var MatDatepickerToggle = /** @class */ (function () {
  3507. function MatDatepickerToggle(_intl, _changeDetectorRef, defaultTabIndex) {
  3508. this._intl = _intl;
  3509. this._changeDetectorRef = _changeDetectorRef;
  3510. this._stateChanges = Subscription.EMPTY;
  3511. /** @type {?} */
  3512. var parsedTabIndex = Number(defaultTabIndex);
  3513. this.tabIndex = (parsedTabIndex || parsedTabIndex === 0) ? parsedTabIndex : null;
  3514. }
  3515. Object.defineProperty(MatDatepickerToggle.prototype, "disabled", {
  3516. /** Whether the toggle button is disabled. */
  3517. get: /**
  3518. * Whether the toggle button is disabled.
  3519. * @return {?}
  3520. */
  3521. function () {
  3522. if (this._disabled === undefined && this.datepicker) {
  3523. return this.datepicker.disabled;
  3524. }
  3525. return !!this._disabled;
  3526. },
  3527. set: /**
  3528. * @param {?} value
  3529. * @return {?}
  3530. */
  3531. function (value) {
  3532. this._disabled = coerceBooleanProperty(value);
  3533. },
  3534. enumerable: true,
  3535. configurable: true
  3536. });
  3537. /**
  3538. * @param {?} changes
  3539. * @return {?}
  3540. */
  3541. MatDatepickerToggle.prototype.ngOnChanges = /**
  3542. * @param {?} changes
  3543. * @return {?}
  3544. */
  3545. function (changes) {
  3546. if (changes['datepicker']) {
  3547. this._watchStateChanges();
  3548. }
  3549. };
  3550. /**
  3551. * @return {?}
  3552. */
  3553. MatDatepickerToggle.prototype.ngOnDestroy = /**
  3554. * @return {?}
  3555. */
  3556. function () {
  3557. this._stateChanges.unsubscribe();
  3558. };
  3559. /**
  3560. * @return {?}
  3561. */
  3562. MatDatepickerToggle.prototype.ngAfterContentInit = /**
  3563. * @return {?}
  3564. */
  3565. function () {
  3566. this._watchStateChanges();
  3567. };
  3568. /**
  3569. * @param {?} event
  3570. * @return {?}
  3571. */
  3572. MatDatepickerToggle.prototype._open = /**
  3573. * @param {?} event
  3574. * @return {?}
  3575. */
  3576. function (event) {
  3577. if (this.datepicker && !this.disabled) {
  3578. this.datepicker.open();
  3579. event.stopPropagation();
  3580. }
  3581. };
  3582. /**
  3583. * @private
  3584. * @return {?}
  3585. */
  3586. MatDatepickerToggle.prototype._watchStateChanges = /**
  3587. * @private
  3588. * @return {?}
  3589. */
  3590. function () {
  3591. var _this = this;
  3592. /** @type {?} */
  3593. var datepickerDisabled = this.datepicker ? this.datepicker._disabledChange : of();
  3594. /** @type {?} */
  3595. var inputDisabled = this.datepicker && this.datepicker._datepickerInput ?
  3596. this.datepicker._datepickerInput._disabledChange : of();
  3597. /** @type {?} */
  3598. var datepickerToggled = this.datepicker ?
  3599. merge(this.datepicker.openedStream, this.datepicker.closedStream) :
  3600. of();
  3601. this._stateChanges.unsubscribe();
  3602. this._stateChanges = merge(this._intl.changes, datepickerDisabled, inputDisabled, datepickerToggled).subscribe((/**
  3603. * @return {?}
  3604. */
  3605. function () { return _this._changeDetectorRef.markForCheck(); }));
  3606. };
  3607. MatDatepickerToggle.decorators = [
  3608. { type: Component, args: [{selector: 'mat-datepicker-toggle',
  3609. template: "<button #button mat-icon-button type=\"button\" [attr.aria-haspopup]=\"datepicker ? 'dialog' : null\" [attr.aria-label]=\"_intl.openCalendarLabel\" [attr.tabindex]=\"disabled ? -1 : tabIndex\" [disabled]=\"disabled\" [disableRipple]=\"disableRipple\" (click)=\"_open($event)\"><svg *ngIf=\"!_customIcon\" class=\"mat-datepicker-toggle-default-icon\" viewBox=\"0 0 24 24\" width=\"24px\" height=\"24px\" fill=\"currentColor\" focusable=\"false\"><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><ng-content select=\"[matDatepickerToggleIcon]\"></ng-content></button>",
  3610. styles: [".mat-form-field-appearance-legacy .mat-form-field-prefix .mat-datepicker-toggle-default-icon,.mat-form-field-appearance-legacy .mat-form-field-suffix .mat-datepicker-toggle-default-icon{width:1em}.mat-form-field:not(.mat-form-field-appearance-legacy) .mat-form-field-prefix .mat-datepicker-toggle-default-icon,.mat-form-field:not(.mat-form-field-appearance-legacy) .mat-form-field-suffix .mat-datepicker-toggle-default-icon{display:block;width:1.5em;height:1.5em}.mat-form-field:not(.mat-form-field-appearance-legacy) .mat-form-field-prefix .mat-icon-button .mat-datepicker-toggle-default-icon,.mat-form-field:not(.mat-form-field-appearance-legacy) .mat-form-field-suffix .mat-icon-button .mat-datepicker-toggle-default-icon{margin:auto}"],
  3611. host: {
  3612. 'class': 'mat-datepicker-toggle',
  3613. // Always set the tabindex to -1 so that it doesn't overlap with any custom tabindex the
  3614. // consumer may have provided, while still being able to receive focus.
  3615. '[attr.tabindex]': '-1',
  3616. '[class.mat-datepicker-toggle-active]': 'datepicker && datepicker.opened',
  3617. '[class.mat-accent]': 'datepicker && datepicker.color === "accent"',
  3618. '[class.mat-warn]': 'datepicker && datepicker.color === "warn"',
  3619. '(focus)': '_button.focus()',
  3620. },
  3621. exportAs: 'matDatepickerToggle',
  3622. encapsulation: ViewEncapsulation.None,
  3623. changeDetection: ChangeDetectionStrategy.OnPush,
  3624. },] },
  3625. ];
  3626. /** @nocollapse */
  3627. MatDatepickerToggle.ctorParameters = function () { return [
  3628. { type: MatDatepickerIntl },
  3629. { type: ChangeDetectorRef },
  3630. { type: String, decorators: [{ type: Attribute, args: ['tabindex',] }] }
  3631. ]; };
  3632. MatDatepickerToggle.propDecorators = {
  3633. datepicker: [{ type: Input, args: ['for',] }],
  3634. tabIndex: [{ type: Input }],
  3635. disabled: [{ type: Input }],
  3636. disableRipple: [{ type: Input }],
  3637. _customIcon: [{ type: ContentChild, args: [MatDatepickerToggleIcon, { static: false },] }],
  3638. _button: [{ type: ViewChild, args: ['button', { static: false },] }]
  3639. };
  3640. return MatDatepickerToggle;
  3641. }());
  3642. /**
  3643. * @fileoverview added by tsickle
  3644. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3645. */
  3646. var MatDatepickerModule = /** @class */ (function () {
  3647. function MatDatepickerModule() {
  3648. }
  3649. MatDatepickerModule.decorators = [
  3650. { type: NgModule, args: [{
  3651. imports: [
  3652. CommonModule,
  3653. MatButtonModule,
  3654. MatDialogModule,
  3655. OverlayModule,
  3656. A11yModule,
  3657. PortalModule,
  3658. ],
  3659. exports: [
  3660. MatCalendar,
  3661. MatCalendarBody,
  3662. MatDatepicker,
  3663. MatDatepickerContent,
  3664. MatDatepickerInput,
  3665. MatDatepickerToggle,
  3666. MatDatepickerToggleIcon,
  3667. MatMonthView,
  3668. MatYearView,
  3669. MatMultiYearView,
  3670. MatCalendarHeader,
  3671. ],
  3672. declarations: [
  3673. MatCalendar,
  3674. MatCalendarBody,
  3675. MatDatepicker,
  3676. MatDatepickerContent,
  3677. MatDatepickerInput,
  3678. MatDatepickerToggle,
  3679. MatDatepickerToggleIcon,
  3680. MatMonthView,
  3681. MatYearView,
  3682. MatMultiYearView,
  3683. MatCalendarHeader,
  3684. ],
  3685. providers: [
  3686. MatDatepickerIntl,
  3687. MAT_DATEPICKER_SCROLL_STRATEGY_FACTORY_PROVIDER,
  3688. ],
  3689. entryComponents: [
  3690. MatDatepickerContent,
  3691. MatCalendarHeader,
  3692. ]
  3693. },] },
  3694. ];
  3695. return MatDatepickerModule;
  3696. }());
  3697. /**
  3698. * @fileoverview added by tsickle
  3699. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3700. */
  3701. /**
  3702. * @fileoverview added by tsickle
  3703. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3704. */
  3705. export { MatMultiYearView, yearsPerPage, yearsPerRow, MatDatepickerModule, MatCalendarHeader, MatCalendar, MatCalendarCell, MatCalendarBody, MAT_DATEPICKER_SCROLL_STRATEGY_FACTORY, MAT_DATEPICKER_SCROLL_STRATEGY, MAT_DATEPICKER_SCROLL_STRATEGY_FACTORY_PROVIDER, MatDatepickerContent, MatDatepicker, matDatepickerAnimations, MAT_DATEPICKER_VALUE_ACCESSOR, MAT_DATEPICKER_VALIDATORS, MatDatepickerInputEvent, MatDatepickerInput, MatDatepickerIntl, MatDatepickerToggleIcon, MatDatepickerToggle, MatMonthView, MatYearView };
  3706. //# sourceMappingURL=datepicker.es5.js.map