material-datepicker.umd.js 143 KB

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