datepicker.mjs 293 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879
  1. import * as i0 from '@angular/core';
  2. import { Injectable, inject, ElementRef, NgZone, EventEmitter, Injector, Renderer2, afterNextRender, Component, ViewEncapsulation, ChangeDetectionStrategy, Input, Output, Optional, SkipSelf, InjectionToken, ChangeDetectorRef, ViewChild, ANIMATION_MODULE_TYPE, ViewContainerRef, booleanAttribute, Directive, forwardRef, signal, HostAttributeToken, ContentChild, TemplateRef, NgModule } from '@angular/core';
  3. import { Subject, Subscription, merge, of } from 'rxjs';
  4. import { D as DateAdapter, a as MAT_DATE_FORMATS } from './date-formats-K6TQue-Y.mjs';
  5. import { _IdGenerator, CdkMonitorFocus, CdkTrapFocus, A11yModule } from '@angular/cdk/a11y';
  6. import { Directionality } from '@angular/cdk/bidi';
  7. import { coerceStringArray } from '@angular/cdk/coercion';
  8. import { ESCAPE, hasModifierKey, SPACE, ENTER, PAGE_DOWN, PAGE_UP, END, HOME, DOWN_ARROW, UP_ARROW, RIGHT_ARROW, LEFT_ARROW, BACKSPACE } from '@angular/cdk/keycodes';
  9. import { Overlay, FlexibleConnectedPositionStrategy, OverlayConfig, OverlayModule } from '@angular/cdk/overlay';
  10. import { Platform, _bindEventWithOptions, _getFocusedElementPierceShadowDom } from '@angular/cdk/platform';
  11. import { ComponentPortal, CdkPortalOutlet, TemplatePortal, PortalModule } from '@angular/cdk/portal';
  12. import { NgClass, DOCUMENT } from '@angular/common';
  13. import { startWith, take, filter } from 'rxjs/operators';
  14. import { _CdkPrivateStyleLoader, _VisuallyHiddenLoader } from '@angular/cdk/private';
  15. import { _ as _StructuralStylesLoader } from './structural-styles-BQUT6wsL.mjs';
  16. import { MatButton, MatButtonModule } from './button.mjs';
  17. import { M as MatIconButton } from './icon-button-D1J0zeqv.mjs';
  18. import { NG_VALUE_ACCESSOR, NG_VALIDATORS, Validators, ControlContainer, NgForm, FormGroupDirective, NgControl } from '@angular/forms';
  19. import { M as MAT_INPUT_VALUE_ACCESSOR } from './input-value-accessor-D1GvPuqO.mjs';
  20. import { h as MAT_FORM_FIELD, k as MatFormFieldControl } from './form-field-DqPi4knt.mjs';
  21. import { E as ErrorStateMatcher } from './error-options-Dm2JJUbF.mjs';
  22. import { _ as _ErrorStateTracker } from './error-state-Dtb1IHM-.mjs';
  23. import { CdkScrollableModule } from '@angular/cdk/scrolling';
  24. import { M as MatCommonModule } from './common-module-WayjW0Pb.mjs';
  25. import './index-SYVYjXwK.mjs';
  26. import './ripple-BT3tzh6F.mjs';
  27. import './ripple-loader-Ce3DAhPW.mjs';
  28. import '@angular/cdk/observers/private';
  29. /** @docs-private */
  30. function createMissingDateImplError(provider) {
  31. return Error(`MatDatepicker: No provider found for ${provider}. You must add one of the following ` +
  32. `to your app config: provideNativeDateAdapter, provideDateFnsAdapter, ` +
  33. `provideLuxonDateAdapter, provideMomentDateAdapter, or provide a custom implementation.`);
  34. }
  35. /** Datepicker data that requires internationalization. */
  36. class MatDatepickerIntl {
  37. /**
  38. * Stream that emits whenever the labels here are changed. Use this to notify
  39. * components if the labels have changed after initialization.
  40. */
  41. changes = new Subject();
  42. /** A label for the calendar popup (used by screen readers). */
  43. calendarLabel = 'Calendar';
  44. /** A label for the button used to open the calendar popup (used by screen readers). */
  45. openCalendarLabel = 'Open calendar';
  46. /** Label for the button used to close the calendar popup. */
  47. closeCalendarLabel = 'Close calendar';
  48. /** A label for the previous month button (used by screen readers). */
  49. prevMonthLabel = 'Previous month';
  50. /** A label for the next month button (used by screen readers). */
  51. nextMonthLabel = 'Next month';
  52. /** A label for the previous year button (used by screen readers). */
  53. prevYearLabel = 'Previous year';
  54. /** A label for the next year button (used by screen readers). */
  55. nextYearLabel = 'Next year';
  56. /** A label for the previous multi-year button (used by screen readers). */
  57. prevMultiYearLabel = 'Previous 24 years';
  58. /** A label for the next multi-year button (used by screen readers). */
  59. nextMultiYearLabel = 'Next 24 years';
  60. /** A label for the 'switch to month view' button (used by screen readers). */
  61. switchToMonthViewLabel = 'Choose date';
  62. /** A label for the 'switch to year view' button (used by screen readers). */
  63. switchToMultiYearViewLabel = 'Choose month and year';
  64. /**
  65. * A label for the first date of a range of dates (used by screen readers).
  66. * @deprecated Provide your own internationalization string.
  67. * @breaking-change 17.0.0
  68. */
  69. startDateLabel = 'Start date';
  70. /**
  71. * A label for the last date of a range of dates (used by screen readers).
  72. * @deprecated Provide your own internationalization string.
  73. * @breaking-change 17.0.0
  74. */
  75. endDateLabel = 'End date';
  76. /**
  77. * A label for the Comparison date of a range of dates (used by screen readers).
  78. */
  79. comparisonDateLabel = 'Comparison range';
  80. /** Formats a range of years (used for visuals). */
  81. formatYearRange(start, end) {
  82. return `${start} \u2013 ${end}`;
  83. }
  84. /** Formats a label for a range of years (used by screen readers). */
  85. formatYearRangeLabel(start, end) {
  86. return `${start} to ${end}`;
  87. }
  88. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerIntl, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
  89. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerIntl, providedIn: 'root' });
  90. }
  91. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerIntl, decorators: [{
  92. type: Injectable,
  93. args: [{ providedIn: 'root' }]
  94. }] });
  95. let uniqueIdCounter$1 = 0;
  96. /**
  97. * An internal class that represents the data corresponding to a single calendar cell.
  98. * @docs-private
  99. */
  100. class MatCalendarCell {
  101. value;
  102. displayValue;
  103. ariaLabel;
  104. enabled;
  105. cssClasses;
  106. compareValue;
  107. rawValue;
  108. id = uniqueIdCounter$1++;
  109. constructor(value, displayValue, ariaLabel, enabled, cssClasses = {}, compareValue = value, rawValue) {
  110. this.value = value;
  111. this.displayValue = displayValue;
  112. this.ariaLabel = ariaLabel;
  113. this.enabled = enabled;
  114. this.cssClasses = cssClasses;
  115. this.compareValue = compareValue;
  116. this.rawValue = rawValue;
  117. }
  118. }
  119. /** Event options that can be used to bind an active, capturing event. */
  120. const activeCapturingEventOptions = {
  121. passive: false,
  122. capture: true,
  123. };
  124. /** Event options that can be used to bind a passive, capturing event. */
  125. const passiveCapturingEventOptions = {
  126. passive: true,
  127. capture: true,
  128. };
  129. /** Event options that can be used to bind a passive, non-capturing event. */
  130. const passiveEventOptions = { passive: true };
  131. /**
  132. * An internal component used to display calendar data in a table.
  133. * @docs-private
  134. */
  135. class MatCalendarBody {
  136. _elementRef = inject(ElementRef);
  137. _ngZone = inject(NgZone);
  138. _platform = inject(Platform);
  139. _intl = inject(MatDatepickerIntl);
  140. _eventCleanups;
  141. /**
  142. * Used to skip the next focus event when rendering the preview range.
  143. * We need a flag like this, because some browsers fire focus events asynchronously.
  144. */
  145. _skipNextFocus;
  146. /**
  147. * Used to focus the active cell after change detection has run.
  148. */
  149. _focusActiveCellAfterViewChecked = false;
  150. /** The label for the table. (e.g. "Jan 2017"). */
  151. label;
  152. /** The cells to display in the table. */
  153. rows;
  154. /** The value in the table that corresponds to today. */
  155. todayValue;
  156. /** Start value of the selected date range. */
  157. startValue;
  158. /** End value of the selected date range. */
  159. endValue;
  160. /** The minimum number of free cells needed to fit the label in the first row. */
  161. labelMinRequiredCells;
  162. /** The number of columns in the table. */
  163. numCols = 7;
  164. /** The cell number of the active cell in the table. */
  165. activeCell = 0;
  166. ngAfterViewChecked() {
  167. if (this._focusActiveCellAfterViewChecked) {
  168. this._focusActiveCell();
  169. this._focusActiveCellAfterViewChecked = false;
  170. }
  171. }
  172. /** Whether a range is being selected. */
  173. isRange = false;
  174. /**
  175. * The aspect ratio (width / height) to use for the cells in the table. This aspect ratio will be
  176. * maintained even as the table resizes.
  177. */
  178. cellAspectRatio = 1;
  179. /** Start of the comparison range. */
  180. comparisonStart;
  181. /** End of the comparison range. */
  182. comparisonEnd;
  183. /** Start of the preview range. */
  184. previewStart = null;
  185. /** End of the preview range. */
  186. previewEnd = null;
  187. /** ARIA Accessible name of the `<input matStartDate/>` */
  188. startDateAccessibleName;
  189. /** ARIA Accessible name of the `<input matEndDate/>` */
  190. endDateAccessibleName;
  191. /** Emits when a new value is selected. */
  192. selectedValueChange = new EventEmitter();
  193. /** Emits when the preview has changed as a result of a user action. */
  194. previewChange = new EventEmitter();
  195. activeDateChange = new EventEmitter();
  196. /** Emits the date at the possible start of a drag event. */
  197. dragStarted = new EventEmitter();
  198. /** Emits the date at the conclusion of a drag, or null if mouse was not released on a date. */
  199. dragEnded = new EventEmitter();
  200. /** The number of blank cells to put at the beginning for the first row. */
  201. _firstRowOffset;
  202. /** Padding for the individual date cells. */
  203. _cellPadding;
  204. /** Width of an individual cell. */
  205. _cellWidth;
  206. /** ID for the start date label. */
  207. _startDateLabelId;
  208. /** ID for the end date label. */
  209. _endDateLabelId;
  210. /** ID for the comparison start date label. */
  211. _comparisonStartDateLabelId;
  212. /** ID for the comparison end date label. */
  213. _comparisonEndDateLabelId;
  214. _didDragSinceMouseDown = false;
  215. _injector = inject(Injector);
  216. comparisonDateAccessibleName = this._intl.comparisonDateLabel;
  217. /**
  218. * Tracking function for rows based on their identity. Ideally we would use some sort of
  219. * key on the row, but that would require a breaking change for the `rows` input. We don't
  220. * use the built-in identity tracking, because it logs warnings.
  221. */
  222. _trackRow = (row) => row;
  223. constructor() {
  224. const renderer = inject(Renderer2);
  225. const idGenerator = inject(_IdGenerator);
  226. this._startDateLabelId = idGenerator.getId('mat-calendar-body-start-');
  227. this._endDateLabelId = idGenerator.getId('mat-calendar-body-end-');
  228. this._comparisonStartDateLabelId = idGenerator.getId('mat-calendar-body-comparison-start-');
  229. this._comparisonEndDateLabelId = idGenerator.getId('mat-calendar-body-comparison-end-');
  230. inject(_CdkPrivateStyleLoader).load(_StructuralStylesLoader);
  231. this._ngZone.runOutsideAngular(() => {
  232. const element = this._elementRef.nativeElement;
  233. const cleanups = [
  234. // `touchmove` is active since we need to call `preventDefault`.
  235. _bindEventWithOptions(renderer, element, 'touchmove', this._touchmoveHandler, activeCapturingEventOptions),
  236. _bindEventWithOptions(renderer, element, 'mouseenter', this._enterHandler, passiveCapturingEventOptions),
  237. _bindEventWithOptions(renderer, element, 'focus', this._enterHandler, passiveCapturingEventOptions),
  238. _bindEventWithOptions(renderer, element, 'mouseleave', this._leaveHandler, passiveCapturingEventOptions),
  239. _bindEventWithOptions(renderer, element, 'blur', this._leaveHandler, passiveCapturingEventOptions),
  240. _bindEventWithOptions(renderer, element, 'mousedown', this._mousedownHandler, passiveEventOptions),
  241. _bindEventWithOptions(renderer, element, 'touchstart', this._mousedownHandler, passiveEventOptions),
  242. ];
  243. if (this._platform.isBrowser) {
  244. cleanups.push(renderer.listen('window', 'mouseup', this._mouseupHandler), renderer.listen('window', 'touchend', this._touchendHandler));
  245. }
  246. this._eventCleanups = cleanups;
  247. });
  248. }
  249. /** Called when a cell is clicked. */
  250. _cellClicked(cell, event) {
  251. // Ignore "clicks" that are actually canceled drags (eg the user dragged
  252. // off and then went back to this cell to undo).
  253. if (this._didDragSinceMouseDown) {
  254. return;
  255. }
  256. if (cell.enabled) {
  257. this.selectedValueChange.emit({ value: cell.value, event });
  258. }
  259. }
  260. _emitActiveDateChange(cell, event) {
  261. if (cell.enabled) {
  262. this.activeDateChange.emit({ value: cell.value, event });
  263. }
  264. }
  265. /** Returns whether a cell should be marked as selected. */
  266. _isSelected(value) {
  267. return this.startValue === value || this.endValue === value;
  268. }
  269. ngOnChanges(changes) {
  270. const columnChanges = changes['numCols'];
  271. const { rows, numCols } = this;
  272. if (changes['rows'] || columnChanges) {
  273. this._firstRowOffset = rows && rows.length && rows[0].length ? numCols - rows[0].length : 0;
  274. }
  275. if (changes['cellAspectRatio'] || columnChanges || !this._cellPadding) {
  276. this._cellPadding = `${(50 * this.cellAspectRatio) / numCols}%`;
  277. }
  278. if (columnChanges || !this._cellWidth) {
  279. this._cellWidth = `${100 / numCols}%`;
  280. }
  281. }
  282. ngOnDestroy() {
  283. this._eventCleanups.forEach(cleanup => cleanup());
  284. }
  285. /** Returns whether a cell is active. */
  286. _isActiveCell(rowIndex, colIndex) {
  287. let cellNumber = rowIndex * this.numCols + colIndex;
  288. // Account for the fact that the first row may not have as many cells.
  289. if (rowIndex) {
  290. cellNumber -= this._firstRowOffset;
  291. }
  292. return cellNumber == this.activeCell;
  293. }
  294. /**
  295. * Focuses the active cell after the microtask queue is empty.
  296. *
  297. * Adding a 0ms setTimeout seems to fix Voiceover losing focus when pressing PageUp/PageDown
  298. * (issue #24330).
  299. *
  300. * Determined a 0ms by gradually increasing duration from 0 and testing two use cases with screen
  301. * reader enabled:
  302. *
  303. * 1. Pressing PageUp/PageDown repeatedly with pausing between each key press.
  304. * 2. Pressing and holding the PageDown key with repeated keys enabled.
  305. *
  306. * Test 1 worked roughly 95-99% of the time with 0ms and got a little bit better as the duration
  307. * increased. Test 2 got slightly better until the duration was long enough to interfere with
  308. * repeated keys. If the repeated key speed was faster than the timeout duration, then pressing
  309. * and holding pagedown caused the entire page to scroll.
  310. *
  311. * Since repeated key speed can verify across machines, determined that any duration could
  312. * potentially interfere with repeated keys. 0ms would be best because it almost entirely
  313. * eliminates the focus being lost in Voiceover (#24330) without causing unintended side effects.
  314. * Adding delay also complicates writing tests.
  315. */
  316. _focusActiveCell(movePreview = true) {
  317. afterNextRender(() => {
  318. setTimeout(() => {
  319. const activeCell = this._elementRef.nativeElement.querySelector('.mat-calendar-body-active');
  320. if (activeCell) {
  321. if (!movePreview) {
  322. this._skipNextFocus = true;
  323. }
  324. activeCell.focus();
  325. }
  326. });
  327. }, { injector: this._injector });
  328. }
  329. /** Focuses the active cell after change detection has run and the microtask queue is empty. */
  330. _scheduleFocusActiveCellAfterViewChecked() {
  331. this._focusActiveCellAfterViewChecked = true;
  332. }
  333. /** Gets whether a value is the start of the main range. */
  334. _isRangeStart(value) {
  335. return isStart(value, this.startValue, this.endValue);
  336. }
  337. /** Gets whether a value is the end of the main range. */
  338. _isRangeEnd(value) {
  339. return isEnd(value, this.startValue, this.endValue);
  340. }
  341. /** Gets whether a value is within the currently-selected range. */
  342. _isInRange(value) {
  343. return isInRange(value, this.startValue, this.endValue, this.isRange);
  344. }
  345. /** Gets whether a value is the start of the comparison range. */
  346. _isComparisonStart(value) {
  347. return isStart(value, this.comparisonStart, this.comparisonEnd);
  348. }
  349. /** Whether the cell is a start bridge cell between the main and comparison ranges. */
  350. _isComparisonBridgeStart(value, rowIndex, colIndex) {
  351. if (!this._isComparisonStart(value) || this._isRangeStart(value) || !this._isInRange(value)) {
  352. return false;
  353. }
  354. let previousCell = this.rows[rowIndex][colIndex - 1];
  355. if (!previousCell) {
  356. const previousRow = this.rows[rowIndex - 1];
  357. previousCell = previousRow && previousRow[previousRow.length - 1];
  358. }
  359. return previousCell && !this._isRangeEnd(previousCell.compareValue);
  360. }
  361. /** Whether the cell is an end bridge cell between the main and comparison ranges. */
  362. _isComparisonBridgeEnd(value, rowIndex, colIndex) {
  363. if (!this._isComparisonEnd(value) || this._isRangeEnd(value) || !this._isInRange(value)) {
  364. return false;
  365. }
  366. let nextCell = this.rows[rowIndex][colIndex + 1];
  367. if (!nextCell) {
  368. const nextRow = this.rows[rowIndex + 1];
  369. nextCell = nextRow && nextRow[0];
  370. }
  371. return nextCell && !this._isRangeStart(nextCell.compareValue);
  372. }
  373. /** Gets whether a value is the end of the comparison range. */
  374. _isComparisonEnd(value) {
  375. return isEnd(value, this.comparisonStart, this.comparisonEnd);
  376. }
  377. /** Gets whether a value is within the current comparison range. */
  378. _isInComparisonRange(value) {
  379. return isInRange(value, this.comparisonStart, this.comparisonEnd, this.isRange);
  380. }
  381. /**
  382. * Gets whether a value is the same as the start and end of the comparison range.
  383. * For context, the functions that we use to determine whether something is the start/end of
  384. * a range don't allow for the start and end to be on the same day, because we'd have to use
  385. * much more specific CSS selectors to style them correctly in all scenarios. This is fine for
  386. * the regular range, because when it happens, the selected styles take over and still show where
  387. * the range would've been, however we don't have these selected styles for a comparison range.
  388. * This function is used to apply a class that serves the same purpose as the one for selected
  389. * dates, but it only applies in the context of a comparison range.
  390. */
  391. _isComparisonIdentical(value) {
  392. // Note that we don't need to null check the start/end
  393. // here, because the `value` will always be defined.
  394. return this.comparisonStart === this.comparisonEnd && value === this.comparisonStart;
  395. }
  396. /** Gets whether a value is the start of the preview range. */
  397. _isPreviewStart(value) {
  398. return isStart(value, this.previewStart, this.previewEnd);
  399. }
  400. /** Gets whether a value is the end of the preview range. */
  401. _isPreviewEnd(value) {
  402. return isEnd(value, this.previewStart, this.previewEnd);
  403. }
  404. /** Gets whether a value is inside the preview range. */
  405. _isInPreview(value) {
  406. return isInRange(value, this.previewStart, this.previewEnd, this.isRange);
  407. }
  408. /** Gets ids of aria descriptions for the start and end of a date range. */
  409. _getDescribedby(value) {
  410. if (!this.isRange) {
  411. return null;
  412. }
  413. if (this.startValue === value && this.endValue === value) {
  414. return `${this._startDateLabelId} ${this._endDateLabelId}`;
  415. }
  416. else if (this.startValue === value) {
  417. return this._startDateLabelId;
  418. }
  419. else if (this.endValue === value) {
  420. return this._endDateLabelId;
  421. }
  422. if (this.comparisonStart !== null && this.comparisonEnd !== null) {
  423. if (value === this.comparisonStart && value === this.comparisonEnd) {
  424. return `${this._comparisonStartDateLabelId} ${this._comparisonEndDateLabelId}`;
  425. }
  426. else if (value === this.comparisonStart) {
  427. return this._comparisonStartDateLabelId;
  428. }
  429. else if (value === this.comparisonEnd) {
  430. return this._comparisonEndDateLabelId;
  431. }
  432. }
  433. return null;
  434. }
  435. /**
  436. * Event handler for when the user enters an element
  437. * inside the calendar body (e.g. by hovering in or focus).
  438. */
  439. _enterHandler = (event) => {
  440. if (this._skipNextFocus && event.type === 'focus') {
  441. this._skipNextFocus = false;
  442. return;
  443. }
  444. // We only need to hit the zone when we're selecting a range.
  445. if (event.target && this.isRange) {
  446. const cell = this._getCellFromElement(event.target);
  447. if (cell) {
  448. this._ngZone.run(() => this.previewChange.emit({ value: cell.enabled ? cell : null, event }));
  449. }
  450. }
  451. };
  452. _touchmoveHandler = (event) => {
  453. if (!this.isRange)
  454. return;
  455. const target = getActualTouchTarget(event);
  456. const cell = target ? this._getCellFromElement(target) : null;
  457. if (target !== event.target) {
  458. this._didDragSinceMouseDown = true;
  459. }
  460. // If the initial target of the touch is a date cell, prevent default so
  461. // that the move is not handled as a scroll.
  462. if (getCellElement(event.target)) {
  463. event.preventDefault();
  464. }
  465. this._ngZone.run(() => this.previewChange.emit({ value: cell?.enabled ? cell : null, event }));
  466. };
  467. /**
  468. * Event handler for when the user's pointer leaves an element
  469. * inside the calendar body (e.g. by hovering out or blurring).
  470. */
  471. _leaveHandler = (event) => {
  472. // We only need to hit the zone when we're selecting a range.
  473. if (this.previewEnd !== null && this.isRange) {
  474. if (event.type !== 'blur') {
  475. this._didDragSinceMouseDown = true;
  476. }
  477. // Only reset the preview end value when leaving cells. This looks better, because
  478. // we have a gap between the cells and the rows and we don't want to remove the
  479. // range just for it to show up again when the user moves a few pixels to the side.
  480. if (event.target &&
  481. this._getCellFromElement(event.target) &&
  482. !(event.relatedTarget &&
  483. this._getCellFromElement(event.relatedTarget))) {
  484. this._ngZone.run(() => this.previewChange.emit({ value: null, event }));
  485. }
  486. }
  487. };
  488. /**
  489. * Triggered on mousedown or touchstart on a date cell.
  490. * Respsonsible for starting a drag sequence.
  491. */
  492. _mousedownHandler = (event) => {
  493. if (!this.isRange)
  494. return;
  495. this._didDragSinceMouseDown = false;
  496. // Begin a drag if a cell within the current range was targeted.
  497. const cell = event.target && this._getCellFromElement(event.target);
  498. if (!cell || !this._isInRange(cell.compareValue)) {
  499. return;
  500. }
  501. this._ngZone.run(() => {
  502. this.dragStarted.emit({
  503. value: cell.rawValue,
  504. event,
  505. });
  506. });
  507. };
  508. /** Triggered on mouseup anywhere. Respsonsible for ending a drag sequence. */
  509. _mouseupHandler = (event) => {
  510. if (!this.isRange)
  511. return;
  512. const cellElement = getCellElement(event.target);
  513. if (!cellElement) {
  514. // Mouseup happened outside of datepicker. Cancel drag.
  515. this._ngZone.run(() => {
  516. this.dragEnded.emit({ value: null, event });
  517. });
  518. return;
  519. }
  520. if (cellElement.closest('.mat-calendar-body') !== this._elementRef.nativeElement) {
  521. // Mouseup happened inside a different month instance.
  522. // Allow it to handle the event.
  523. return;
  524. }
  525. this._ngZone.run(() => {
  526. const cell = this._getCellFromElement(cellElement);
  527. this.dragEnded.emit({ value: cell?.rawValue ?? null, event });
  528. });
  529. };
  530. /** Triggered on touchend anywhere. Respsonsible for ending a drag sequence. */
  531. _touchendHandler = (event) => {
  532. const target = getActualTouchTarget(event);
  533. if (target) {
  534. this._mouseupHandler({ target });
  535. }
  536. };
  537. /** Finds the MatCalendarCell that corresponds to a DOM node. */
  538. _getCellFromElement(element) {
  539. const cell = getCellElement(element);
  540. if (cell) {
  541. const row = cell.getAttribute('data-mat-row');
  542. const col = cell.getAttribute('data-mat-col');
  543. if (row && col) {
  544. return this.rows[parseInt(row)][parseInt(col)];
  545. }
  546. }
  547. return null;
  548. }
  549. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatCalendarBody, deps: [], target: i0.ɵɵFactoryTarget.Component });
  550. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.6", type: MatCalendarBody, isStandalone: true, selector: "[mat-calendar-body]", inputs: { label: "label", rows: "rows", todayValue: "todayValue", startValue: "startValue", endValue: "endValue", labelMinRequiredCells: "labelMinRequiredCells", numCols: "numCols", activeCell: "activeCell", isRange: "isRange", cellAspectRatio: "cellAspectRatio", comparisonStart: "comparisonStart", comparisonEnd: "comparisonEnd", previewStart: "previewStart", previewEnd: "previewEnd", startDateAccessibleName: "startDateAccessibleName", endDateAccessibleName: "endDateAccessibleName" }, outputs: { selectedValueChange: "selectedValueChange", previewChange: "previewChange", activeDateChange: "activeDateChange", dragStarted: "dragStarted", dragEnded: "dragEnded" }, host: { classAttribute: "mat-calendar-body" }, exportAs: ["matCalendarBody"], usesOnChanges: true, ngImport: i0, template: "<!--\n If there's not enough space in the first row, create a separate label row. We mark this row as\n aria-hidden because we don't want it to be read out as one of the weeks in the month.\n-->\n@if (_firstRowOffset < labelMinRequiredCells) {\n <tr aria-hidden=\"true\">\n <td class=\"mat-calendar-body-label\"\n [attr.colspan]=\"numCols\"\n [style.paddingTop]=\"_cellPadding\"\n [style.paddingBottom]=\"_cellPadding\">\n {{label}}\n </td>\n </tr>\n}\n\n<!-- Create the first row separately so we can include a special spacer cell. -->\n@for (row of rows; track _trackRow(row); let rowIndex = $index) {\n <tr role=\"row\">\n <!--\n This cell is purely decorative, but we can't put `aria-hidden` or `role=\"presentation\"` on it,\n because it throws off the week days for the rest of the row on NVDA. The aspect ratio of the\n table cells is maintained by setting the top and bottom padding as a percentage of the width\n (a variant of the trick described here: https://www.w3schools.com/howto/howto_css_aspect_ratio.asp).\n -->\n @if (rowIndex === 0 && _firstRowOffset) {\n <td\n class=\"mat-calendar-body-label\"\n [attr.colspan]=\"_firstRowOffset\"\n [style.paddingTop]=\"_cellPadding\"\n [style.paddingBottom]=\"_cellPadding\">\n {{_firstRowOffset >= labelMinRequiredCells ? label : ''}}\n </td>\n }\n <!--\n Each gridcell in the calendar contains a button, which signals to assistive technology that the\n cell is interactable, as well as the selection state via `aria-pressed`. See #23476 for\n background.\n -->\n @for (item of row; track item.id; let colIndex = $index) {\n <td\n role=\"gridcell\"\n class=\"mat-calendar-body-cell-container\"\n [style.width]=\"_cellWidth\"\n [style.paddingTop]=\"_cellPadding\"\n [style.paddingBottom]=\"_cellPadding\"\n [attr.data-mat-row]=\"rowIndex\"\n [attr.data-mat-col]=\"colIndex\"\n >\n <button\n type=\"button\"\n class=\"mat-calendar-body-cell\"\n [ngClass]=\"item.cssClasses\"\n [tabindex]=\"_isActiveCell(rowIndex, colIndex) ? 0 : -1\"\n [class.mat-calendar-body-disabled]=\"!item.enabled\"\n [class.mat-calendar-body-active]=\"_isActiveCell(rowIndex, colIndex)\"\n [class.mat-calendar-body-range-start]=\"_isRangeStart(item.compareValue)\"\n [class.mat-calendar-body-range-end]=\"_isRangeEnd(item.compareValue)\"\n [class.mat-calendar-body-in-range]=\"_isInRange(item.compareValue)\"\n [class.mat-calendar-body-comparison-bridge-start]=\"_isComparisonBridgeStart(item.compareValue, rowIndex, colIndex)\"\n [class.mat-calendar-body-comparison-bridge-end]=\"_isComparisonBridgeEnd(item.compareValue, rowIndex, colIndex)\"\n [class.mat-calendar-body-comparison-start]=\"_isComparisonStart(item.compareValue)\"\n [class.mat-calendar-body-comparison-end]=\"_isComparisonEnd(item.compareValue)\"\n [class.mat-calendar-body-in-comparison-range]=\"_isInComparisonRange(item.compareValue)\"\n [class.mat-calendar-body-preview-start]=\"_isPreviewStart(item.compareValue)\"\n [class.mat-calendar-body-preview-end]=\"_isPreviewEnd(item.compareValue)\"\n [class.mat-calendar-body-in-preview]=\"_isInPreview(item.compareValue)\"\n [attr.aria-label]=\"item.ariaLabel\"\n [attr.aria-disabled]=\"!item.enabled || null\"\n [attr.aria-pressed]=\"_isSelected(item.compareValue)\"\n [attr.aria-current]=\"todayValue === item.compareValue ? 'date' : null\"\n [attr.aria-describedby]=\"_getDescribedby(item.compareValue)\"\n (click)=\"_cellClicked(item, $event)\"\n (focus)=\"_emitActiveDateChange(item, $event)\">\n <span class=\"mat-calendar-body-cell-content mat-focus-indicator\"\n [class.mat-calendar-body-selected]=\"_isSelected(item.compareValue)\"\n [class.mat-calendar-body-comparison-identical]=\"_isComparisonIdentical(item.compareValue)\"\n [class.mat-calendar-body-today]=\"todayValue === item.compareValue\">\n {{item.displayValue}}\n </span>\n <span class=\"mat-calendar-body-cell-preview\" aria-hidden=\"true\"></span>\n </button>\n </td>\n }\n </tr>\n}\n\n<span [id]=\"_startDateLabelId\" class=\"mat-calendar-body-hidden-label\">\n {{startDateAccessibleName}}\n</span>\n<span [id]=\"_endDateLabelId\" class=\"mat-calendar-body-hidden-label\">\n {{endDateAccessibleName}}\n</span>\n<span [id]=\"_comparisonStartDateLabelId\" class=\"mat-calendar-body-hidden-label\">\n {{comparisonDateAccessibleName}} {{startDateAccessibleName}}\n</span>\n<span [id]=\"_comparisonEndDateLabelId\" class=\"mat-calendar-body-hidden-label\">\n {{comparisonDateAccessibleName}} {{endDateAccessibleName}}\n</span>\n", styles: [".mat-calendar-body{min-width:224px}.mat-calendar-body-today:not(.mat-calendar-body-selected):not(.mat-calendar-body-comparison-identical){border-color:var(--mat-datepicker-calendar-date-today-outline-color, var(--mat-sys-primary))}.mat-calendar-body-label{height:0;line-height:0;text-align:start;padding-left:4.7142857143%;padding-right:4.7142857143%;font-size:var(--mat-datepicker-calendar-body-label-text-size, var(--mat-sys-title-small-size));font-weight:var(--mat-datepicker-calendar-body-label-text-weight, var(--mat-sys-title-small-weight));color:var(--mat-datepicker-calendar-body-label-text-color, var(--mat-sys-on-surface))}.mat-calendar-body-hidden-label{display:none}.mat-calendar-body-cell-container{position:relative;height:0;line-height:0}.mat-calendar-body-cell{position:absolute;top:0;left:0;width:100%;height:100%;background:none;text-align:center;outline:none;font-family:inherit;margin:0;font-family:var(--mat-datepicker-calendar-text-font, var(--mat-sys-body-medium-font));font-size:var(--mat-datepicker-calendar-text-size, var(--mat-sys-body-medium-size));-webkit-user-select:none;user-select:none;cursor:pointer;outline:none;border:none;-webkit-tap-highlight-color:rgba(0,0,0,0)}.mat-calendar-body-cell::-moz-focus-inner{border:0}.mat-calendar-body-cell::before,.mat-calendar-body-cell::after,.mat-calendar-body-cell-preview{content:\"\";position:absolute;top:5%;left:0;z-index:0;box-sizing:border-box;display:block;height:90%;width:100%}.mat-calendar-body-range-start:not(.mat-calendar-body-in-comparison-range)::before,.mat-calendar-body-range-start::after,.mat-calendar-body-comparison-start:not(.mat-calendar-body-comparison-bridge-start)::before,.mat-calendar-body-comparison-start::after,.mat-calendar-body-preview-start .mat-calendar-body-cell-preview{left:5%;width:95%;border-top-left-radius:999px;border-bottom-left-radius:999px}[dir=rtl] .mat-calendar-body-range-start:not(.mat-calendar-body-in-comparison-range)::before,[dir=rtl] .mat-calendar-body-range-start::after,[dir=rtl] .mat-calendar-body-comparison-start:not(.mat-calendar-body-comparison-bridge-start)::before,[dir=rtl] .mat-calendar-body-comparison-start::after,[dir=rtl] .mat-calendar-body-preview-start .mat-calendar-body-cell-preview{left:0;border-radius:0;border-top-right-radius:999px;border-bottom-right-radius:999px}.mat-calendar-body-range-end:not(.mat-calendar-body-in-comparison-range)::before,.mat-calendar-body-range-end::after,.mat-calendar-body-comparison-end:not(.mat-calendar-body-comparison-bridge-end)::before,.mat-calendar-body-comparison-end::after,.mat-calendar-body-preview-end .mat-calendar-body-cell-preview{width:95%;border-top-right-radius:999px;border-bottom-right-radius:999px}[dir=rtl] .mat-calendar-body-range-end:not(.mat-calendar-body-in-comparison-range)::before,[dir=rtl] .mat-calendar-body-range-end::after,[dir=rtl] .mat-calendar-body-comparison-end:not(.mat-calendar-body-comparison-bridge-end)::before,[dir=rtl] .mat-calendar-body-comparison-end::after,[dir=rtl] .mat-calendar-body-preview-end .mat-calendar-body-cell-preview{left:5%;border-radius:0;border-top-left-radius:999px;border-bottom-left-radius:999px}[dir=rtl] .mat-calendar-body-comparison-bridge-start.mat-calendar-body-range-end::after,[dir=rtl] .mat-calendar-body-comparison-bridge-end.mat-calendar-body-range-start::after{width:95%;border-top-right-radius:999px;border-bottom-right-radius:999px}.mat-calendar-body-comparison-start.mat-calendar-body-range-end::after,[dir=rtl] .mat-calendar-body-comparison-start.mat-calendar-body-range-end::after,.mat-calendar-body-comparison-end.mat-calendar-body-range-start::after,[dir=rtl] .mat-calendar-body-comparison-end.mat-calendar-body-range-start::after{width:90%}.mat-calendar-body-in-preview{color:var(--mat-datepicker-calendar-date-preview-state-outline-color, var(--mat-sys-primary))}.mat-calendar-body-in-preview .mat-calendar-body-cell-preview{border-top:dashed 1px;border-bottom:dashed 1px}.mat-calendar-body-preview-start .mat-calendar-body-cell-preview{border-left:dashed 1px}[dir=rtl] .mat-calendar-body-preview-start .mat-calendar-body-cell-preview{border-left:0;border-right:dashed 1px}.mat-calendar-body-preview-end .mat-calendar-body-cell-preview{border-right:dashed 1px}[dir=rtl] .mat-calendar-body-preview-end .mat-calendar-body-cell-preview{border-right:0;border-left:dashed 1px}.mat-calendar-body-disabled{cursor:default}.mat-calendar-body-disabled>.mat-calendar-body-cell-content:not(.mat-calendar-body-selected):not(.mat-calendar-body-comparison-identical){color:var(--mat-datepicker-calendar-date-disabled-state-text-color, color-mix(in srgb, var(--mat-sys-on-surface) 38%, transparent))}.mat-calendar-body-disabled>.mat-calendar-body-today:not(.mat-calendar-body-selected):not(.mat-calendar-body-comparison-identical){border-color:var(--mat-datepicker-calendar-date-today-disabled-state-outline-color, color-mix(in srgb, var(--mat-sys-on-surface) 38%, transparent))}@media(forced-colors: active){.mat-calendar-body-disabled{opacity:.5}}.mat-calendar-body-cell-content{top:5%;left:5%;z-index:1;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;color:var(--mat-datepicker-calendar-date-text-color, var(--mat-sys-on-surface));border-color:var(--mat-datepicker-calendar-date-outline-color, transparent)}.mat-calendar-body-cell-content.mat-focus-indicator{position:absolute}@media(forced-colors: active){.mat-calendar-body-cell-content{border:none}}.cdk-keyboard-focused .mat-calendar-body-active>.mat-calendar-body-cell-content:not(.mat-calendar-body-selected):not(.mat-calendar-body-comparison-identical),.cdk-program-focused .mat-calendar-body-active>.mat-calendar-body-cell-content:not(.mat-calendar-body-selected):not(.mat-calendar-body-comparison-identical){background-color:var(--mat-datepicker-calendar-date-focus-state-background-color, color-mix(in srgb, var(--mat-sys-on-surface) calc(var(--mat-sys-focus-state-layer-opacity) * 100%), transparent))}@media(hover: hover){.mat-calendar-body-cell:not(.mat-calendar-body-disabled):hover>.mat-calendar-body-cell-content:not(.mat-calendar-body-selected):not(.mat-calendar-body-comparison-identical){background-color:var(--mat-datepicker-calendar-date-hover-state-background-color, color-mix(in srgb, var(--mat-sys-on-surface) calc(var(--mat-sys-hover-state-layer-opacity) * 100%), transparent))}}.mat-calendar-body-selected{background-color:var(--mat-datepicker-calendar-date-selected-state-background-color, var(--mat-sys-primary));color:var(--mat-datepicker-calendar-date-selected-state-text-color, var(--mat-sys-on-primary))}.mat-calendar-body-disabled>.mat-calendar-body-selected{background-color:var(--mat-datepicker-calendar-date-selected-disabled-state-background-color, color-mix(in srgb, var(--mat-sys-on-surface) 38%, transparent))}.mat-calendar-body-selected.mat-calendar-body-today{box-shadow:inset 0 0 0 1px var(--mat-datepicker-calendar-date-today-selected-state-outline-color, var(--mat-sys-primary))}.mat-calendar-body-in-range::before{background:var(--mat-datepicker-calendar-date-in-range-state-background-color, var(--mat-sys-primary-container))}.mat-calendar-body-comparison-identical,.mat-calendar-body-in-comparison-range::before{background:var(--mat-datepicker-calendar-date-in-comparison-range-state-background-color, var(--mat-sys-tertiary-container))}.mat-calendar-body-comparison-identical,.mat-calendar-body-in-comparison-range::before{background:var(--mat-datepicker-calendar-date-in-comparison-range-state-background-color, var(--mat-sys-tertiary-container))}.mat-calendar-body-comparison-bridge-start::before,[dir=rtl] .mat-calendar-body-comparison-bridge-end::before{background:linear-gradient(to right, var(--mat-datepicker-calendar-date-in-range-state-background-color, var(--mat-sys-primary-container)) 50%, var(--mat-datepicker-calendar-date-in-comparison-range-state-background-color, var(--mat-sys-tertiary-container)) 50%)}.mat-calendar-body-comparison-bridge-end::before,[dir=rtl] .mat-calendar-body-comparison-bridge-start::before{background:linear-gradient(to left, var(--mat-datepicker-calendar-date-in-range-state-background-color, var(--mat-sys-primary-container)) 50%, var(--mat-datepicker-calendar-date-in-comparison-range-state-background-color, var(--mat-sys-tertiary-container)) 50%)}.mat-calendar-body-in-range>.mat-calendar-body-comparison-identical,.mat-calendar-body-in-comparison-range.mat-calendar-body-in-range::after{background:var(--mat-datepicker-calendar-date-in-overlap-range-state-background-color, var(--mat-sys-secondary-container))}.mat-calendar-body-comparison-identical.mat-calendar-body-selected,.mat-calendar-body-in-comparison-range>.mat-calendar-body-selected{background:var(--mat-datepicker-calendar-date-in-overlap-range-selected-state-background-color, var(--mat-sys-secondary))}@media(forced-colors: active){.mat-datepicker-popup:not(:empty),.mat-calendar-body-cell:not(.mat-calendar-body-in-range) .mat-calendar-body-selected{outline:solid 1px}.mat-calendar-body-today{outline:dotted 1px}.mat-calendar-body-cell::before,.mat-calendar-body-cell::after,.mat-calendar-body-selected{background:none}.mat-calendar-body-in-range::before,.mat-calendar-body-comparison-bridge-start::before,.mat-calendar-body-comparison-bridge-end::before{border-top:solid 1px;border-bottom:solid 1px}.mat-calendar-body-range-start::before{border-left:solid 1px}[dir=rtl] .mat-calendar-body-range-start::before{border-left:0;border-right:solid 1px}.mat-calendar-body-range-end::before{border-right:solid 1px}[dir=rtl] .mat-calendar-body-range-end::before{border-right:0;border-left:solid 1px}.mat-calendar-body-in-comparison-range::before{border-top:dashed 1px;border-bottom:dashed 1px}.mat-calendar-body-comparison-start::before{border-left:dashed 1px}[dir=rtl] .mat-calendar-body-comparison-start::before{border-left:0;border-right:dashed 1px}.mat-calendar-body-comparison-end::before{border-right:dashed 1px}[dir=rtl] .mat-calendar-body-comparison-end::before{border-right:0;border-left:dashed 1px}}\n"], dependencies: [{ kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
  551. }
  552. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatCalendarBody, decorators: [{
  553. type: Component,
  554. args: [{ selector: '[mat-calendar-body]', host: {
  555. 'class': 'mat-calendar-body',
  556. }, exportAs: 'matCalendarBody', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, imports: [NgClass], template: "<!--\n If there's not enough space in the first row, create a separate label row. We mark this row as\n aria-hidden because we don't want it to be read out as one of the weeks in the month.\n-->\n@if (_firstRowOffset < labelMinRequiredCells) {\n <tr aria-hidden=\"true\">\n <td class=\"mat-calendar-body-label\"\n [attr.colspan]=\"numCols\"\n [style.paddingTop]=\"_cellPadding\"\n [style.paddingBottom]=\"_cellPadding\">\n {{label}}\n </td>\n </tr>\n}\n\n<!-- Create the first row separately so we can include a special spacer cell. -->\n@for (row of rows; track _trackRow(row); let rowIndex = $index) {\n <tr role=\"row\">\n <!--\n This cell is purely decorative, but we can't put `aria-hidden` or `role=\"presentation\"` on it,\n because it throws off the week days for the rest of the row on NVDA. The aspect ratio of the\n table cells is maintained by setting the top and bottom padding as a percentage of the width\n (a variant of the trick described here: https://www.w3schools.com/howto/howto_css_aspect_ratio.asp).\n -->\n @if (rowIndex === 0 && _firstRowOffset) {\n <td\n class=\"mat-calendar-body-label\"\n [attr.colspan]=\"_firstRowOffset\"\n [style.paddingTop]=\"_cellPadding\"\n [style.paddingBottom]=\"_cellPadding\">\n {{_firstRowOffset >= labelMinRequiredCells ? label : ''}}\n </td>\n }\n <!--\n Each gridcell in the calendar contains a button, which signals to assistive technology that the\n cell is interactable, as well as the selection state via `aria-pressed`. See #23476 for\n background.\n -->\n @for (item of row; track item.id; let colIndex = $index) {\n <td\n role=\"gridcell\"\n class=\"mat-calendar-body-cell-container\"\n [style.width]=\"_cellWidth\"\n [style.paddingTop]=\"_cellPadding\"\n [style.paddingBottom]=\"_cellPadding\"\n [attr.data-mat-row]=\"rowIndex\"\n [attr.data-mat-col]=\"colIndex\"\n >\n <button\n type=\"button\"\n class=\"mat-calendar-body-cell\"\n [ngClass]=\"item.cssClasses\"\n [tabindex]=\"_isActiveCell(rowIndex, colIndex) ? 0 : -1\"\n [class.mat-calendar-body-disabled]=\"!item.enabled\"\n [class.mat-calendar-body-active]=\"_isActiveCell(rowIndex, colIndex)\"\n [class.mat-calendar-body-range-start]=\"_isRangeStart(item.compareValue)\"\n [class.mat-calendar-body-range-end]=\"_isRangeEnd(item.compareValue)\"\n [class.mat-calendar-body-in-range]=\"_isInRange(item.compareValue)\"\n [class.mat-calendar-body-comparison-bridge-start]=\"_isComparisonBridgeStart(item.compareValue, rowIndex, colIndex)\"\n [class.mat-calendar-body-comparison-bridge-end]=\"_isComparisonBridgeEnd(item.compareValue, rowIndex, colIndex)\"\n [class.mat-calendar-body-comparison-start]=\"_isComparisonStart(item.compareValue)\"\n [class.mat-calendar-body-comparison-end]=\"_isComparisonEnd(item.compareValue)\"\n [class.mat-calendar-body-in-comparison-range]=\"_isInComparisonRange(item.compareValue)\"\n [class.mat-calendar-body-preview-start]=\"_isPreviewStart(item.compareValue)\"\n [class.mat-calendar-body-preview-end]=\"_isPreviewEnd(item.compareValue)\"\n [class.mat-calendar-body-in-preview]=\"_isInPreview(item.compareValue)\"\n [attr.aria-label]=\"item.ariaLabel\"\n [attr.aria-disabled]=\"!item.enabled || null\"\n [attr.aria-pressed]=\"_isSelected(item.compareValue)\"\n [attr.aria-current]=\"todayValue === item.compareValue ? 'date' : null\"\n [attr.aria-describedby]=\"_getDescribedby(item.compareValue)\"\n (click)=\"_cellClicked(item, $event)\"\n (focus)=\"_emitActiveDateChange(item, $event)\">\n <span class=\"mat-calendar-body-cell-content mat-focus-indicator\"\n [class.mat-calendar-body-selected]=\"_isSelected(item.compareValue)\"\n [class.mat-calendar-body-comparison-identical]=\"_isComparisonIdentical(item.compareValue)\"\n [class.mat-calendar-body-today]=\"todayValue === item.compareValue\">\n {{item.displayValue}}\n </span>\n <span class=\"mat-calendar-body-cell-preview\" aria-hidden=\"true\"></span>\n </button>\n </td>\n }\n </tr>\n}\n\n<span [id]=\"_startDateLabelId\" class=\"mat-calendar-body-hidden-label\">\n {{startDateAccessibleName}}\n</span>\n<span [id]=\"_endDateLabelId\" class=\"mat-calendar-body-hidden-label\">\n {{endDateAccessibleName}}\n</span>\n<span [id]=\"_comparisonStartDateLabelId\" class=\"mat-calendar-body-hidden-label\">\n {{comparisonDateAccessibleName}} {{startDateAccessibleName}}\n</span>\n<span [id]=\"_comparisonEndDateLabelId\" class=\"mat-calendar-body-hidden-label\">\n {{comparisonDateAccessibleName}} {{endDateAccessibleName}}\n</span>\n", styles: [".mat-calendar-body{min-width:224px}.mat-calendar-body-today:not(.mat-calendar-body-selected):not(.mat-calendar-body-comparison-identical){border-color:var(--mat-datepicker-calendar-date-today-outline-color, var(--mat-sys-primary))}.mat-calendar-body-label{height:0;line-height:0;text-align:start;padding-left:4.7142857143%;padding-right:4.7142857143%;font-size:var(--mat-datepicker-calendar-body-label-text-size, var(--mat-sys-title-small-size));font-weight:var(--mat-datepicker-calendar-body-label-text-weight, var(--mat-sys-title-small-weight));color:var(--mat-datepicker-calendar-body-label-text-color, var(--mat-sys-on-surface))}.mat-calendar-body-hidden-label{display:none}.mat-calendar-body-cell-container{position:relative;height:0;line-height:0}.mat-calendar-body-cell{position:absolute;top:0;left:0;width:100%;height:100%;background:none;text-align:center;outline:none;font-family:inherit;margin:0;font-family:var(--mat-datepicker-calendar-text-font, var(--mat-sys-body-medium-font));font-size:var(--mat-datepicker-calendar-text-size, var(--mat-sys-body-medium-size));-webkit-user-select:none;user-select:none;cursor:pointer;outline:none;border:none;-webkit-tap-highlight-color:rgba(0,0,0,0)}.mat-calendar-body-cell::-moz-focus-inner{border:0}.mat-calendar-body-cell::before,.mat-calendar-body-cell::after,.mat-calendar-body-cell-preview{content:\"\";position:absolute;top:5%;left:0;z-index:0;box-sizing:border-box;display:block;height:90%;width:100%}.mat-calendar-body-range-start:not(.mat-calendar-body-in-comparison-range)::before,.mat-calendar-body-range-start::after,.mat-calendar-body-comparison-start:not(.mat-calendar-body-comparison-bridge-start)::before,.mat-calendar-body-comparison-start::after,.mat-calendar-body-preview-start .mat-calendar-body-cell-preview{left:5%;width:95%;border-top-left-radius:999px;border-bottom-left-radius:999px}[dir=rtl] .mat-calendar-body-range-start:not(.mat-calendar-body-in-comparison-range)::before,[dir=rtl] .mat-calendar-body-range-start::after,[dir=rtl] .mat-calendar-body-comparison-start:not(.mat-calendar-body-comparison-bridge-start)::before,[dir=rtl] .mat-calendar-body-comparison-start::after,[dir=rtl] .mat-calendar-body-preview-start .mat-calendar-body-cell-preview{left:0;border-radius:0;border-top-right-radius:999px;border-bottom-right-radius:999px}.mat-calendar-body-range-end:not(.mat-calendar-body-in-comparison-range)::before,.mat-calendar-body-range-end::after,.mat-calendar-body-comparison-end:not(.mat-calendar-body-comparison-bridge-end)::before,.mat-calendar-body-comparison-end::after,.mat-calendar-body-preview-end .mat-calendar-body-cell-preview{width:95%;border-top-right-radius:999px;border-bottom-right-radius:999px}[dir=rtl] .mat-calendar-body-range-end:not(.mat-calendar-body-in-comparison-range)::before,[dir=rtl] .mat-calendar-body-range-end::after,[dir=rtl] .mat-calendar-body-comparison-end:not(.mat-calendar-body-comparison-bridge-end)::before,[dir=rtl] .mat-calendar-body-comparison-end::after,[dir=rtl] .mat-calendar-body-preview-end .mat-calendar-body-cell-preview{left:5%;border-radius:0;border-top-left-radius:999px;border-bottom-left-radius:999px}[dir=rtl] .mat-calendar-body-comparison-bridge-start.mat-calendar-body-range-end::after,[dir=rtl] .mat-calendar-body-comparison-bridge-end.mat-calendar-body-range-start::after{width:95%;border-top-right-radius:999px;border-bottom-right-radius:999px}.mat-calendar-body-comparison-start.mat-calendar-body-range-end::after,[dir=rtl] .mat-calendar-body-comparison-start.mat-calendar-body-range-end::after,.mat-calendar-body-comparison-end.mat-calendar-body-range-start::after,[dir=rtl] .mat-calendar-body-comparison-end.mat-calendar-body-range-start::after{width:90%}.mat-calendar-body-in-preview{color:var(--mat-datepicker-calendar-date-preview-state-outline-color, var(--mat-sys-primary))}.mat-calendar-body-in-preview .mat-calendar-body-cell-preview{border-top:dashed 1px;border-bottom:dashed 1px}.mat-calendar-body-preview-start .mat-calendar-body-cell-preview{border-left:dashed 1px}[dir=rtl] .mat-calendar-body-preview-start .mat-calendar-body-cell-preview{border-left:0;border-right:dashed 1px}.mat-calendar-body-preview-end .mat-calendar-body-cell-preview{border-right:dashed 1px}[dir=rtl] .mat-calendar-body-preview-end .mat-calendar-body-cell-preview{border-right:0;border-left:dashed 1px}.mat-calendar-body-disabled{cursor:default}.mat-calendar-body-disabled>.mat-calendar-body-cell-content:not(.mat-calendar-body-selected):not(.mat-calendar-body-comparison-identical){color:var(--mat-datepicker-calendar-date-disabled-state-text-color, color-mix(in srgb, var(--mat-sys-on-surface) 38%, transparent))}.mat-calendar-body-disabled>.mat-calendar-body-today:not(.mat-calendar-body-selected):not(.mat-calendar-body-comparison-identical){border-color:var(--mat-datepicker-calendar-date-today-disabled-state-outline-color, color-mix(in srgb, var(--mat-sys-on-surface) 38%, transparent))}@media(forced-colors: active){.mat-calendar-body-disabled{opacity:.5}}.mat-calendar-body-cell-content{top:5%;left:5%;z-index:1;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;color:var(--mat-datepicker-calendar-date-text-color, var(--mat-sys-on-surface));border-color:var(--mat-datepicker-calendar-date-outline-color, transparent)}.mat-calendar-body-cell-content.mat-focus-indicator{position:absolute}@media(forced-colors: active){.mat-calendar-body-cell-content{border:none}}.cdk-keyboard-focused .mat-calendar-body-active>.mat-calendar-body-cell-content:not(.mat-calendar-body-selected):not(.mat-calendar-body-comparison-identical),.cdk-program-focused .mat-calendar-body-active>.mat-calendar-body-cell-content:not(.mat-calendar-body-selected):not(.mat-calendar-body-comparison-identical){background-color:var(--mat-datepicker-calendar-date-focus-state-background-color, color-mix(in srgb, var(--mat-sys-on-surface) calc(var(--mat-sys-focus-state-layer-opacity) * 100%), transparent))}@media(hover: hover){.mat-calendar-body-cell:not(.mat-calendar-body-disabled):hover>.mat-calendar-body-cell-content:not(.mat-calendar-body-selected):not(.mat-calendar-body-comparison-identical){background-color:var(--mat-datepicker-calendar-date-hover-state-background-color, color-mix(in srgb, var(--mat-sys-on-surface) calc(var(--mat-sys-hover-state-layer-opacity) * 100%), transparent))}}.mat-calendar-body-selected{background-color:var(--mat-datepicker-calendar-date-selected-state-background-color, var(--mat-sys-primary));color:var(--mat-datepicker-calendar-date-selected-state-text-color, var(--mat-sys-on-primary))}.mat-calendar-body-disabled>.mat-calendar-body-selected{background-color:var(--mat-datepicker-calendar-date-selected-disabled-state-background-color, color-mix(in srgb, var(--mat-sys-on-surface) 38%, transparent))}.mat-calendar-body-selected.mat-calendar-body-today{box-shadow:inset 0 0 0 1px var(--mat-datepicker-calendar-date-today-selected-state-outline-color, var(--mat-sys-primary))}.mat-calendar-body-in-range::before{background:var(--mat-datepicker-calendar-date-in-range-state-background-color, var(--mat-sys-primary-container))}.mat-calendar-body-comparison-identical,.mat-calendar-body-in-comparison-range::before{background:var(--mat-datepicker-calendar-date-in-comparison-range-state-background-color, var(--mat-sys-tertiary-container))}.mat-calendar-body-comparison-identical,.mat-calendar-body-in-comparison-range::before{background:var(--mat-datepicker-calendar-date-in-comparison-range-state-background-color, var(--mat-sys-tertiary-container))}.mat-calendar-body-comparison-bridge-start::before,[dir=rtl] .mat-calendar-body-comparison-bridge-end::before{background:linear-gradient(to right, var(--mat-datepicker-calendar-date-in-range-state-background-color, var(--mat-sys-primary-container)) 50%, var(--mat-datepicker-calendar-date-in-comparison-range-state-background-color, var(--mat-sys-tertiary-container)) 50%)}.mat-calendar-body-comparison-bridge-end::before,[dir=rtl] .mat-calendar-body-comparison-bridge-start::before{background:linear-gradient(to left, var(--mat-datepicker-calendar-date-in-range-state-background-color, var(--mat-sys-primary-container)) 50%, var(--mat-datepicker-calendar-date-in-comparison-range-state-background-color, var(--mat-sys-tertiary-container)) 50%)}.mat-calendar-body-in-range>.mat-calendar-body-comparison-identical,.mat-calendar-body-in-comparison-range.mat-calendar-body-in-range::after{background:var(--mat-datepicker-calendar-date-in-overlap-range-state-background-color, var(--mat-sys-secondary-container))}.mat-calendar-body-comparison-identical.mat-calendar-body-selected,.mat-calendar-body-in-comparison-range>.mat-calendar-body-selected{background:var(--mat-datepicker-calendar-date-in-overlap-range-selected-state-background-color, var(--mat-sys-secondary))}@media(forced-colors: active){.mat-datepicker-popup:not(:empty),.mat-calendar-body-cell:not(.mat-calendar-body-in-range) .mat-calendar-body-selected{outline:solid 1px}.mat-calendar-body-today{outline:dotted 1px}.mat-calendar-body-cell::before,.mat-calendar-body-cell::after,.mat-calendar-body-selected{background:none}.mat-calendar-body-in-range::before,.mat-calendar-body-comparison-bridge-start::before,.mat-calendar-body-comparison-bridge-end::before{border-top:solid 1px;border-bottom:solid 1px}.mat-calendar-body-range-start::before{border-left:solid 1px}[dir=rtl] .mat-calendar-body-range-start::before{border-left:0;border-right:solid 1px}.mat-calendar-body-range-end::before{border-right:solid 1px}[dir=rtl] .mat-calendar-body-range-end::before{border-right:0;border-left:solid 1px}.mat-calendar-body-in-comparison-range::before{border-top:dashed 1px;border-bottom:dashed 1px}.mat-calendar-body-comparison-start::before{border-left:dashed 1px}[dir=rtl] .mat-calendar-body-comparison-start::before{border-left:0;border-right:dashed 1px}.mat-calendar-body-comparison-end::before{border-right:dashed 1px}[dir=rtl] .mat-calendar-body-comparison-end::before{border-right:0;border-left:dashed 1px}}\n"] }]
  557. }], ctorParameters: () => [], propDecorators: { label: [{
  558. type: Input
  559. }], rows: [{
  560. type: Input
  561. }], todayValue: [{
  562. type: Input
  563. }], startValue: [{
  564. type: Input
  565. }], endValue: [{
  566. type: Input
  567. }], labelMinRequiredCells: [{
  568. type: Input
  569. }], numCols: [{
  570. type: Input
  571. }], activeCell: [{
  572. type: Input
  573. }], isRange: [{
  574. type: Input
  575. }], cellAspectRatio: [{
  576. type: Input
  577. }], comparisonStart: [{
  578. type: Input
  579. }], comparisonEnd: [{
  580. type: Input
  581. }], previewStart: [{
  582. type: Input
  583. }], previewEnd: [{
  584. type: Input
  585. }], startDateAccessibleName: [{
  586. type: Input
  587. }], endDateAccessibleName: [{
  588. type: Input
  589. }], selectedValueChange: [{
  590. type: Output
  591. }], previewChange: [{
  592. type: Output
  593. }], activeDateChange: [{
  594. type: Output
  595. }], dragStarted: [{
  596. type: Output
  597. }], dragEnded: [{
  598. type: Output
  599. }] } });
  600. /** Checks whether a node is a table cell element. */
  601. function isTableCell(node) {
  602. return node?.nodeName === 'TD';
  603. }
  604. /**
  605. * Gets the date table cell element that is or contains the specified element.
  606. * Or returns null if element is not part of a date cell.
  607. */
  608. function getCellElement(element) {
  609. let cell;
  610. if (isTableCell(element)) {
  611. cell = element;
  612. }
  613. else if (isTableCell(element.parentNode)) {
  614. cell = element.parentNode;
  615. }
  616. else if (isTableCell(element.parentNode?.parentNode)) {
  617. cell = element.parentNode.parentNode;
  618. }
  619. return cell?.getAttribute('data-mat-row') != null ? cell : null;
  620. }
  621. /** Checks whether a value is the start of a range. */
  622. function isStart(value, start, end) {
  623. return end !== null && start !== end && value < end && value === start;
  624. }
  625. /** Checks whether a value is the end of a range. */
  626. function isEnd(value, start, end) {
  627. return start !== null && start !== end && value >= start && value === end;
  628. }
  629. /** Checks whether a value is inside of a range. */
  630. function isInRange(value, start, end, rangeEnabled) {
  631. return (rangeEnabled &&
  632. start !== null &&
  633. end !== null &&
  634. start !== end &&
  635. value >= start &&
  636. value <= end);
  637. }
  638. /**
  639. * Extracts the element that actually corresponds to a touch event's location
  640. * (rather than the element that initiated the sequence of touch events).
  641. */
  642. function getActualTouchTarget(event) {
  643. const touchLocation = event.changedTouches[0];
  644. return document.elementFromPoint(touchLocation.clientX, touchLocation.clientY);
  645. }
  646. /** A class representing a range of dates. */
  647. class DateRange {
  648. start;
  649. end;
  650. /**
  651. * Ensures that objects with a `start` and `end` property can't be assigned to a variable that
  652. * expects a `DateRange`
  653. */
  654. // tslint:disable-next-line:no-unused-variable
  655. _disableStructuralEquivalency;
  656. constructor(
  657. /** The start date of the range. */
  658. start,
  659. /** The end date of the range. */
  660. end) {
  661. this.start = start;
  662. this.end = end;
  663. }
  664. }
  665. /**
  666. * A selection model containing a date selection.
  667. * @docs-private
  668. */
  669. class MatDateSelectionModel {
  670. selection;
  671. _adapter;
  672. _selectionChanged = new Subject();
  673. /** Emits when the selection has changed. */
  674. selectionChanged = this._selectionChanged;
  675. constructor(
  676. /** The current selection. */
  677. selection, _adapter) {
  678. this.selection = selection;
  679. this._adapter = _adapter;
  680. this.selection = selection;
  681. }
  682. /**
  683. * Updates the current selection in the model.
  684. * @param value New selection that should be assigned.
  685. * @param source Object that triggered the selection change.
  686. */
  687. updateSelection(value, source) {
  688. const oldValue = this.selection;
  689. this.selection = value;
  690. this._selectionChanged.next({ selection: value, source, oldValue });
  691. }
  692. ngOnDestroy() {
  693. this._selectionChanged.complete();
  694. }
  695. _isValidDateInstance(date) {
  696. return this._adapter.isDateInstance(date) && this._adapter.isValid(date);
  697. }
  698. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDateSelectionModel, deps: "invalid", target: i0.ɵɵFactoryTarget.Injectable });
  699. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDateSelectionModel });
  700. }
  701. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDateSelectionModel, decorators: [{
  702. type: Injectable
  703. }], ctorParameters: () => [{ type: undefined }, { type: DateAdapter }] });
  704. /**
  705. * A selection model that contains a single date.
  706. * @docs-private
  707. */
  708. class MatSingleDateSelectionModel extends MatDateSelectionModel {
  709. constructor(adapter) {
  710. super(null, adapter);
  711. }
  712. /**
  713. * Adds a date to the current selection. In the case of a single date selection, the added date
  714. * simply overwrites the previous selection
  715. */
  716. add(date) {
  717. super.updateSelection(date, this);
  718. }
  719. /** Checks whether the current selection is valid. */
  720. isValid() {
  721. return this.selection != null && this._isValidDateInstance(this.selection);
  722. }
  723. /**
  724. * Checks whether the current selection is complete. In the case of a single date selection, this
  725. * is true if the current selection is not null.
  726. */
  727. isComplete() {
  728. return this.selection != null;
  729. }
  730. /** Clones the selection model. */
  731. clone() {
  732. const clone = new MatSingleDateSelectionModel(this._adapter);
  733. clone.updateSelection(this.selection, this);
  734. return clone;
  735. }
  736. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatSingleDateSelectionModel, deps: [{ token: DateAdapter }], target: i0.ɵɵFactoryTarget.Injectable });
  737. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatSingleDateSelectionModel });
  738. }
  739. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatSingleDateSelectionModel, decorators: [{
  740. type: Injectable
  741. }], ctorParameters: () => [{ type: DateAdapter }] });
  742. /**
  743. * A selection model that contains a date range.
  744. * @docs-private
  745. */
  746. class MatRangeDateSelectionModel extends MatDateSelectionModel {
  747. constructor(adapter) {
  748. super(new DateRange(null, null), adapter);
  749. }
  750. /**
  751. * Adds a date to the current selection. In the case of a date range selection, the added date
  752. * fills in the next `null` value in the range. If both the start and the end already have a date,
  753. * the selection is reset so that the given date is the new `start` and the `end` is null.
  754. */
  755. add(date) {
  756. let { start, end } = this.selection;
  757. if (start == null) {
  758. start = date;
  759. }
  760. else if (end == null) {
  761. end = date;
  762. }
  763. else {
  764. start = date;
  765. end = null;
  766. }
  767. super.updateSelection(new DateRange(start, end), this);
  768. }
  769. /** Checks whether the current selection is valid. */
  770. isValid() {
  771. const { start, end } = this.selection;
  772. // Empty ranges are valid.
  773. if (start == null && end == null) {
  774. return true;
  775. }
  776. // Complete ranges are only valid if both dates are valid and the start is before the end.
  777. if (start != null && end != null) {
  778. return (this._isValidDateInstance(start) &&
  779. this._isValidDateInstance(end) &&
  780. this._adapter.compareDate(start, end) <= 0);
  781. }
  782. // Partial ranges are valid if the start/end is valid.
  783. return ((start == null || this._isValidDateInstance(start)) &&
  784. (end == null || this._isValidDateInstance(end)));
  785. }
  786. /**
  787. * Checks whether the current selection is complete. In the case of a date range selection, this
  788. * is true if the current selection has a non-null `start` and `end`.
  789. */
  790. isComplete() {
  791. return this.selection.start != null && this.selection.end != null;
  792. }
  793. /** Clones the selection model. */
  794. clone() {
  795. const clone = new MatRangeDateSelectionModel(this._adapter);
  796. clone.updateSelection(this.selection, this);
  797. return clone;
  798. }
  799. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatRangeDateSelectionModel, deps: [{ token: DateAdapter }], target: i0.ɵɵFactoryTarget.Injectable });
  800. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatRangeDateSelectionModel });
  801. }
  802. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatRangeDateSelectionModel, decorators: [{
  803. type: Injectable
  804. }], ctorParameters: () => [{ type: DateAdapter }] });
  805. /**
  806. * @docs-private
  807. * @deprecated No longer used, will be removed.
  808. * @breaking-change 21.0.0
  809. */
  810. function MAT_SINGLE_DATE_SELECTION_MODEL_FACTORY(parent, adapter) {
  811. return parent || new MatSingleDateSelectionModel(adapter);
  812. }
  813. /**
  814. * Used to provide a single selection model to a component.
  815. * @docs-private
  816. * @deprecated No longer used, will be removed.
  817. * @breaking-change 21.0.0
  818. */
  819. const MAT_SINGLE_DATE_SELECTION_MODEL_PROVIDER = {
  820. provide: MatDateSelectionModel,
  821. deps: [[new Optional(), new SkipSelf(), MatDateSelectionModel], DateAdapter],
  822. useFactory: MAT_SINGLE_DATE_SELECTION_MODEL_FACTORY,
  823. };
  824. /**
  825. * @docs-private
  826. * @deprecated No longer used, will be removed.
  827. * @breaking-change 21.0.0
  828. */
  829. function MAT_RANGE_DATE_SELECTION_MODEL_FACTORY(parent, adapter) {
  830. return parent || new MatRangeDateSelectionModel(adapter);
  831. }
  832. /**
  833. * Used to provide a range selection model to a component.
  834. * @docs-private
  835. * @deprecated No longer used, will be removed.
  836. * @breaking-change 21.0.0
  837. */
  838. const MAT_RANGE_DATE_SELECTION_MODEL_PROVIDER = {
  839. provide: MatDateSelectionModel,
  840. deps: [[new Optional(), new SkipSelf(), MatDateSelectionModel], DateAdapter],
  841. useFactory: MAT_RANGE_DATE_SELECTION_MODEL_FACTORY,
  842. };
  843. /** Injection token used to customize the date range selection behavior. */
  844. const MAT_DATE_RANGE_SELECTION_STRATEGY = new InjectionToken('MAT_DATE_RANGE_SELECTION_STRATEGY');
  845. /** Provides the default date range selection behavior. */
  846. class DefaultMatCalendarRangeStrategy {
  847. _dateAdapter;
  848. constructor(_dateAdapter) {
  849. this._dateAdapter = _dateAdapter;
  850. }
  851. selectionFinished(date, currentRange) {
  852. let { start, end } = currentRange;
  853. if (start == null) {
  854. start = date;
  855. }
  856. else if (end == null && date && this._dateAdapter.compareDate(date, start) >= 0) {
  857. end = date;
  858. }
  859. else {
  860. start = date;
  861. end = null;
  862. }
  863. return new DateRange(start, end);
  864. }
  865. createPreview(activeDate, currentRange) {
  866. let start = null;
  867. let end = null;
  868. if (currentRange.start && !currentRange.end && activeDate) {
  869. start = currentRange.start;
  870. end = activeDate;
  871. }
  872. return new DateRange(start, end);
  873. }
  874. createDrag(dragOrigin, originalRange, newDate) {
  875. let start = originalRange.start;
  876. let end = originalRange.end;
  877. if (!start || !end) {
  878. // Can't drag from an incomplete range.
  879. return null;
  880. }
  881. const adapter = this._dateAdapter;
  882. const isRange = adapter.compareDate(start, end) !== 0;
  883. const diffYears = adapter.getYear(newDate) - adapter.getYear(dragOrigin);
  884. const diffMonths = adapter.getMonth(newDate) - adapter.getMonth(dragOrigin);
  885. const diffDays = adapter.getDate(newDate) - adapter.getDate(dragOrigin);
  886. if (isRange && adapter.sameDate(dragOrigin, originalRange.start)) {
  887. start = newDate;
  888. if (adapter.compareDate(newDate, end) > 0) {
  889. end = adapter.addCalendarYears(end, diffYears);
  890. end = adapter.addCalendarMonths(end, diffMonths);
  891. end = adapter.addCalendarDays(end, diffDays);
  892. }
  893. }
  894. else if (isRange && adapter.sameDate(dragOrigin, originalRange.end)) {
  895. end = newDate;
  896. if (adapter.compareDate(newDate, start) < 0) {
  897. start = adapter.addCalendarYears(start, diffYears);
  898. start = adapter.addCalendarMonths(start, diffMonths);
  899. start = adapter.addCalendarDays(start, diffDays);
  900. }
  901. }
  902. else {
  903. start = adapter.addCalendarYears(start, diffYears);
  904. start = adapter.addCalendarMonths(start, diffMonths);
  905. start = adapter.addCalendarDays(start, diffDays);
  906. end = adapter.addCalendarYears(end, diffYears);
  907. end = adapter.addCalendarMonths(end, diffMonths);
  908. end = adapter.addCalendarDays(end, diffDays);
  909. }
  910. return new DateRange(start, end);
  911. }
  912. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: DefaultMatCalendarRangeStrategy, deps: [{ token: DateAdapter }], target: i0.ɵɵFactoryTarget.Injectable });
  913. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: DefaultMatCalendarRangeStrategy });
  914. }
  915. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: DefaultMatCalendarRangeStrategy, decorators: [{
  916. type: Injectable
  917. }], ctorParameters: () => [{ type: DateAdapter }] });
  918. /**
  919. * @docs-private
  920. * @deprecated No longer used, will be removed.
  921. * @breaking-change 21.0.0
  922. */
  923. function MAT_CALENDAR_RANGE_STRATEGY_PROVIDER_FACTORY(parent, adapter) {
  924. return parent || new DefaultMatCalendarRangeStrategy(adapter);
  925. }
  926. /**
  927. * @docs-private
  928. * @deprecated No longer used, will be removed.
  929. * @breaking-change 21.0.0
  930. */
  931. const MAT_CALENDAR_RANGE_STRATEGY_PROVIDER = {
  932. provide: MAT_DATE_RANGE_SELECTION_STRATEGY,
  933. deps: [[new Optional(), new SkipSelf(), MAT_DATE_RANGE_SELECTION_STRATEGY], DateAdapter],
  934. useFactory: MAT_CALENDAR_RANGE_STRATEGY_PROVIDER_FACTORY,
  935. };
  936. const DAYS_PER_WEEK = 7;
  937. let uniqueIdCounter = 0;
  938. /**
  939. * An internal component used to display a single month in the datepicker.
  940. * @docs-private
  941. */
  942. class MatMonthView {
  943. _changeDetectorRef = inject(ChangeDetectorRef);
  944. _dateFormats = inject(MAT_DATE_FORMATS, { optional: true });
  945. _dateAdapter = inject(DateAdapter, { optional: true });
  946. _dir = inject(Directionality, { optional: true });
  947. _rangeStrategy = inject(MAT_DATE_RANGE_SELECTION_STRATEGY, { optional: true });
  948. _rerenderSubscription = Subscription.EMPTY;
  949. /** Flag used to filter out space/enter keyup events that originated outside of the view. */
  950. _selectionKeyPressed;
  951. /**
  952. * The date to display in this month view (everything other than the month and year is ignored).
  953. */
  954. get activeDate() {
  955. return this._activeDate;
  956. }
  957. set activeDate(value) {
  958. const oldActiveDate = this._activeDate;
  959. const validDate = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value)) ||
  960. this._dateAdapter.today();
  961. this._activeDate = this._dateAdapter.clampDate(validDate, this.minDate, this.maxDate);
  962. if (!this._hasSameMonthAndYear(oldActiveDate, this._activeDate)) {
  963. this._init();
  964. }
  965. }
  966. _activeDate;
  967. /** The currently selected date. */
  968. get selected() {
  969. return this._selected;
  970. }
  971. set selected(value) {
  972. if (value instanceof DateRange) {
  973. this._selected = value;
  974. }
  975. else {
  976. this._selected = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value));
  977. }
  978. this._setRanges(this._selected);
  979. }
  980. _selected;
  981. /** The minimum selectable date. */
  982. get minDate() {
  983. return this._minDate;
  984. }
  985. set minDate(value) {
  986. this._minDate = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value));
  987. }
  988. _minDate;
  989. /** The maximum selectable date. */
  990. get maxDate() {
  991. return this._maxDate;
  992. }
  993. set maxDate(value) {
  994. this._maxDate = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value));
  995. }
  996. _maxDate;
  997. /** Function used to filter which dates are selectable. */
  998. dateFilter;
  999. /** Function that can be used to add custom CSS classes to dates. */
  1000. dateClass;
  1001. /** Start of the comparison range. */
  1002. comparisonStart;
  1003. /** End of the comparison range. */
  1004. comparisonEnd;
  1005. /** ARIA Accessible name of the `<input matStartDate/>` */
  1006. startDateAccessibleName;
  1007. /** ARIA Accessible name of the `<input matEndDate/>` */
  1008. endDateAccessibleName;
  1009. /** Origin of active drag, or null when dragging is not active. */
  1010. activeDrag = null;
  1011. /** Emits when a new date is selected. */
  1012. selectedChange = new EventEmitter();
  1013. /** Emits when any date is selected. */
  1014. _userSelection = new EventEmitter();
  1015. /** Emits when the user initiates a date range drag via mouse or touch. */
  1016. dragStarted = new EventEmitter();
  1017. /**
  1018. * Emits when the user completes or cancels a date range drag.
  1019. * Emits null when the drag was canceled or the newly selected date range if completed.
  1020. */
  1021. dragEnded = new EventEmitter();
  1022. /** Emits when any date is activated. */
  1023. activeDateChange = new EventEmitter();
  1024. /** The body of calendar table */
  1025. _matCalendarBody;
  1026. /** The label for this month (e.g. "January 2017"). */
  1027. _monthLabel;
  1028. /** Grid of calendar cells representing the dates of the month. */
  1029. _weeks;
  1030. /** The number of blank cells in the first row before the 1st of the month. */
  1031. _firstWeekOffset;
  1032. /** Start value of the currently-shown date range. */
  1033. _rangeStart;
  1034. /** End value of the currently-shown date range. */
  1035. _rangeEnd;
  1036. /** Start value of the currently-shown comparison date range. */
  1037. _comparisonRangeStart;
  1038. /** End value of the currently-shown comparison date range. */
  1039. _comparisonRangeEnd;
  1040. /** Start of the preview range. */
  1041. _previewStart;
  1042. /** End of the preview range. */
  1043. _previewEnd;
  1044. /** Whether the user is currently selecting a range of dates. */
  1045. _isRange;
  1046. /** The date of the month that today falls on. Null if today is in another month. */
  1047. _todayDate;
  1048. /** The names of the weekdays. */
  1049. _weekdays;
  1050. constructor() {
  1051. inject(_CdkPrivateStyleLoader).load(_VisuallyHiddenLoader);
  1052. if (typeof ngDevMode === 'undefined' || ngDevMode) {
  1053. if (!this._dateAdapter) {
  1054. throw createMissingDateImplError('DateAdapter');
  1055. }
  1056. if (!this._dateFormats) {
  1057. throw createMissingDateImplError('MAT_DATE_FORMATS');
  1058. }
  1059. }
  1060. this._activeDate = this._dateAdapter.today();
  1061. }
  1062. ngAfterContentInit() {
  1063. this._rerenderSubscription = this._dateAdapter.localeChanges
  1064. .pipe(startWith(null))
  1065. .subscribe(() => this._init());
  1066. }
  1067. ngOnChanges(changes) {
  1068. const comparisonChange = changes['comparisonStart'] || changes['comparisonEnd'];
  1069. if (comparisonChange && !comparisonChange.firstChange) {
  1070. this._setRanges(this.selected);
  1071. }
  1072. if (changes['activeDrag'] && !this.activeDrag) {
  1073. this._clearPreview();
  1074. }
  1075. }
  1076. ngOnDestroy() {
  1077. this._rerenderSubscription.unsubscribe();
  1078. }
  1079. /** Handles when a new date is selected. */
  1080. _dateSelected(event) {
  1081. const date = event.value;
  1082. const selectedDate = this._getDateFromDayOfMonth(date);
  1083. let rangeStartDate;
  1084. let rangeEndDate;
  1085. if (this._selected instanceof DateRange) {
  1086. rangeStartDate = this._getDateInCurrentMonth(this._selected.start);
  1087. rangeEndDate = this._getDateInCurrentMonth(this._selected.end);
  1088. }
  1089. else {
  1090. rangeStartDate = rangeEndDate = this._getDateInCurrentMonth(this._selected);
  1091. }
  1092. if (rangeStartDate !== date || rangeEndDate !== date) {
  1093. this.selectedChange.emit(selectedDate);
  1094. }
  1095. this._userSelection.emit({ value: selectedDate, event: event.event });
  1096. this._clearPreview();
  1097. this._changeDetectorRef.markForCheck();
  1098. }
  1099. /**
  1100. * Takes the index of a calendar body cell wrapped in an event as argument. For the date that
  1101. * corresponds to the given cell, set `activeDate` to that date and fire `activeDateChange` with
  1102. * that date.
  1103. *
  1104. * This function is used to match each component's model of the active date with the calendar
  1105. * body cell that was focused. It updates its value of `activeDate` synchronously and updates the
  1106. * parent's value asynchronously via the `activeDateChange` event. The child component receives an
  1107. * updated value asynchronously via the `activeCell` Input.
  1108. */
  1109. _updateActiveDate(event) {
  1110. const month = event.value;
  1111. const oldActiveDate = this._activeDate;
  1112. this.activeDate = this._getDateFromDayOfMonth(month);
  1113. if (this._dateAdapter.compareDate(oldActiveDate, this.activeDate)) {
  1114. this.activeDateChange.emit(this._activeDate);
  1115. }
  1116. }
  1117. /** Handles keydown events on the calendar body when calendar is in month view. */
  1118. _handleCalendarBodyKeydown(event) {
  1119. // TODO(mmalerba): We currently allow keyboard navigation to disabled dates, but just prevent
  1120. // disabled ones from being selected. This may not be ideal, we should look into whether
  1121. // navigation should skip over disabled dates, and if so, how to implement that efficiently.
  1122. const oldActiveDate = this._activeDate;
  1123. const isRtl = this._isRtl();
  1124. switch (event.keyCode) {
  1125. case LEFT_ARROW:
  1126. this.activeDate = this._dateAdapter.addCalendarDays(this._activeDate, isRtl ? 1 : -1);
  1127. break;
  1128. case RIGHT_ARROW:
  1129. this.activeDate = this._dateAdapter.addCalendarDays(this._activeDate, isRtl ? -1 : 1);
  1130. break;
  1131. case UP_ARROW:
  1132. this.activeDate = this._dateAdapter.addCalendarDays(this._activeDate, -7);
  1133. break;
  1134. case DOWN_ARROW:
  1135. this.activeDate = this._dateAdapter.addCalendarDays(this._activeDate, 7);
  1136. break;
  1137. case HOME:
  1138. this.activeDate = this._dateAdapter.addCalendarDays(this._activeDate, 1 - this._dateAdapter.getDate(this._activeDate));
  1139. break;
  1140. case END:
  1141. this.activeDate = this._dateAdapter.addCalendarDays(this._activeDate, this._dateAdapter.getNumDaysInMonth(this._activeDate) -
  1142. this._dateAdapter.getDate(this._activeDate));
  1143. break;
  1144. case PAGE_UP:
  1145. this.activeDate = event.altKey
  1146. ? this._dateAdapter.addCalendarYears(this._activeDate, -1)
  1147. : this._dateAdapter.addCalendarMonths(this._activeDate, -1);
  1148. break;
  1149. case PAGE_DOWN:
  1150. this.activeDate = event.altKey
  1151. ? this._dateAdapter.addCalendarYears(this._activeDate, 1)
  1152. : this._dateAdapter.addCalendarMonths(this._activeDate, 1);
  1153. break;
  1154. case ENTER:
  1155. case SPACE:
  1156. this._selectionKeyPressed = true;
  1157. if (this._canSelect(this._activeDate)) {
  1158. // Prevent unexpected default actions such as form submission.
  1159. // Note that we only prevent the default action here while the selection happens in
  1160. // `keyup` below. We can't do the selection here, because it can cause the calendar to
  1161. // reopen if focus is restored immediately. We also can't call `preventDefault` on `keyup`
  1162. // because it's too late (see #23305).
  1163. event.preventDefault();
  1164. }
  1165. return;
  1166. case ESCAPE:
  1167. // Abort the current range selection if the user presses escape mid-selection.
  1168. if (this._previewEnd != null && !hasModifierKey(event)) {
  1169. this._clearPreview();
  1170. // If a drag is in progress, cancel the drag without changing the
  1171. // current selection.
  1172. if (this.activeDrag) {
  1173. this.dragEnded.emit({ value: null, event });
  1174. }
  1175. else {
  1176. this.selectedChange.emit(null);
  1177. this._userSelection.emit({ value: null, event });
  1178. }
  1179. event.preventDefault();
  1180. event.stopPropagation(); // Prevents the overlay from closing.
  1181. }
  1182. return;
  1183. default:
  1184. // Don't prevent default or focus active cell on keys that we don't explicitly handle.
  1185. return;
  1186. }
  1187. if (this._dateAdapter.compareDate(oldActiveDate, this.activeDate)) {
  1188. this.activeDateChange.emit(this.activeDate);
  1189. this._focusActiveCellAfterViewChecked();
  1190. }
  1191. // Prevent unexpected default actions such as form submission.
  1192. event.preventDefault();
  1193. }
  1194. /** Handles keyup events on the calendar body when calendar is in month view. */
  1195. _handleCalendarBodyKeyup(event) {
  1196. if (event.keyCode === SPACE || event.keyCode === ENTER) {
  1197. if (this._selectionKeyPressed && this._canSelect(this._activeDate)) {
  1198. this._dateSelected({ value: this._dateAdapter.getDate(this._activeDate), event });
  1199. }
  1200. this._selectionKeyPressed = false;
  1201. }
  1202. }
  1203. /** Initializes this month view. */
  1204. _init() {
  1205. this._setRanges(this.selected);
  1206. this._todayDate = this._getCellCompareValue(this._dateAdapter.today());
  1207. this._monthLabel = this._dateFormats.display.monthLabel
  1208. ? this._dateAdapter.format(this.activeDate, this._dateFormats.display.monthLabel)
  1209. : this._dateAdapter
  1210. .getMonthNames('short')[this._dateAdapter.getMonth(this.activeDate)].toLocaleUpperCase();
  1211. let firstOfMonth = this._dateAdapter.createDate(this._dateAdapter.getYear(this.activeDate), this._dateAdapter.getMonth(this.activeDate), 1);
  1212. this._firstWeekOffset =
  1213. (DAYS_PER_WEEK +
  1214. this._dateAdapter.getDayOfWeek(firstOfMonth) -
  1215. this._dateAdapter.getFirstDayOfWeek()) %
  1216. DAYS_PER_WEEK;
  1217. this._initWeekdays();
  1218. this._createWeekCells();
  1219. this._changeDetectorRef.markForCheck();
  1220. }
  1221. /** Focuses the active cell after the microtask queue is empty. */
  1222. _focusActiveCell(movePreview) {
  1223. this._matCalendarBody._focusActiveCell(movePreview);
  1224. }
  1225. /** Focuses the active cell after change detection has run and the microtask queue is empty. */
  1226. _focusActiveCellAfterViewChecked() {
  1227. this._matCalendarBody._scheduleFocusActiveCellAfterViewChecked();
  1228. }
  1229. /** Called when the user has activated a new cell and the preview needs to be updated. */
  1230. _previewChanged({ event, value: cell }) {
  1231. if (this._rangeStrategy) {
  1232. // We can assume that this will be a range, because preview
  1233. // events aren't fired for single date selections.
  1234. const value = cell ? cell.rawValue : null;
  1235. const previewRange = this._rangeStrategy.createPreview(value, this.selected, event);
  1236. this._previewStart = this._getCellCompareValue(previewRange.start);
  1237. this._previewEnd = this._getCellCompareValue(previewRange.end);
  1238. if (this.activeDrag && value) {
  1239. const dragRange = this._rangeStrategy.createDrag?.(this.activeDrag.value, this.selected, value, event);
  1240. if (dragRange) {
  1241. this._previewStart = this._getCellCompareValue(dragRange.start);
  1242. this._previewEnd = this._getCellCompareValue(dragRange.end);
  1243. }
  1244. }
  1245. // Note that here we need to use `detectChanges`, rather than `markForCheck`, because
  1246. // the way `_focusActiveCell` is set up at the moment makes it fire at the wrong time
  1247. // when navigating one month back using the keyboard which will cause this handler
  1248. // to throw a "changed after checked" error when updating the preview state.
  1249. this._changeDetectorRef.detectChanges();
  1250. }
  1251. }
  1252. /**
  1253. * Called when the user has ended a drag. If the drag/drop was successful,
  1254. * computes and emits the new range selection.
  1255. */
  1256. _dragEnded(event) {
  1257. if (!this.activeDrag)
  1258. return;
  1259. if (event.value) {
  1260. // Propagate drag effect
  1261. const dragDropResult = this._rangeStrategy?.createDrag?.(this.activeDrag.value, this.selected, event.value, event.event);
  1262. this.dragEnded.emit({ value: dragDropResult ?? null, event: event.event });
  1263. }
  1264. else {
  1265. this.dragEnded.emit({ value: null, event: event.event });
  1266. }
  1267. }
  1268. /**
  1269. * Takes a day of the month and returns a new date in the same month and year as the currently
  1270. * active date. The returned date will have the same day of the month as the argument date.
  1271. */
  1272. _getDateFromDayOfMonth(dayOfMonth) {
  1273. return this._dateAdapter.createDate(this._dateAdapter.getYear(this.activeDate), this._dateAdapter.getMonth(this.activeDate), dayOfMonth);
  1274. }
  1275. /** Initializes the weekdays. */
  1276. _initWeekdays() {
  1277. const firstDayOfWeek = this._dateAdapter.getFirstDayOfWeek();
  1278. const narrowWeekdays = this._dateAdapter.getDayOfWeekNames('narrow');
  1279. const longWeekdays = this._dateAdapter.getDayOfWeekNames('long');
  1280. // Rotate the labels for days of the week based on the configured first day of the week.
  1281. let weekdays = longWeekdays.map((long, i) => {
  1282. return { long, narrow: narrowWeekdays[i], id: uniqueIdCounter++ };
  1283. });
  1284. this._weekdays = weekdays.slice(firstDayOfWeek).concat(weekdays.slice(0, firstDayOfWeek));
  1285. }
  1286. /** Creates MatCalendarCells for the dates in this month. */
  1287. _createWeekCells() {
  1288. const daysInMonth = this._dateAdapter.getNumDaysInMonth(this.activeDate);
  1289. const dateNames = this._dateAdapter.getDateNames();
  1290. this._weeks = [[]];
  1291. for (let i = 0, cell = this._firstWeekOffset; i < daysInMonth; i++, cell++) {
  1292. if (cell == DAYS_PER_WEEK) {
  1293. this._weeks.push([]);
  1294. cell = 0;
  1295. }
  1296. const date = this._dateAdapter.createDate(this._dateAdapter.getYear(this.activeDate), this._dateAdapter.getMonth(this.activeDate), i + 1);
  1297. const enabled = this._shouldEnableDate(date);
  1298. const ariaLabel = this._dateAdapter.format(date, this._dateFormats.display.dateA11yLabel);
  1299. const cellClasses = this.dateClass ? this.dateClass(date, 'month') : undefined;
  1300. this._weeks[this._weeks.length - 1].push(new MatCalendarCell(i + 1, dateNames[i], ariaLabel, enabled, cellClasses, this._getCellCompareValue(date), date));
  1301. }
  1302. }
  1303. /** Date filter for the month */
  1304. _shouldEnableDate(date) {
  1305. return (!!date &&
  1306. (!this.minDate || this._dateAdapter.compareDate(date, this.minDate) >= 0) &&
  1307. (!this.maxDate || this._dateAdapter.compareDate(date, this.maxDate) <= 0) &&
  1308. (!this.dateFilter || this.dateFilter(date)));
  1309. }
  1310. /**
  1311. * Gets the date in this month that the given Date falls on.
  1312. * Returns null if the given Date is in another month.
  1313. */
  1314. _getDateInCurrentMonth(date) {
  1315. return date && this._hasSameMonthAndYear(date, this.activeDate)
  1316. ? this._dateAdapter.getDate(date)
  1317. : null;
  1318. }
  1319. /** Checks whether the 2 dates are non-null and fall within the same month of the same year. */
  1320. _hasSameMonthAndYear(d1, d2) {
  1321. return !!(d1 &&
  1322. d2 &&
  1323. this._dateAdapter.getMonth(d1) == this._dateAdapter.getMonth(d2) &&
  1324. this._dateAdapter.getYear(d1) == this._dateAdapter.getYear(d2));
  1325. }
  1326. /** Gets the value that will be used to one cell to another. */
  1327. _getCellCompareValue(date) {
  1328. if (date) {
  1329. // We use the time since the Unix epoch to compare dates in this view, rather than the
  1330. // cell values, because we need to support ranges that span across multiple months/years.
  1331. const year = this._dateAdapter.getYear(date);
  1332. const month = this._dateAdapter.getMonth(date);
  1333. const day = this._dateAdapter.getDate(date);
  1334. return new Date(year, month, day).getTime();
  1335. }
  1336. return null;
  1337. }
  1338. /** Determines whether the user has the RTL layout direction. */
  1339. _isRtl() {
  1340. return this._dir && this._dir.value === 'rtl';
  1341. }
  1342. /** Sets the current range based on a model value. */
  1343. _setRanges(selectedValue) {
  1344. if (selectedValue instanceof DateRange) {
  1345. this._rangeStart = this._getCellCompareValue(selectedValue.start);
  1346. this._rangeEnd = this._getCellCompareValue(selectedValue.end);
  1347. this._isRange = true;
  1348. }
  1349. else {
  1350. this._rangeStart = this._rangeEnd = this._getCellCompareValue(selectedValue);
  1351. this._isRange = false;
  1352. }
  1353. this._comparisonRangeStart = this._getCellCompareValue(this.comparisonStart);
  1354. this._comparisonRangeEnd = this._getCellCompareValue(this.comparisonEnd);
  1355. }
  1356. /** Gets whether a date can be selected in the month view. */
  1357. _canSelect(date) {
  1358. return !this.dateFilter || this.dateFilter(date);
  1359. }
  1360. /** Clears out preview state. */
  1361. _clearPreview() {
  1362. this._previewStart = this._previewEnd = null;
  1363. }
  1364. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatMonthView, deps: [], target: i0.ɵɵFactoryTarget.Component });
  1365. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.6", type: MatMonthView, isStandalone: true, selector: "mat-month-view", inputs: { activeDate: "activeDate", selected: "selected", minDate: "minDate", maxDate: "maxDate", dateFilter: "dateFilter", dateClass: "dateClass", comparisonStart: "comparisonStart", comparisonEnd: "comparisonEnd", startDateAccessibleName: "startDateAccessibleName", endDateAccessibleName: "endDateAccessibleName", activeDrag: "activeDrag" }, outputs: { selectedChange: "selectedChange", _userSelection: "_userSelection", dragStarted: "dragStarted", dragEnded: "dragEnded", activeDateChange: "activeDateChange" }, viewQueries: [{ propertyName: "_matCalendarBody", first: true, predicate: MatCalendarBody, descendants: true }], exportAs: ["matMonthView"], usesOnChanges: true, ngImport: i0, template: "<table class=\"mat-calendar-table\" role=\"grid\">\n <thead class=\"mat-calendar-table-header\">\n <tr>\n @for (day of _weekdays; track day.id) {\n <th scope=\"col\">\n <span class=\"cdk-visually-hidden\">{{day.long}}</span>\n <span aria-hidden=\"true\">{{day.narrow}}</span>\n </th>\n }\n </tr>\n <tr aria-hidden=\"true\"><th class=\"mat-calendar-table-header-divider\" colspan=\"7\"></th></tr>\n </thead>\n <tbody mat-calendar-body\n [label]=\"_monthLabel\"\n [rows]=\"_weeks\"\n [todayValue]=\"_todayDate!\"\n [startValue]=\"_rangeStart!\"\n [endValue]=\"_rangeEnd!\"\n [comparisonStart]=\"_comparisonRangeStart\"\n [comparisonEnd]=\"_comparisonRangeEnd\"\n [previewStart]=\"_previewStart\"\n [previewEnd]=\"_previewEnd\"\n [isRange]=\"_isRange\"\n [labelMinRequiredCells]=\"3\"\n [activeCell]=\"_dateAdapter.getDate(activeDate) - 1\"\n [startDateAccessibleName]=\"startDateAccessibleName\"\n [endDateAccessibleName]=\"endDateAccessibleName\"\n (selectedValueChange)=\"_dateSelected($event)\"\n (activeDateChange)=\"_updateActiveDate($event)\"\n (previewChange)=\"_previewChanged($event)\"\n (dragStarted)=\"dragStarted.emit($event)\"\n (dragEnded)=\"_dragEnded($event)\"\n (keyup)=\"_handleCalendarBodyKeyup($event)\"\n (keydown)=\"_handleCalendarBodyKeydown($event)\">\n </tbody>\n</table>\n", dependencies: [{ kind: "component", type: MatCalendarBody, selector: "[mat-calendar-body]", inputs: ["label", "rows", "todayValue", "startValue", "endValue", "labelMinRequiredCells", "numCols", "activeCell", "isRange", "cellAspectRatio", "comparisonStart", "comparisonEnd", "previewStart", "previewEnd", "startDateAccessibleName", "endDateAccessibleName"], outputs: ["selectedValueChange", "previewChange", "activeDateChange", "dragStarted", "dragEnded"], exportAs: ["matCalendarBody"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
  1366. }
  1367. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatMonthView, decorators: [{
  1368. type: Component,
  1369. args: [{ selector: 'mat-month-view', exportAs: 'matMonthView', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, imports: [MatCalendarBody], template: "<table class=\"mat-calendar-table\" role=\"grid\">\n <thead class=\"mat-calendar-table-header\">\n <tr>\n @for (day of _weekdays; track day.id) {\n <th scope=\"col\">\n <span class=\"cdk-visually-hidden\">{{day.long}}</span>\n <span aria-hidden=\"true\">{{day.narrow}}</span>\n </th>\n }\n </tr>\n <tr aria-hidden=\"true\"><th class=\"mat-calendar-table-header-divider\" colspan=\"7\"></th></tr>\n </thead>\n <tbody mat-calendar-body\n [label]=\"_monthLabel\"\n [rows]=\"_weeks\"\n [todayValue]=\"_todayDate!\"\n [startValue]=\"_rangeStart!\"\n [endValue]=\"_rangeEnd!\"\n [comparisonStart]=\"_comparisonRangeStart\"\n [comparisonEnd]=\"_comparisonRangeEnd\"\n [previewStart]=\"_previewStart\"\n [previewEnd]=\"_previewEnd\"\n [isRange]=\"_isRange\"\n [labelMinRequiredCells]=\"3\"\n [activeCell]=\"_dateAdapter.getDate(activeDate) - 1\"\n [startDateAccessibleName]=\"startDateAccessibleName\"\n [endDateAccessibleName]=\"endDateAccessibleName\"\n (selectedValueChange)=\"_dateSelected($event)\"\n (activeDateChange)=\"_updateActiveDate($event)\"\n (previewChange)=\"_previewChanged($event)\"\n (dragStarted)=\"dragStarted.emit($event)\"\n (dragEnded)=\"_dragEnded($event)\"\n (keyup)=\"_handleCalendarBodyKeyup($event)\"\n (keydown)=\"_handleCalendarBodyKeydown($event)\">\n </tbody>\n</table>\n" }]
  1370. }], ctorParameters: () => [], propDecorators: { activeDate: [{
  1371. type: Input
  1372. }], selected: [{
  1373. type: Input
  1374. }], minDate: [{
  1375. type: Input
  1376. }], maxDate: [{
  1377. type: Input
  1378. }], dateFilter: [{
  1379. type: Input
  1380. }], dateClass: [{
  1381. type: Input
  1382. }], comparisonStart: [{
  1383. type: Input
  1384. }], comparisonEnd: [{
  1385. type: Input
  1386. }], startDateAccessibleName: [{
  1387. type: Input
  1388. }], endDateAccessibleName: [{
  1389. type: Input
  1390. }], activeDrag: [{
  1391. type: Input
  1392. }], selectedChange: [{
  1393. type: Output
  1394. }], _userSelection: [{
  1395. type: Output
  1396. }], dragStarted: [{
  1397. type: Output
  1398. }], dragEnded: [{
  1399. type: Output
  1400. }], activeDateChange: [{
  1401. type: Output
  1402. }], _matCalendarBody: [{
  1403. type: ViewChild,
  1404. args: [MatCalendarBody]
  1405. }] } });
  1406. const yearsPerPage = 24;
  1407. const yearsPerRow = 4;
  1408. /**
  1409. * An internal component used to display a year selector in the datepicker.
  1410. * @docs-private
  1411. */
  1412. class MatMultiYearView {
  1413. _changeDetectorRef = inject(ChangeDetectorRef);
  1414. _dateAdapter = inject(DateAdapter, { optional: true });
  1415. _dir = inject(Directionality, { optional: true });
  1416. _rerenderSubscription = Subscription.EMPTY;
  1417. /** Flag used to filter out space/enter keyup events that originated outside of the view. */
  1418. _selectionKeyPressed;
  1419. /** The date to display in this multi-year view (everything other than the year is ignored). */
  1420. get activeDate() {
  1421. return this._activeDate;
  1422. }
  1423. set activeDate(value) {
  1424. let oldActiveDate = this._activeDate;
  1425. const validDate = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value)) ||
  1426. this._dateAdapter.today();
  1427. this._activeDate = this._dateAdapter.clampDate(validDate, this.minDate, this.maxDate);
  1428. if (!isSameMultiYearView(this._dateAdapter, oldActiveDate, this._activeDate, this.minDate, this.maxDate)) {
  1429. this._init();
  1430. }
  1431. }
  1432. _activeDate;
  1433. /** The currently selected date. */
  1434. get selected() {
  1435. return this._selected;
  1436. }
  1437. set selected(value) {
  1438. if (value instanceof DateRange) {
  1439. this._selected = value;
  1440. }
  1441. else {
  1442. this._selected = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value));
  1443. }
  1444. this._setSelectedYear(value);
  1445. }
  1446. _selected;
  1447. /** The minimum selectable date. */
  1448. get minDate() {
  1449. return this._minDate;
  1450. }
  1451. set minDate(value) {
  1452. this._minDate = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value));
  1453. }
  1454. _minDate;
  1455. /** The maximum selectable date. */
  1456. get maxDate() {
  1457. return this._maxDate;
  1458. }
  1459. set maxDate(value) {
  1460. this._maxDate = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value));
  1461. }
  1462. _maxDate;
  1463. /** A function used to filter which dates are selectable. */
  1464. dateFilter;
  1465. /** Function that can be used to add custom CSS classes to date cells. */
  1466. dateClass;
  1467. /** Emits when a new year is selected. */
  1468. selectedChange = new EventEmitter();
  1469. /** Emits the selected year. This doesn't imply a change on the selected date */
  1470. yearSelected = new EventEmitter();
  1471. /** Emits when any date is activated. */
  1472. activeDateChange = new EventEmitter();
  1473. /** The body of calendar table */
  1474. _matCalendarBody;
  1475. /** Grid of calendar cells representing the currently displayed years. */
  1476. _years;
  1477. /** The year that today falls on. */
  1478. _todayYear;
  1479. /** The year of the selected date. Null if the selected date is null. */
  1480. _selectedYear;
  1481. constructor() {
  1482. if (!this._dateAdapter && (typeof ngDevMode === 'undefined' || ngDevMode)) {
  1483. throw createMissingDateImplError('DateAdapter');
  1484. }
  1485. this._activeDate = this._dateAdapter.today();
  1486. }
  1487. ngAfterContentInit() {
  1488. this._rerenderSubscription = this._dateAdapter.localeChanges
  1489. .pipe(startWith(null))
  1490. .subscribe(() => this._init());
  1491. }
  1492. ngOnDestroy() {
  1493. this._rerenderSubscription.unsubscribe();
  1494. }
  1495. /** Initializes this multi-year view. */
  1496. _init() {
  1497. this._todayYear = this._dateAdapter.getYear(this._dateAdapter.today());
  1498. // We want a range years such that we maximize the number of
  1499. // enabled dates visible at once. This prevents issues where the minimum year
  1500. // is the last item of a page OR the maximum year is the first item of a page.
  1501. // The offset from the active year to the "slot" for the starting year is the
  1502. // *actual* first rendered year in the multi-year view.
  1503. const activeYear = this._dateAdapter.getYear(this._activeDate);
  1504. const minYearOfPage = activeYear - getActiveOffset(this._dateAdapter, this.activeDate, this.minDate, this.maxDate);
  1505. this._years = [];
  1506. for (let i = 0, row = []; i < yearsPerPage; i++) {
  1507. row.push(minYearOfPage + i);
  1508. if (row.length == yearsPerRow) {
  1509. this._years.push(row.map(year => this._createCellForYear(year)));
  1510. row = [];
  1511. }
  1512. }
  1513. this._changeDetectorRef.markForCheck();
  1514. }
  1515. /** Handles when a new year is selected. */
  1516. _yearSelected(event) {
  1517. const year = event.value;
  1518. const selectedYear = this._dateAdapter.createDate(year, 0, 1);
  1519. const selectedDate = this._getDateFromYear(year);
  1520. this.yearSelected.emit(selectedYear);
  1521. this.selectedChange.emit(selectedDate);
  1522. }
  1523. /**
  1524. * Takes the index of a calendar body cell wrapped in an event as argument. For the date that
  1525. * corresponds to the given cell, set `activeDate` to that date and fire `activeDateChange` with
  1526. * that date.
  1527. *
  1528. * This function is used to match each component's model of the active date with the calendar
  1529. * body cell that was focused. It updates its value of `activeDate` synchronously and updates the
  1530. * parent's value asynchronously via the `activeDateChange` event. The child component receives an
  1531. * updated value asynchronously via the `activeCell` Input.
  1532. */
  1533. _updateActiveDate(event) {
  1534. const year = event.value;
  1535. const oldActiveDate = this._activeDate;
  1536. this.activeDate = this._getDateFromYear(year);
  1537. if (this._dateAdapter.compareDate(oldActiveDate, this.activeDate)) {
  1538. this.activeDateChange.emit(this.activeDate);
  1539. }
  1540. }
  1541. /** Handles keydown events on the calendar body when calendar is in multi-year view. */
  1542. _handleCalendarBodyKeydown(event) {
  1543. const oldActiveDate = this._activeDate;
  1544. const isRtl = this._isRtl();
  1545. switch (event.keyCode) {
  1546. case LEFT_ARROW:
  1547. this.activeDate = this._dateAdapter.addCalendarYears(this._activeDate, isRtl ? 1 : -1);
  1548. break;
  1549. case RIGHT_ARROW:
  1550. this.activeDate = this._dateAdapter.addCalendarYears(this._activeDate, isRtl ? -1 : 1);
  1551. break;
  1552. case UP_ARROW:
  1553. this.activeDate = this._dateAdapter.addCalendarYears(this._activeDate, -yearsPerRow);
  1554. break;
  1555. case DOWN_ARROW:
  1556. this.activeDate = this._dateAdapter.addCalendarYears(this._activeDate, yearsPerRow);
  1557. break;
  1558. case HOME:
  1559. this.activeDate = this._dateAdapter.addCalendarYears(this._activeDate, -getActiveOffset(this._dateAdapter, this.activeDate, this.minDate, this.maxDate));
  1560. break;
  1561. case END:
  1562. this.activeDate = this._dateAdapter.addCalendarYears(this._activeDate, yearsPerPage -
  1563. getActiveOffset(this._dateAdapter, this.activeDate, this.minDate, this.maxDate) -
  1564. 1);
  1565. break;
  1566. case PAGE_UP:
  1567. this.activeDate = this._dateAdapter.addCalendarYears(this._activeDate, event.altKey ? -yearsPerPage * 10 : -yearsPerPage);
  1568. break;
  1569. case PAGE_DOWN:
  1570. this.activeDate = this._dateAdapter.addCalendarYears(this._activeDate, event.altKey ? yearsPerPage * 10 : yearsPerPage);
  1571. break;
  1572. case ENTER:
  1573. case SPACE:
  1574. // Note that we only prevent the default action here while the selection happens in
  1575. // `keyup` below. We can't do the selection here, because it can cause the calendar to
  1576. // reopen if focus is restored immediately. We also can't call `preventDefault` on `keyup`
  1577. // because it's too late (see #23305).
  1578. this._selectionKeyPressed = true;
  1579. break;
  1580. default:
  1581. // Don't prevent default or focus active cell on keys that we don't explicitly handle.
  1582. return;
  1583. }
  1584. if (this._dateAdapter.compareDate(oldActiveDate, this.activeDate)) {
  1585. this.activeDateChange.emit(this.activeDate);
  1586. }
  1587. this._focusActiveCellAfterViewChecked();
  1588. // Prevent unexpected default actions such as form submission.
  1589. event.preventDefault();
  1590. }
  1591. /** Handles keyup events on the calendar body when calendar is in multi-year view. */
  1592. _handleCalendarBodyKeyup(event) {
  1593. if (event.keyCode === SPACE || event.keyCode === ENTER) {
  1594. if (this._selectionKeyPressed) {
  1595. this._yearSelected({ value: this._dateAdapter.getYear(this._activeDate), event });
  1596. }
  1597. this._selectionKeyPressed = false;
  1598. }
  1599. }
  1600. _getActiveCell() {
  1601. return getActiveOffset(this._dateAdapter, this.activeDate, this.minDate, this.maxDate);
  1602. }
  1603. /** Focuses the active cell after the microtask queue is empty. */
  1604. _focusActiveCell() {
  1605. this._matCalendarBody._focusActiveCell();
  1606. }
  1607. /** Focuses the active cell after change detection has run and the microtask queue is empty. */
  1608. _focusActiveCellAfterViewChecked() {
  1609. this._matCalendarBody._scheduleFocusActiveCellAfterViewChecked();
  1610. }
  1611. /**
  1612. * Takes a year and returns a new date on the same day and month as the currently active date
  1613. * The returned date will have the same year as the argument date.
  1614. */
  1615. _getDateFromYear(year) {
  1616. const activeMonth = this._dateAdapter.getMonth(this.activeDate);
  1617. const daysInMonth = this._dateAdapter.getNumDaysInMonth(this._dateAdapter.createDate(year, activeMonth, 1));
  1618. const normalizedDate = this._dateAdapter.createDate(year, activeMonth, Math.min(this._dateAdapter.getDate(this.activeDate), daysInMonth));
  1619. return normalizedDate;
  1620. }
  1621. /** Creates an MatCalendarCell for the given year. */
  1622. _createCellForYear(year) {
  1623. const date = this._dateAdapter.createDate(year, 0, 1);
  1624. const yearName = this._dateAdapter.getYearName(date);
  1625. const cellClasses = this.dateClass ? this.dateClass(date, 'multi-year') : undefined;
  1626. return new MatCalendarCell(year, yearName, yearName, this._shouldEnableYear(year), cellClasses);
  1627. }
  1628. /** Whether the given year is enabled. */
  1629. _shouldEnableYear(year) {
  1630. // disable if the year is greater than maxDate lower than minDate
  1631. if (year === undefined ||
  1632. year === null ||
  1633. (this.maxDate && year > this._dateAdapter.getYear(this.maxDate)) ||
  1634. (this.minDate && year < this._dateAdapter.getYear(this.minDate))) {
  1635. return false;
  1636. }
  1637. // enable if it reaches here and there's no filter defined
  1638. if (!this.dateFilter) {
  1639. return true;
  1640. }
  1641. const firstOfYear = this._dateAdapter.createDate(year, 0, 1);
  1642. // If any date in the year is enabled count the year as enabled.
  1643. for (let date = firstOfYear; this._dateAdapter.getYear(date) == year; date = this._dateAdapter.addCalendarDays(date, 1)) {
  1644. if (this.dateFilter(date)) {
  1645. return true;
  1646. }
  1647. }
  1648. return false;
  1649. }
  1650. /** Determines whether the user has the RTL layout direction. */
  1651. _isRtl() {
  1652. return this._dir && this._dir.value === 'rtl';
  1653. }
  1654. /** Sets the currently-highlighted year based on a model value. */
  1655. _setSelectedYear(value) {
  1656. this._selectedYear = null;
  1657. if (value instanceof DateRange) {
  1658. const displayValue = value.start || value.end;
  1659. if (displayValue) {
  1660. this._selectedYear = this._dateAdapter.getYear(displayValue);
  1661. }
  1662. }
  1663. else if (value) {
  1664. this._selectedYear = this._dateAdapter.getYear(value);
  1665. }
  1666. }
  1667. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatMultiYearView, deps: [], target: i0.ɵɵFactoryTarget.Component });
  1668. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.6", type: MatMultiYearView, isStandalone: true, selector: "mat-multi-year-view", inputs: { activeDate: "activeDate", selected: "selected", minDate: "minDate", maxDate: "maxDate", dateFilter: "dateFilter", dateClass: "dateClass" }, outputs: { selectedChange: "selectedChange", yearSelected: "yearSelected", activeDateChange: "activeDateChange" }, viewQueries: [{ propertyName: "_matCalendarBody", first: true, predicate: MatCalendarBody, descendants: true }], exportAs: ["matMultiYearView"], ngImport: i0, template: "<table class=\"mat-calendar-table\" role=\"grid\">\n <thead aria-hidden=\"true\" class=\"mat-calendar-table-header\">\n <tr><th class=\"mat-calendar-table-header-divider\" colspan=\"4\"></th></tr>\n </thead>\n <tbody mat-calendar-body\n [rows]=\"_years\"\n [todayValue]=\"_todayYear\"\n [startValue]=\"_selectedYear!\"\n [endValue]=\"_selectedYear!\"\n [numCols]=\"4\"\n [cellAspectRatio]=\"4 / 7\"\n [activeCell]=\"_getActiveCell()\"\n (selectedValueChange)=\"_yearSelected($event)\"\n (activeDateChange)=\"_updateActiveDate($event)\"\n (keyup)=\"_handleCalendarBodyKeyup($event)\"\n (keydown)=\"_handleCalendarBodyKeydown($event)\">\n </tbody>\n</table>\n", dependencies: [{ kind: "component", type: MatCalendarBody, selector: "[mat-calendar-body]", inputs: ["label", "rows", "todayValue", "startValue", "endValue", "labelMinRequiredCells", "numCols", "activeCell", "isRange", "cellAspectRatio", "comparisonStart", "comparisonEnd", "previewStart", "previewEnd", "startDateAccessibleName", "endDateAccessibleName"], outputs: ["selectedValueChange", "previewChange", "activeDateChange", "dragStarted", "dragEnded"], exportAs: ["matCalendarBody"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
  1669. }
  1670. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatMultiYearView, decorators: [{
  1671. type: Component,
  1672. args: [{ selector: 'mat-multi-year-view', exportAs: 'matMultiYearView', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, imports: [MatCalendarBody], template: "<table class=\"mat-calendar-table\" role=\"grid\">\n <thead aria-hidden=\"true\" class=\"mat-calendar-table-header\">\n <tr><th class=\"mat-calendar-table-header-divider\" colspan=\"4\"></th></tr>\n </thead>\n <tbody mat-calendar-body\n [rows]=\"_years\"\n [todayValue]=\"_todayYear\"\n [startValue]=\"_selectedYear!\"\n [endValue]=\"_selectedYear!\"\n [numCols]=\"4\"\n [cellAspectRatio]=\"4 / 7\"\n [activeCell]=\"_getActiveCell()\"\n (selectedValueChange)=\"_yearSelected($event)\"\n (activeDateChange)=\"_updateActiveDate($event)\"\n (keyup)=\"_handleCalendarBodyKeyup($event)\"\n (keydown)=\"_handleCalendarBodyKeydown($event)\">\n </tbody>\n</table>\n" }]
  1673. }], ctorParameters: () => [], propDecorators: { activeDate: [{
  1674. type: Input
  1675. }], selected: [{
  1676. type: Input
  1677. }], minDate: [{
  1678. type: Input
  1679. }], maxDate: [{
  1680. type: Input
  1681. }], dateFilter: [{
  1682. type: Input
  1683. }], dateClass: [{
  1684. type: Input
  1685. }], selectedChange: [{
  1686. type: Output
  1687. }], yearSelected: [{
  1688. type: Output
  1689. }], activeDateChange: [{
  1690. type: Output
  1691. }], _matCalendarBody: [{
  1692. type: ViewChild,
  1693. args: [MatCalendarBody]
  1694. }] } });
  1695. function isSameMultiYearView(dateAdapter, date1, date2, minDate, maxDate) {
  1696. const year1 = dateAdapter.getYear(date1);
  1697. const year2 = dateAdapter.getYear(date2);
  1698. const startingYear = getStartingYear(dateAdapter, minDate, maxDate);
  1699. return (Math.floor((year1 - startingYear) / yearsPerPage) ===
  1700. Math.floor((year2 - startingYear) / yearsPerPage));
  1701. }
  1702. /**
  1703. * When the multi-year view is first opened, the active year will be in view.
  1704. * So we compute how many years are between the active year and the *slot* where our
  1705. * "startingYear" will render when paged into view.
  1706. */
  1707. function getActiveOffset(dateAdapter, activeDate, minDate, maxDate) {
  1708. const activeYear = dateAdapter.getYear(activeDate);
  1709. return euclideanModulo(activeYear - getStartingYear(dateAdapter, minDate, maxDate), yearsPerPage);
  1710. }
  1711. /**
  1712. * We pick a "starting" year such that either the maximum year would be at the end
  1713. * or the minimum year would be at the beginning of a page.
  1714. */
  1715. function getStartingYear(dateAdapter, minDate, maxDate) {
  1716. let startingYear = 0;
  1717. if (maxDate) {
  1718. const maxYear = dateAdapter.getYear(maxDate);
  1719. startingYear = maxYear - yearsPerPage + 1;
  1720. }
  1721. else if (minDate) {
  1722. startingYear = dateAdapter.getYear(minDate);
  1723. }
  1724. return startingYear;
  1725. }
  1726. /** Gets remainder that is non-negative, even if first number is negative */
  1727. function euclideanModulo(a, b) {
  1728. return ((a % b) + b) % b;
  1729. }
  1730. /**
  1731. * An internal component used to display a single year in the datepicker.
  1732. * @docs-private
  1733. */
  1734. class MatYearView {
  1735. _changeDetectorRef = inject(ChangeDetectorRef);
  1736. _dateFormats = inject(MAT_DATE_FORMATS, { optional: true });
  1737. _dateAdapter = inject(DateAdapter, { optional: true });
  1738. _dir = inject(Directionality, { optional: true });
  1739. _rerenderSubscription = Subscription.EMPTY;
  1740. /** Flag used to filter out space/enter keyup events that originated outside of the view. */
  1741. _selectionKeyPressed;
  1742. /** The date to display in this year view (everything other than the year is ignored). */
  1743. get activeDate() {
  1744. return this._activeDate;
  1745. }
  1746. set activeDate(value) {
  1747. let oldActiveDate = this._activeDate;
  1748. const validDate = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value)) ||
  1749. this._dateAdapter.today();
  1750. this._activeDate = this._dateAdapter.clampDate(validDate, this.minDate, this.maxDate);
  1751. if (this._dateAdapter.getYear(oldActiveDate) !== this._dateAdapter.getYear(this._activeDate)) {
  1752. this._init();
  1753. }
  1754. }
  1755. _activeDate;
  1756. /** The currently selected date. */
  1757. get selected() {
  1758. return this._selected;
  1759. }
  1760. set selected(value) {
  1761. if (value instanceof DateRange) {
  1762. this._selected = value;
  1763. }
  1764. else {
  1765. this._selected = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value));
  1766. }
  1767. this._setSelectedMonth(value);
  1768. }
  1769. _selected;
  1770. /** The minimum selectable date. */
  1771. get minDate() {
  1772. return this._minDate;
  1773. }
  1774. set minDate(value) {
  1775. this._minDate = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value));
  1776. }
  1777. _minDate;
  1778. /** The maximum selectable date. */
  1779. get maxDate() {
  1780. return this._maxDate;
  1781. }
  1782. set maxDate(value) {
  1783. this._maxDate = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value));
  1784. }
  1785. _maxDate;
  1786. /** A function used to filter which dates are selectable. */
  1787. dateFilter;
  1788. /** Function that can be used to add custom CSS classes to date cells. */
  1789. dateClass;
  1790. /** Emits when a new month is selected. */
  1791. selectedChange = new EventEmitter();
  1792. /** Emits the selected month. This doesn't imply a change on the selected date */
  1793. monthSelected = new EventEmitter();
  1794. /** Emits when any date is activated. */
  1795. activeDateChange = new EventEmitter();
  1796. /** The body of calendar table */
  1797. _matCalendarBody;
  1798. /** Grid of calendar cells representing the months of the year. */
  1799. _months;
  1800. /** The label for this year (e.g. "2017"). */
  1801. _yearLabel;
  1802. /** The month in this year that today falls on. Null if today is in a different year. */
  1803. _todayMonth;
  1804. /**
  1805. * The month in this year that the selected Date falls on.
  1806. * Null if the selected Date is in a different year.
  1807. */
  1808. _selectedMonth;
  1809. constructor() {
  1810. if (typeof ngDevMode === 'undefined' || ngDevMode) {
  1811. if (!this._dateAdapter) {
  1812. throw createMissingDateImplError('DateAdapter');
  1813. }
  1814. if (!this._dateFormats) {
  1815. throw createMissingDateImplError('MAT_DATE_FORMATS');
  1816. }
  1817. }
  1818. this._activeDate = this._dateAdapter.today();
  1819. }
  1820. ngAfterContentInit() {
  1821. this._rerenderSubscription = this._dateAdapter.localeChanges
  1822. .pipe(startWith(null))
  1823. .subscribe(() => this._init());
  1824. }
  1825. ngOnDestroy() {
  1826. this._rerenderSubscription.unsubscribe();
  1827. }
  1828. /** Handles when a new month is selected. */
  1829. _monthSelected(event) {
  1830. const month = event.value;
  1831. const selectedMonth = this._dateAdapter.createDate(this._dateAdapter.getYear(this.activeDate), month, 1);
  1832. this.monthSelected.emit(selectedMonth);
  1833. const selectedDate = this._getDateFromMonth(month);
  1834. this.selectedChange.emit(selectedDate);
  1835. }
  1836. /**
  1837. * Takes the index of a calendar body cell wrapped in an event as argument. For the date that
  1838. * corresponds to the given cell, set `activeDate` to that date and fire `activeDateChange` with
  1839. * that date.
  1840. *
  1841. * This function is used to match each component's model of the active date with the calendar
  1842. * body cell that was focused. It updates its value of `activeDate` synchronously and updates the
  1843. * parent's value asynchronously via the `activeDateChange` event. The child component receives an
  1844. * updated value asynchronously via the `activeCell` Input.
  1845. */
  1846. _updateActiveDate(event) {
  1847. const month = event.value;
  1848. const oldActiveDate = this._activeDate;
  1849. this.activeDate = this._getDateFromMonth(month);
  1850. if (this._dateAdapter.compareDate(oldActiveDate, this.activeDate)) {
  1851. this.activeDateChange.emit(this.activeDate);
  1852. }
  1853. }
  1854. /** Handles keydown events on the calendar body when calendar is in year view. */
  1855. _handleCalendarBodyKeydown(event) {
  1856. // TODO(mmalerba): We currently allow keyboard navigation to disabled dates, but just prevent
  1857. // disabled ones from being selected. This may not be ideal, we should look into whether
  1858. // navigation should skip over disabled dates, and if so, how to implement that efficiently.
  1859. const oldActiveDate = this._activeDate;
  1860. const isRtl = this._isRtl();
  1861. switch (event.keyCode) {
  1862. case LEFT_ARROW:
  1863. this.activeDate = this._dateAdapter.addCalendarMonths(this._activeDate, isRtl ? 1 : -1);
  1864. break;
  1865. case RIGHT_ARROW:
  1866. this.activeDate = this._dateAdapter.addCalendarMonths(this._activeDate, isRtl ? -1 : 1);
  1867. break;
  1868. case UP_ARROW:
  1869. this.activeDate = this._dateAdapter.addCalendarMonths(this._activeDate, -4);
  1870. break;
  1871. case DOWN_ARROW:
  1872. this.activeDate = this._dateAdapter.addCalendarMonths(this._activeDate, 4);
  1873. break;
  1874. case HOME:
  1875. this.activeDate = this._dateAdapter.addCalendarMonths(this._activeDate, -this._dateAdapter.getMonth(this._activeDate));
  1876. break;
  1877. case END:
  1878. this.activeDate = this._dateAdapter.addCalendarMonths(this._activeDate, 11 - this._dateAdapter.getMonth(this._activeDate));
  1879. break;
  1880. case PAGE_UP:
  1881. this.activeDate = this._dateAdapter.addCalendarYears(this._activeDate, event.altKey ? -10 : -1);
  1882. break;
  1883. case PAGE_DOWN:
  1884. this.activeDate = this._dateAdapter.addCalendarYears(this._activeDate, event.altKey ? 10 : 1);
  1885. break;
  1886. case ENTER:
  1887. case SPACE:
  1888. // Note that we only prevent the default action here while the selection happens in
  1889. // `keyup` below. We can't do the selection here, because it can cause the calendar to
  1890. // reopen if focus is restored immediately. We also can't call `preventDefault` on `keyup`
  1891. // because it's too late (see #23305).
  1892. this._selectionKeyPressed = true;
  1893. break;
  1894. default:
  1895. // Don't prevent default or focus active cell on keys that we don't explicitly handle.
  1896. return;
  1897. }
  1898. if (this._dateAdapter.compareDate(oldActiveDate, this.activeDate)) {
  1899. this.activeDateChange.emit(this.activeDate);
  1900. this._focusActiveCellAfterViewChecked();
  1901. }
  1902. // Prevent unexpected default actions such as form submission.
  1903. event.preventDefault();
  1904. }
  1905. /** Handles keyup events on the calendar body when calendar is in year view. */
  1906. _handleCalendarBodyKeyup(event) {
  1907. if (event.keyCode === SPACE || event.keyCode === ENTER) {
  1908. if (this._selectionKeyPressed) {
  1909. this._monthSelected({ value: this._dateAdapter.getMonth(this._activeDate), event });
  1910. }
  1911. this._selectionKeyPressed = false;
  1912. }
  1913. }
  1914. /** Initializes this year view. */
  1915. _init() {
  1916. this._setSelectedMonth(this.selected);
  1917. this._todayMonth = this._getMonthInCurrentYear(this._dateAdapter.today());
  1918. this._yearLabel = this._dateAdapter.getYearName(this.activeDate);
  1919. let monthNames = this._dateAdapter.getMonthNames('short');
  1920. // First row of months only contains 5 elements so we can fit the year label on the same row.
  1921. this._months = [
  1922. [0, 1, 2, 3],
  1923. [4, 5, 6, 7],
  1924. [8, 9, 10, 11],
  1925. ].map(row => row.map(month => this._createCellForMonth(month, monthNames[month])));
  1926. this._changeDetectorRef.markForCheck();
  1927. }
  1928. /** Focuses the active cell after the microtask queue is empty. */
  1929. _focusActiveCell() {
  1930. this._matCalendarBody._focusActiveCell();
  1931. }
  1932. /** Schedules the matCalendarBody to focus the active cell after change detection has run */
  1933. _focusActiveCellAfterViewChecked() {
  1934. this._matCalendarBody._scheduleFocusActiveCellAfterViewChecked();
  1935. }
  1936. /**
  1937. * Gets the month in this year that the given Date falls on.
  1938. * Returns null if the given Date is in another year.
  1939. */
  1940. _getMonthInCurrentYear(date) {
  1941. return date && this._dateAdapter.getYear(date) == this._dateAdapter.getYear(this.activeDate)
  1942. ? this._dateAdapter.getMonth(date)
  1943. : null;
  1944. }
  1945. /**
  1946. * Takes a month and returns a new date in the same day and year as the currently active date.
  1947. * The returned date will have the same month as the argument date.
  1948. */
  1949. _getDateFromMonth(month) {
  1950. const normalizedDate = this._dateAdapter.createDate(this._dateAdapter.getYear(this.activeDate), month, 1);
  1951. const daysInMonth = this._dateAdapter.getNumDaysInMonth(normalizedDate);
  1952. return this._dateAdapter.createDate(this._dateAdapter.getYear(this.activeDate), month, Math.min(this._dateAdapter.getDate(this.activeDate), daysInMonth));
  1953. }
  1954. /** Creates an MatCalendarCell for the given month. */
  1955. _createCellForMonth(month, monthName) {
  1956. const date = this._dateAdapter.createDate(this._dateAdapter.getYear(this.activeDate), month, 1);
  1957. const ariaLabel = this._dateAdapter.format(date, this._dateFormats.display.monthYearA11yLabel);
  1958. const cellClasses = this.dateClass ? this.dateClass(date, 'year') : undefined;
  1959. return new MatCalendarCell(month, monthName.toLocaleUpperCase(), ariaLabel, this._shouldEnableMonth(month), cellClasses);
  1960. }
  1961. /** Whether the given month is enabled. */
  1962. _shouldEnableMonth(month) {
  1963. const activeYear = this._dateAdapter.getYear(this.activeDate);
  1964. if (month === undefined ||
  1965. month === null ||
  1966. this._isYearAndMonthAfterMaxDate(activeYear, month) ||
  1967. this._isYearAndMonthBeforeMinDate(activeYear, month)) {
  1968. return false;
  1969. }
  1970. if (!this.dateFilter) {
  1971. return true;
  1972. }
  1973. const firstOfMonth = this._dateAdapter.createDate(activeYear, month, 1);
  1974. // If any date in the month is enabled count the month as enabled.
  1975. for (let date = firstOfMonth; this._dateAdapter.getMonth(date) == month; date = this._dateAdapter.addCalendarDays(date, 1)) {
  1976. if (this.dateFilter(date)) {
  1977. return true;
  1978. }
  1979. }
  1980. return false;
  1981. }
  1982. /**
  1983. * Tests whether the combination month/year is after this.maxDate, considering
  1984. * just the month and year of this.maxDate
  1985. */
  1986. _isYearAndMonthAfterMaxDate(year, month) {
  1987. if (this.maxDate) {
  1988. const maxYear = this._dateAdapter.getYear(this.maxDate);
  1989. const maxMonth = this._dateAdapter.getMonth(this.maxDate);
  1990. return year > maxYear || (year === maxYear && month > maxMonth);
  1991. }
  1992. return false;
  1993. }
  1994. /**
  1995. * Tests whether the combination month/year is before this.minDate, considering
  1996. * just the month and year of this.minDate
  1997. */
  1998. _isYearAndMonthBeforeMinDate(year, month) {
  1999. if (this.minDate) {
  2000. const minYear = this._dateAdapter.getYear(this.minDate);
  2001. const minMonth = this._dateAdapter.getMonth(this.minDate);
  2002. return year < minYear || (year === minYear && month < minMonth);
  2003. }
  2004. return false;
  2005. }
  2006. /** Determines whether the user has the RTL layout direction. */
  2007. _isRtl() {
  2008. return this._dir && this._dir.value === 'rtl';
  2009. }
  2010. /** Sets the currently-selected month based on a model value. */
  2011. _setSelectedMonth(value) {
  2012. if (value instanceof DateRange) {
  2013. this._selectedMonth =
  2014. this._getMonthInCurrentYear(value.start) || this._getMonthInCurrentYear(value.end);
  2015. }
  2016. else {
  2017. this._selectedMonth = this._getMonthInCurrentYear(value);
  2018. }
  2019. }
  2020. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatYearView, deps: [], target: i0.ɵɵFactoryTarget.Component });
  2021. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.6", type: MatYearView, isStandalone: true, selector: "mat-year-view", inputs: { activeDate: "activeDate", selected: "selected", minDate: "minDate", maxDate: "maxDate", dateFilter: "dateFilter", dateClass: "dateClass" }, outputs: { selectedChange: "selectedChange", monthSelected: "monthSelected", activeDateChange: "activeDateChange" }, viewQueries: [{ propertyName: "_matCalendarBody", first: true, predicate: MatCalendarBody, descendants: true }], exportAs: ["matYearView"], ngImport: i0, template: "<table class=\"mat-calendar-table\" role=\"grid\">\n <thead aria-hidden=\"true\" class=\"mat-calendar-table-header\">\n <tr><th class=\"mat-calendar-table-header-divider\" colspan=\"4\"></th></tr>\n </thead>\n <tbody mat-calendar-body\n [label]=\"_yearLabel\"\n [rows]=\"_months\"\n [todayValue]=\"_todayMonth!\"\n [startValue]=\"_selectedMonth!\"\n [endValue]=\"_selectedMonth!\"\n [labelMinRequiredCells]=\"2\"\n [numCols]=\"4\"\n [cellAspectRatio]=\"4 / 7\"\n [activeCell]=\"_dateAdapter.getMonth(activeDate)\"\n (selectedValueChange)=\"_monthSelected($event)\"\n (activeDateChange)=\"_updateActiveDate($event)\"\n (keyup)=\"_handleCalendarBodyKeyup($event)\"\n (keydown)=\"_handleCalendarBodyKeydown($event)\">\n </tbody>\n</table>\n", dependencies: [{ kind: "component", type: MatCalendarBody, selector: "[mat-calendar-body]", inputs: ["label", "rows", "todayValue", "startValue", "endValue", "labelMinRequiredCells", "numCols", "activeCell", "isRange", "cellAspectRatio", "comparisonStart", "comparisonEnd", "previewStart", "previewEnd", "startDateAccessibleName", "endDateAccessibleName"], outputs: ["selectedValueChange", "previewChange", "activeDateChange", "dragStarted", "dragEnded"], exportAs: ["matCalendarBody"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
  2022. }
  2023. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatYearView, decorators: [{
  2024. type: Component,
  2025. args: [{ selector: 'mat-year-view', exportAs: 'matYearView', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, imports: [MatCalendarBody], template: "<table class=\"mat-calendar-table\" role=\"grid\">\n <thead aria-hidden=\"true\" class=\"mat-calendar-table-header\">\n <tr><th class=\"mat-calendar-table-header-divider\" colspan=\"4\"></th></tr>\n </thead>\n <tbody mat-calendar-body\n [label]=\"_yearLabel\"\n [rows]=\"_months\"\n [todayValue]=\"_todayMonth!\"\n [startValue]=\"_selectedMonth!\"\n [endValue]=\"_selectedMonth!\"\n [labelMinRequiredCells]=\"2\"\n [numCols]=\"4\"\n [cellAspectRatio]=\"4 / 7\"\n [activeCell]=\"_dateAdapter.getMonth(activeDate)\"\n (selectedValueChange)=\"_monthSelected($event)\"\n (activeDateChange)=\"_updateActiveDate($event)\"\n (keyup)=\"_handleCalendarBodyKeyup($event)\"\n (keydown)=\"_handleCalendarBodyKeydown($event)\">\n </tbody>\n</table>\n" }]
  2026. }], ctorParameters: () => [], propDecorators: { activeDate: [{
  2027. type: Input
  2028. }], selected: [{
  2029. type: Input
  2030. }], minDate: [{
  2031. type: Input
  2032. }], maxDate: [{
  2033. type: Input
  2034. }], dateFilter: [{
  2035. type: Input
  2036. }], dateClass: [{
  2037. type: Input
  2038. }], selectedChange: [{
  2039. type: Output
  2040. }], monthSelected: [{
  2041. type: Output
  2042. }], activeDateChange: [{
  2043. type: Output
  2044. }], _matCalendarBody: [{
  2045. type: ViewChild,
  2046. args: [MatCalendarBody]
  2047. }] } });
  2048. /** Default header for MatCalendar */
  2049. class MatCalendarHeader {
  2050. _intl = inject(MatDatepickerIntl);
  2051. calendar = inject(MatCalendar);
  2052. _dateAdapter = inject(DateAdapter, { optional: true });
  2053. _dateFormats = inject(MAT_DATE_FORMATS, { optional: true });
  2054. constructor() {
  2055. inject(_CdkPrivateStyleLoader).load(_VisuallyHiddenLoader);
  2056. const changeDetectorRef = inject(ChangeDetectorRef);
  2057. this.calendar.stateChanges.subscribe(() => changeDetectorRef.markForCheck());
  2058. }
  2059. /** The display text for the current calendar view. */
  2060. get periodButtonText() {
  2061. if (this.calendar.currentView == 'month') {
  2062. return this._dateAdapter
  2063. .format(this.calendar.activeDate, this._dateFormats.display.monthYearLabel)
  2064. .toLocaleUpperCase();
  2065. }
  2066. if (this.calendar.currentView == 'year') {
  2067. return this._dateAdapter.getYearName(this.calendar.activeDate);
  2068. }
  2069. return this._intl.formatYearRange(...this._formatMinAndMaxYearLabels());
  2070. }
  2071. /** The aria description for the current calendar view. */
  2072. get periodButtonDescription() {
  2073. if (this.calendar.currentView == 'month') {
  2074. return this._dateAdapter
  2075. .format(this.calendar.activeDate, this._dateFormats.display.monthYearLabel)
  2076. .toLocaleUpperCase();
  2077. }
  2078. if (this.calendar.currentView == 'year') {
  2079. return this._dateAdapter.getYearName(this.calendar.activeDate);
  2080. }
  2081. // Format a label for the window of years displayed in the multi-year calendar view. Use
  2082. // `formatYearRangeLabel` because it is TTS friendly.
  2083. return this._intl.formatYearRangeLabel(...this._formatMinAndMaxYearLabels());
  2084. }
  2085. /** The `aria-label` for changing the calendar view. */
  2086. get periodButtonLabel() {
  2087. return this.calendar.currentView == 'month'
  2088. ? this._intl.switchToMultiYearViewLabel
  2089. : this._intl.switchToMonthViewLabel;
  2090. }
  2091. /** The label for the previous button. */
  2092. get prevButtonLabel() {
  2093. return {
  2094. 'month': this._intl.prevMonthLabel,
  2095. 'year': this._intl.prevYearLabel,
  2096. 'multi-year': this._intl.prevMultiYearLabel,
  2097. }[this.calendar.currentView];
  2098. }
  2099. /** The label for the next button. */
  2100. get nextButtonLabel() {
  2101. return {
  2102. 'month': this._intl.nextMonthLabel,
  2103. 'year': this._intl.nextYearLabel,
  2104. 'multi-year': this._intl.nextMultiYearLabel,
  2105. }[this.calendar.currentView];
  2106. }
  2107. /** Handles user clicks on the period label. */
  2108. currentPeriodClicked() {
  2109. this.calendar.currentView = this.calendar.currentView == 'month' ? 'multi-year' : 'month';
  2110. }
  2111. /** Handles user clicks on the previous button. */
  2112. previousClicked() {
  2113. this.calendar.activeDate =
  2114. this.calendar.currentView == 'month'
  2115. ? this._dateAdapter.addCalendarMonths(this.calendar.activeDate, -1)
  2116. : this._dateAdapter.addCalendarYears(this.calendar.activeDate, this.calendar.currentView == 'year' ? -1 : -yearsPerPage);
  2117. }
  2118. /** Handles user clicks on the next button. */
  2119. nextClicked() {
  2120. this.calendar.activeDate =
  2121. this.calendar.currentView == 'month'
  2122. ? this._dateAdapter.addCalendarMonths(this.calendar.activeDate, 1)
  2123. : this._dateAdapter.addCalendarYears(this.calendar.activeDate, this.calendar.currentView == 'year' ? 1 : yearsPerPage);
  2124. }
  2125. /** Whether the previous period button is enabled. */
  2126. previousEnabled() {
  2127. if (!this.calendar.minDate) {
  2128. return true;
  2129. }
  2130. return (!this.calendar.minDate || !this._isSameView(this.calendar.activeDate, this.calendar.minDate));
  2131. }
  2132. /** Whether the next period button is enabled. */
  2133. nextEnabled() {
  2134. return (!this.calendar.maxDate || !this._isSameView(this.calendar.activeDate, this.calendar.maxDate));
  2135. }
  2136. /** Whether the two dates represent the same view in the current view mode (month or year). */
  2137. _isSameView(date1, date2) {
  2138. if (this.calendar.currentView == 'month') {
  2139. return (this._dateAdapter.getYear(date1) == this._dateAdapter.getYear(date2) &&
  2140. this._dateAdapter.getMonth(date1) == this._dateAdapter.getMonth(date2));
  2141. }
  2142. if (this.calendar.currentView == 'year') {
  2143. return this._dateAdapter.getYear(date1) == this._dateAdapter.getYear(date2);
  2144. }
  2145. // Otherwise we are in 'multi-year' view.
  2146. return isSameMultiYearView(this._dateAdapter, date1, date2, this.calendar.minDate, this.calendar.maxDate);
  2147. }
  2148. /**
  2149. * Format two individual labels for the minimum year and maximum year available in the multi-year
  2150. * calendar view. Returns an array of two strings where the first string is the formatted label
  2151. * for the minimum year, and the second string is the formatted label for the maximum year.
  2152. */
  2153. _formatMinAndMaxYearLabels() {
  2154. // The offset from the active year to the "slot" for the starting year is the
  2155. // *actual* first rendered year in the multi-year view, and the last year is
  2156. // just yearsPerPage - 1 away.
  2157. const activeYear = this._dateAdapter.getYear(this.calendar.activeDate);
  2158. const minYearOfPage = activeYear -
  2159. getActiveOffset(this._dateAdapter, this.calendar.activeDate, this.calendar.minDate, this.calendar.maxDate);
  2160. const maxYearOfPage = minYearOfPage + yearsPerPage - 1;
  2161. const minYearLabel = this._dateAdapter.getYearName(this._dateAdapter.createDate(minYearOfPage, 0, 1));
  2162. const maxYearLabel = this._dateAdapter.getYearName(this._dateAdapter.createDate(maxYearOfPage, 0, 1));
  2163. return [minYearLabel, maxYearLabel];
  2164. }
  2165. _periodButtonLabelId = inject(_IdGenerator).getId('mat-calendar-period-label-');
  2166. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatCalendarHeader, deps: [], target: i0.ɵɵFactoryTarget.Component });
  2167. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.6", type: MatCalendarHeader, isStandalone: true, selector: "mat-calendar-header", exportAs: ["matCalendarHeader"], ngImport: i0, template: "<div class=\"mat-calendar-header\">\n <div class=\"mat-calendar-controls\">\n <!-- [Firefox Issue: https://bugzilla.mozilla.org/show_bug.cgi?id=1880533]\n Relocated label next to related button and made visually hidden via cdk-visually-hidden\n to enable label to appear in a11y tree for SR when using Firefox -->\n <span [id]=\"_periodButtonLabelId\" class=\"cdk-visually-hidden\" aria-live=\"polite\">{{periodButtonDescription}}</span>\n <button mat-button type=\"button\" class=\"mat-calendar-period-button\"\n (click)=\"currentPeriodClicked()\" [attr.aria-label]=\"periodButtonLabel\"\n [attr.aria-describedby]=\"_periodButtonLabelId\">\n <span aria-hidden=\"true\">{{periodButtonText}}</span>\n <svg class=\"mat-calendar-arrow\" [class.mat-calendar-invert]=\"calendar.currentView !== 'month'\"\n viewBox=\"0 0 10 5\" focusable=\"false\" aria-hidden=\"true\">\n <polygon points=\"0,0 5,5 10,0\"/>\n </svg>\n </button>\n\n <div class=\"mat-calendar-spacer\"></div>\n\n <ng-content></ng-content>\n\n <button mat-icon-button type=\"button\" class=\"mat-calendar-previous-button\"\n [disabled]=\"!previousEnabled()\" (click)=\"previousClicked()\"\n [attr.aria-label]=\"prevButtonLabel\">\n <svg viewBox=\"0 0 24 24\" focusable=\"false\" aria-hidden=\"true\">\n <path d=\"M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z\"/>\n </svg>\n </button>\n\n <button mat-icon-button type=\"button\" class=\"mat-calendar-next-button\"\n [disabled]=\"!nextEnabled()\" (click)=\"nextClicked()\"\n [attr.aria-label]=\"nextButtonLabel\">\n <svg viewBox=\"0 0 24 24\" focusable=\"false\" aria-hidden=\"true\">\n <path d=\"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z\"/>\n </svg>\n </button>\n </div>\n</div>\n", dependencies: [{ kind: "component", type: MatButton, selector: " button[mat-button], button[mat-raised-button], button[mat-flat-button], button[mat-stroked-button] ", exportAs: ["matButton"] }, { kind: "component", type: MatIconButton, selector: "button[mat-icon-button]", exportAs: ["matButton"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
  2168. }
  2169. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatCalendarHeader, decorators: [{
  2170. type: Component,
  2171. args: [{ selector: 'mat-calendar-header', exportAs: 'matCalendarHeader', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, imports: [MatButton, MatIconButton], template: "<div class=\"mat-calendar-header\">\n <div class=\"mat-calendar-controls\">\n <!-- [Firefox Issue: https://bugzilla.mozilla.org/show_bug.cgi?id=1880533]\n Relocated label next to related button and made visually hidden via cdk-visually-hidden\n to enable label to appear in a11y tree for SR when using Firefox -->\n <span [id]=\"_periodButtonLabelId\" class=\"cdk-visually-hidden\" aria-live=\"polite\">{{periodButtonDescription}}</span>\n <button mat-button type=\"button\" class=\"mat-calendar-period-button\"\n (click)=\"currentPeriodClicked()\" [attr.aria-label]=\"periodButtonLabel\"\n [attr.aria-describedby]=\"_periodButtonLabelId\">\n <span aria-hidden=\"true\">{{periodButtonText}}</span>\n <svg class=\"mat-calendar-arrow\" [class.mat-calendar-invert]=\"calendar.currentView !== 'month'\"\n viewBox=\"0 0 10 5\" focusable=\"false\" aria-hidden=\"true\">\n <polygon points=\"0,0 5,5 10,0\"/>\n </svg>\n </button>\n\n <div class=\"mat-calendar-spacer\"></div>\n\n <ng-content></ng-content>\n\n <button mat-icon-button type=\"button\" class=\"mat-calendar-previous-button\"\n [disabled]=\"!previousEnabled()\" (click)=\"previousClicked()\"\n [attr.aria-label]=\"prevButtonLabel\">\n <svg viewBox=\"0 0 24 24\" focusable=\"false\" aria-hidden=\"true\">\n <path d=\"M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z\"/>\n </svg>\n </button>\n\n <button mat-icon-button type=\"button\" class=\"mat-calendar-next-button\"\n [disabled]=\"!nextEnabled()\" (click)=\"nextClicked()\"\n [attr.aria-label]=\"nextButtonLabel\">\n <svg viewBox=\"0 0 24 24\" focusable=\"false\" aria-hidden=\"true\">\n <path d=\"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z\"/>\n </svg>\n </button>\n </div>\n</div>\n" }]
  2172. }], ctorParameters: () => [] });
  2173. /** A calendar that is used as part of the datepicker. */
  2174. class MatCalendar {
  2175. _dateAdapter = inject(DateAdapter, { optional: true });
  2176. _dateFormats = inject(MAT_DATE_FORMATS, { optional: true });
  2177. _changeDetectorRef = inject(ChangeDetectorRef);
  2178. _elementRef = inject(ElementRef);
  2179. /** An input indicating the type of the header component, if set. */
  2180. headerComponent;
  2181. /** A portal containing the header component type for this calendar. */
  2182. _calendarHeaderPortal;
  2183. _intlChanges;
  2184. /**
  2185. * Used for scheduling that focus should be moved to the active cell on the next tick.
  2186. * We need to schedule it, rather than do it immediately, because we have to wait
  2187. * for Angular to re-evaluate the view children.
  2188. */
  2189. _moveFocusOnNextTick = false;
  2190. /** A date representing the period (month or year) to start the calendar in. */
  2191. get startAt() {
  2192. return this._startAt;
  2193. }
  2194. set startAt(value) {
  2195. this._startAt = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value));
  2196. }
  2197. _startAt;
  2198. /** Whether the calendar should be started in month or year view. */
  2199. startView = 'month';
  2200. /** The currently selected date. */
  2201. get selected() {
  2202. return this._selected;
  2203. }
  2204. set selected(value) {
  2205. if (value instanceof DateRange) {
  2206. this._selected = value;
  2207. }
  2208. else {
  2209. this._selected = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value));
  2210. }
  2211. }
  2212. _selected;
  2213. /** The minimum selectable date. */
  2214. get minDate() {
  2215. return this._minDate;
  2216. }
  2217. set minDate(value) {
  2218. this._minDate = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value));
  2219. }
  2220. _minDate;
  2221. /** The maximum selectable date. */
  2222. get maxDate() {
  2223. return this._maxDate;
  2224. }
  2225. set maxDate(value) {
  2226. this._maxDate = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value));
  2227. }
  2228. _maxDate;
  2229. /** Function used to filter which dates are selectable. */
  2230. dateFilter;
  2231. /** Function that can be used to add custom CSS classes to dates. */
  2232. dateClass;
  2233. /** Start of the comparison range. */
  2234. comparisonStart;
  2235. /** End of the comparison range. */
  2236. comparisonEnd;
  2237. /** ARIA Accessible name of the `<input matStartDate/>` */
  2238. startDateAccessibleName;
  2239. /** ARIA Accessible name of the `<input matEndDate/>` */
  2240. endDateAccessibleName;
  2241. /** Emits when the currently selected date changes. */
  2242. selectedChange = new EventEmitter();
  2243. /**
  2244. * Emits the year chosen in multiyear view.
  2245. * This doesn't imply a change on the selected date.
  2246. */
  2247. yearSelected = new EventEmitter();
  2248. /**
  2249. * Emits the month chosen in year view.
  2250. * This doesn't imply a change on the selected date.
  2251. */
  2252. monthSelected = new EventEmitter();
  2253. /**
  2254. * Emits when the current view changes.
  2255. */
  2256. viewChanged = new EventEmitter(true);
  2257. /** Emits when any date is selected. */
  2258. _userSelection = new EventEmitter();
  2259. /** Emits a new date range value when the user completes a drag drop operation. */
  2260. _userDragDrop = new EventEmitter();
  2261. /** Reference to the current month view component. */
  2262. monthView;
  2263. /** Reference to the current year view component. */
  2264. yearView;
  2265. /** Reference to the current multi-year view component. */
  2266. multiYearView;
  2267. /**
  2268. * The current active date. This determines which time period is shown and which date is
  2269. * highlighted when using keyboard navigation.
  2270. */
  2271. get activeDate() {
  2272. return this._clampedActiveDate;
  2273. }
  2274. set activeDate(value) {
  2275. this._clampedActiveDate = this._dateAdapter.clampDate(value, this.minDate, this.maxDate);
  2276. this.stateChanges.next();
  2277. this._changeDetectorRef.markForCheck();
  2278. }
  2279. _clampedActiveDate;
  2280. /** Whether the calendar is in month view. */
  2281. get currentView() {
  2282. return this._currentView;
  2283. }
  2284. set currentView(value) {
  2285. const viewChangedResult = this._currentView !== value ? value : null;
  2286. this._currentView = value;
  2287. this._moveFocusOnNextTick = true;
  2288. this._changeDetectorRef.markForCheck();
  2289. if (viewChangedResult) {
  2290. this.viewChanged.emit(viewChangedResult);
  2291. }
  2292. }
  2293. _currentView;
  2294. /** Origin of active drag, or null when dragging is not active. */
  2295. _activeDrag = null;
  2296. /**
  2297. * Emits whenever there is a state change that the header may need to respond to.
  2298. */
  2299. stateChanges = new Subject();
  2300. constructor() {
  2301. if (typeof ngDevMode === 'undefined' || ngDevMode) {
  2302. if (!this._dateAdapter) {
  2303. throw createMissingDateImplError('DateAdapter');
  2304. }
  2305. if (!this._dateFormats) {
  2306. throw createMissingDateImplError('MAT_DATE_FORMATS');
  2307. }
  2308. }
  2309. this._intlChanges = inject(MatDatepickerIntl).changes.subscribe(() => {
  2310. this._changeDetectorRef.markForCheck();
  2311. this.stateChanges.next();
  2312. });
  2313. }
  2314. ngAfterContentInit() {
  2315. this._calendarHeaderPortal = new ComponentPortal(this.headerComponent || MatCalendarHeader);
  2316. this.activeDate = this.startAt || this._dateAdapter.today();
  2317. // Assign to the private property since we don't want to move focus on init.
  2318. this._currentView = this.startView;
  2319. }
  2320. ngAfterViewChecked() {
  2321. if (this._moveFocusOnNextTick) {
  2322. this._moveFocusOnNextTick = false;
  2323. this.focusActiveCell();
  2324. }
  2325. }
  2326. ngOnDestroy() {
  2327. this._intlChanges.unsubscribe();
  2328. this.stateChanges.complete();
  2329. }
  2330. ngOnChanges(changes) {
  2331. // Ignore date changes that are at a different time on the same day. This fixes issues where
  2332. // the calendar re-renders when there is no meaningful change to [minDate] or [maxDate]
  2333. // (#24435).
  2334. const minDateChange = changes['minDate'] &&
  2335. !this._dateAdapter.sameDate(changes['minDate'].previousValue, changes['minDate'].currentValue)
  2336. ? changes['minDate']
  2337. : undefined;
  2338. const maxDateChange = changes['maxDate'] &&
  2339. !this._dateAdapter.sameDate(changes['maxDate'].previousValue, changes['maxDate'].currentValue)
  2340. ? changes['maxDate']
  2341. : undefined;
  2342. const changeRequiringRerender = minDateChange || maxDateChange || changes['dateFilter'];
  2343. if (changeRequiringRerender && !changeRequiringRerender.firstChange) {
  2344. const view = this._getCurrentViewComponent();
  2345. if (view) {
  2346. // Schedule focus to be moved to the active date since re-rendering can blur the active
  2347. // cell (see #29265), however don't do so if focus is outside of the calendar, because it
  2348. // can steal away the user's attention (see #30635).
  2349. if (this._elementRef.nativeElement.contains(_getFocusedElementPierceShadowDom())) {
  2350. this._moveFocusOnNextTick = true;
  2351. }
  2352. // We need to `detectChanges` manually here, because the `minDate`, `maxDate` etc. are
  2353. // passed down to the view via data bindings which won't be up-to-date when we call `_init`.
  2354. this._changeDetectorRef.detectChanges();
  2355. view._init();
  2356. }
  2357. }
  2358. this.stateChanges.next();
  2359. }
  2360. /** Focuses the active date. */
  2361. focusActiveCell() {
  2362. this._getCurrentViewComponent()._focusActiveCell(false);
  2363. }
  2364. /** Updates today's date after an update of the active date */
  2365. updateTodaysDate() {
  2366. this._getCurrentViewComponent()._init();
  2367. }
  2368. /** Handles date selection in the month view. */
  2369. _dateSelected(event) {
  2370. const date = event.value;
  2371. if (this.selected instanceof DateRange ||
  2372. (date && !this._dateAdapter.sameDate(date, this.selected))) {
  2373. this.selectedChange.emit(date);
  2374. }
  2375. this._userSelection.emit(event);
  2376. }
  2377. /** Handles year selection in the multiyear view. */
  2378. _yearSelectedInMultiYearView(normalizedYear) {
  2379. this.yearSelected.emit(normalizedYear);
  2380. }
  2381. /** Handles month selection in the year view. */
  2382. _monthSelectedInYearView(normalizedMonth) {
  2383. this.monthSelected.emit(normalizedMonth);
  2384. }
  2385. /** Handles year/month selection in the multi-year/year views. */
  2386. _goToDateInView(date, view) {
  2387. this.activeDate = date;
  2388. this.currentView = view;
  2389. }
  2390. /** Called when the user starts dragging to change a date range. */
  2391. _dragStarted(event) {
  2392. this._activeDrag = event;
  2393. }
  2394. /**
  2395. * Called when a drag completes. It may end in cancelation or in the selection
  2396. * of a new range.
  2397. */
  2398. _dragEnded(event) {
  2399. if (!this._activeDrag)
  2400. return;
  2401. if (event.value) {
  2402. this._userDragDrop.emit(event);
  2403. }
  2404. this._activeDrag = null;
  2405. }
  2406. /** Returns the component instance that corresponds to the current calendar view. */
  2407. _getCurrentViewComponent() {
  2408. // The return type is explicitly written as a union to ensure that the Closure compiler does
  2409. // not optimize calls to _init(). Without the explicit return type, TypeScript narrows it to
  2410. // only the first component type. See https://github.com/angular/components/issues/22996.
  2411. return this.monthView || this.yearView || this.multiYearView;
  2412. }
  2413. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatCalendar, deps: [], target: i0.ɵɵFactoryTarget.Component });
  2414. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.6", type: MatCalendar, isStandalone: true, selector: "mat-calendar", inputs: { headerComponent: "headerComponent", startAt: "startAt", startView: "startView", selected: "selected", minDate: "minDate", maxDate: "maxDate", dateFilter: "dateFilter", dateClass: "dateClass", comparisonStart: "comparisonStart", comparisonEnd: "comparisonEnd", startDateAccessibleName: "startDateAccessibleName", endDateAccessibleName: "endDateAccessibleName" }, outputs: { selectedChange: "selectedChange", yearSelected: "yearSelected", monthSelected: "monthSelected", viewChanged: "viewChanged", _userSelection: "_userSelection", _userDragDrop: "_userDragDrop" }, host: { classAttribute: "mat-calendar" }, providers: [MAT_SINGLE_DATE_SELECTION_MODEL_PROVIDER], viewQueries: [{ propertyName: "monthView", first: true, predicate: MatMonthView, descendants: true }, { propertyName: "yearView", first: true, predicate: MatYearView, descendants: true }, { propertyName: "multiYearView", first: true, predicate: MatMultiYearView, descendants: true }], exportAs: ["matCalendar"], usesOnChanges: true, ngImport: i0, template: "<ng-template [cdkPortalOutlet]=\"_calendarHeaderPortal\"></ng-template>\n\n<div class=\"mat-calendar-content\" cdkMonitorSubtreeFocus tabindex=\"-1\">\n @switch (currentView) {\n @case ('month') {\n <mat-month-view\n [(activeDate)]=\"activeDate\"\n [selected]=\"selected\"\n [dateFilter]=\"dateFilter\"\n [maxDate]=\"maxDate\"\n [minDate]=\"minDate\"\n [dateClass]=\"dateClass\"\n [comparisonStart]=\"comparisonStart\"\n [comparisonEnd]=\"comparisonEnd\"\n [startDateAccessibleName]=\"startDateAccessibleName\"\n [endDateAccessibleName]=\"endDateAccessibleName\"\n (_userSelection)=\"_dateSelected($event)\"\n (dragStarted)=\"_dragStarted($event)\"\n (dragEnded)=\"_dragEnded($event)\"\n [activeDrag]=\"_activeDrag\"></mat-month-view>\n }\n\n @case ('year') {\n <mat-year-view\n [(activeDate)]=\"activeDate\"\n [selected]=\"selected\"\n [dateFilter]=\"dateFilter\"\n [maxDate]=\"maxDate\"\n [minDate]=\"minDate\"\n [dateClass]=\"dateClass\"\n (monthSelected)=\"_monthSelectedInYearView($event)\"\n (selectedChange)=\"_goToDateInView($event, 'month')\"></mat-year-view>\n }\n\n @case ('multi-year') {\n <mat-multi-year-view\n [(activeDate)]=\"activeDate\"\n [selected]=\"selected\"\n [dateFilter]=\"dateFilter\"\n [maxDate]=\"maxDate\"\n [minDate]=\"minDate\"\n [dateClass]=\"dateClass\"\n (yearSelected)=\"_yearSelectedInMultiYearView($event)\"\n (selectedChange)=\"_goToDateInView($event, 'year')\"></mat-multi-year-view>\n }\n }\n</div>\n", styles: [".mat-calendar{display:block;line-height:normal;font-family:var(--mat-datepicker-calendar-text-font, var(--mat-sys-body-medium-font));font-size:var(--mat-datepicker-calendar-text-size, var(--mat-sys-body-medium-size))}.mat-calendar-header{padding:8px 8px 0 8px}.mat-calendar-content{padding:0 8px 8px 8px;outline:none}.mat-calendar-controls{display:flex;align-items:center;margin:5% calc(4.7142857143% - 16px)}.mat-calendar-spacer{flex:1 1 auto}.mat-calendar-period-button{min-width:0;margin:0 8px;font-size:var(--mat-datepicker-calendar-period-button-text-size, var(--mat-sys-title-small-size));font-weight:var(--mat-datepicker-calendar-period-button-text-weight, var(--mat-sys-title-small-weight));--mdc-text-button-label-text-color:var(--mat-datepicker-calendar-period-button-text-color, var(--mat-sys-on-surface-variant))}.mat-calendar-arrow{display:inline-block;width:10px;height:5px;margin:0 0 0 5px;vertical-align:middle;fill:var(--mat-datepicker-calendar-period-button-icon-color, var(--mat-sys-on-surface-variant))}.mat-calendar-arrow.mat-calendar-invert{transform:rotate(180deg)}[dir=rtl] .mat-calendar-arrow{margin:0 5px 0 0}@media(forced-colors: active){.mat-calendar-arrow{fill:CanvasText}}.mat-datepicker-content .mat-calendar-previous-button:not(.mat-mdc-button-disabled),.mat-datepicker-content .mat-calendar-next-button:not(.mat-mdc-button-disabled){color:var(--mat-datepicker-calendar-navigation-button-icon-color, var(--mat-sys-on-surface-variant))}[dir=rtl] .mat-calendar-previous-button,[dir=rtl] .mat-calendar-next-button{transform:rotate(180deg)}.mat-calendar-table{border-spacing:0;border-collapse:collapse;width:100%}.mat-calendar-table-header th{text-align:center;padding:0 0 8px 0;color:var(--mat-datepicker-calendar-header-text-color, var(--mat-sys-on-surface-variant));font-size:var(--mat-datepicker-calendar-header-text-size, var(--mat-sys-title-small-size));font-weight:var(--mat-datepicker-calendar-header-text-weight, var(--mat-sys-title-small-weight))}.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;background:var(--mat-datepicker-calendar-header-divider-color, transparent)}.mat-calendar-body-cell-content::before{margin:calc(calc(var(--mat-focus-indicator-border-width, 3px) + 3px)*-1)}.mat-calendar-body-cell:focus .mat-focus-indicator::before{content:\"\"}\n"], dependencies: [{ kind: "directive", type: CdkPortalOutlet, selector: "[cdkPortalOutlet]", inputs: ["cdkPortalOutlet"], outputs: ["attached"], exportAs: ["cdkPortalOutlet"] }, { kind: "directive", type: CdkMonitorFocus, selector: "[cdkMonitorElementFocus], [cdkMonitorSubtreeFocus]", outputs: ["cdkFocusChange"], exportAs: ["cdkMonitorFocus"] }, { kind: "component", type: MatMonthView, selector: "mat-month-view", inputs: ["activeDate", "selected", "minDate", "maxDate", "dateFilter", "dateClass", "comparisonStart", "comparisonEnd", "startDateAccessibleName", "endDateAccessibleName", "activeDrag"], outputs: ["selectedChange", "_userSelection", "dragStarted", "dragEnded", "activeDateChange"], exportAs: ["matMonthView"] }, { kind: "component", type: MatYearView, selector: "mat-year-view", inputs: ["activeDate", "selected", "minDate", "maxDate", "dateFilter", "dateClass"], outputs: ["selectedChange", "monthSelected", "activeDateChange"], exportAs: ["matYearView"] }, { kind: "component", type: MatMultiYearView, selector: "mat-multi-year-view", inputs: ["activeDate", "selected", "minDate", "maxDate", "dateFilter", "dateClass"], outputs: ["selectedChange", "yearSelected", "activeDateChange"], exportAs: ["matMultiYearView"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
  2415. }
  2416. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatCalendar, decorators: [{
  2417. type: Component,
  2418. args: [{ selector: 'mat-calendar', host: {
  2419. 'class': 'mat-calendar',
  2420. }, exportAs: 'matCalendar', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, providers: [MAT_SINGLE_DATE_SELECTION_MODEL_PROVIDER], imports: [CdkPortalOutlet, CdkMonitorFocus, MatMonthView, MatYearView, MatMultiYearView], template: "<ng-template [cdkPortalOutlet]=\"_calendarHeaderPortal\"></ng-template>\n\n<div class=\"mat-calendar-content\" cdkMonitorSubtreeFocus tabindex=\"-1\">\n @switch (currentView) {\n @case ('month') {\n <mat-month-view\n [(activeDate)]=\"activeDate\"\n [selected]=\"selected\"\n [dateFilter]=\"dateFilter\"\n [maxDate]=\"maxDate\"\n [minDate]=\"minDate\"\n [dateClass]=\"dateClass\"\n [comparisonStart]=\"comparisonStart\"\n [comparisonEnd]=\"comparisonEnd\"\n [startDateAccessibleName]=\"startDateAccessibleName\"\n [endDateAccessibleName]=\"endDateAccessibleName\"\n (_userSelection)=\"_dateSelected($event)\"\n (dragStarted)=\"_dragStarted($event)\"\n (dragEnded)=\"_dragEnded($event)\"\n [activeDrag]=\"_activeDrag\"></mat-month-view>\n }\n\n @case ('year') {\n <mat-year-view\n [(activeDate)]=\"activeDate\"\n [selected]=\"selected\"\n [dateFilter]=\"dateFilter\"\n [maxDate]=\"maxDate\"\n [minDate]=\"minDate\"\n [dateClass]=\"dateClass\"\n (monthSelected)=\"_monthSelectedInYearView($event)\"\n (selectedChange)=\"_goToDateInView($event, 'month')\"></mat-year-view>\n }\n\n @case ('multi-year') {\n <mat-multi-year-view\n [(activeDate)]=\"activeDate\"\n [selected]=\"selected\"\n [dateFilter]=\"dateFilter\"\n [maxDate]=\"maxDate\"\n [minDate]=\"minDate\"\n [dateClass]=\"dateClass\"\n (yearSelected)=\"_yearSelectedInMultiYearView($event)\"\n (selectedChange)=\"_goToDateInView($event, 'year')\"></mat-multi-year-view>\n }\n }\n</div>\n", styles: [".mat-calendar{display:block;line-height:normal;font-family:var(--mat-datepicker-calendar-text-font, var(--mat-sys-body-medium-font));font-size:var(--mat-datepicker-calendar-text-size, var(--mat-sys-body-medium-size))}.mat-calendar-header{padding:8px 8px 0 8px}.mat-calendar-content{padding:0 8px 8px 8px;outline:none}.mat-calendar-controls{display:flex;align-items:center;margin:5% calc(4.7142857143% - 16px)}.mat-calendar-spacer{flex:1 1 auto}.mat-calendar-period-button{min-width:0;margin:0 8px;font-size:var(--mat-datepicker-calendar-period-button-text-size, var(--mat-sys-title-small-size));font-weight:var(--mat-datepicker-calendar-period-button-text-weight, var(--mat-sys-title-small-weight));--mdc-text-button-label-text-color:var(--mat-datepicker-calendar-period-button-text-color, var(--mat-sys-on-surface-variant))}.mat-calendar-arrow{display:inline-block;width:10px;height:5px;margin:0 0 0 5px;vertical-align:middle;fill:var(--mat-datepicker-calendar-period-button-icon-color, var(--mat-sys-on-surface-variant))}.mat-calendar-arrow.mat-calendar-invert{transform:rotate(180deg)}[dir=rtl] .mat-calendar-arrow{margin:0 5px 0 0}@media(forced-colors: active){.mat-calendar-arrow{fill:CanvasText}}.mat-datepicker-content .mat-calendar-previous-button:not(.mat-mdc-button-disabled),.mat-datepicker-content .mat-calendar-next-button:not(.mat-mdc-button-disabled){color:var(--mat-datepicker-calendar-navigation-button-icon-color, var(--mat-sys-on-surface-variant))}[dir=rtl] .mat-calendar-previous-button,[dir=rtl] .mat-calendar-next-button{transform:rotate(180deg)}.mat-calendar-table{border-spacing:0;border-collapse:collapse;width:100%}.mat-calendar-table-header th{text-align:center;padding:0 0 8px 0;color:var(--mat-datepicker-calendar-header-text-color, var(--mat-sys-on-surface-variant));font-size:var(--mat-datepicker-calendar-header-text-size, var(--mat-sys-title-small-size));font-weight:var(--mat-datepicker-calendar-header-text-weight, var(--mat-sys-title-small-weight))}.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;background:var(--mat-datepicker-calendar-header-divider-color, transparent)}.mat-calendar-body-cell-content::before{margin:calc(calc(var(--mat-focus-indicator-border-width, 3px) + 3px)*-1)}.mat-calendar-body-cell:focus .mat-focus-indicator::before{content:\"\"}\n"] }]
  2421. }], ctorParameters: () => [], propDecorators: { headerComponent: [{
  2422. type: Input
  2423. }], startAt: [{
  2424. type: Input
  2425. }], startView: [{
  2426. type: Input
  2427. }], selected: [{
  2428. type: Input
  2429. }], minDate: [{
  2430. type: Input
  2431. }], maxDate: [{
  2432. type: Input
  2433. }], dateFilter: [{
  2434. type: Input
  2435. }], dateClass: [{
  2436. type: Input
  2437. }], comparisonStart: [{
  2438. type: Input
  2439. }], comparisonEnd: [{
  2440. type: Input
  2441. }], startDateAccessibleName: [{
  2442. type: Input
  2443. }], endDateAccessibleName: [{
  2444. type: Input
  2445. }], selectedChange: [{
  2446. type: Output
  2447. }], yearSelected: [{
  2448. type: Output
  2449. }], monthSelected: [{
  2450. type: Output
  2451. }], viewChanged: [{
  2452. type: Output
  2453. }], _userSelection: [{
  2454. type: Output
  2455. }], _userDragDrop: [{
  2456. type: Output
  2457. }], monthView: [{
  2458. type: ViewChild,
  2459. args: [MatMonthView]
  2460. }], yearView: [{
  2461. type: ViewChild,
  2462. args: [MatYearView]
  2463. }], multiYearView: [{
  2464. type: ViewChild,
  2465. args: [MatMultiYearView]
  2466. }] } });
  2467. /** Injection token that determines the scroll handling while the calendar is open. */
  2468. const MAT_DATEPICKER_SCROLL_STRATEGY = new InjectionToken('mat-datepicker-scroll-strategy', {
  2469. providedIn: 'root',
  2470. factory: () => {
  2471. const overlay = inject(Overlay);
  2472. return () => overlay.scrollStrategies.reposition();
  2473. },
  2474. });
  2475. /**
  2476. * @docs-private
  2477. * @deprecated No longer used, will be removed.
  2478. * @breaking-change 21.0.0
  2479. */
  2480. function MAT_DATEPICKER_SCROLL_STRATEGY_FACTORY(overlay) {
  2481. return () => overlay.scrollStrategies.reposition();
  2482. }
  2483. /**
  2484. * @docs-private
  2485. * @deprecated No longer used, will be removed.
  2486. * @breaking-change 21.0.0
  2487. */
  2488. const MAT_DATEPICKER_SCROLL_STRATEGY_FACTORY_PROVIDER = {
  2489. provide: MAT_DATEPICKER_SCROLL_STRATEGY,
  2490. deps: [Overlay],
  2491. useFactory: MAT_DATEPICKER_SCROLL_STRATEGY_FACTORY,
  2492. };
  2493. /**
  2494. * Component used as the content for the datepicker overlay. We use this instead of using
  2495. * MatCalendar directly as the content so we can control the initial focus. This also gives us a
  2496. * place to put additional features of the overlay that are not part of the calendar itself in the
  2497. * future. (e.g. confirmation buttons).
  2498. * @docs-private
  2499. */
  2500. class MatDatepickerContent {
  2501. _elementRef = inject(ElementRef);
  2502. _animationsDisabled = inject(ANIMATION_MODULE_TYPE, { optional: true }) === 'NoopAnimations';
  2503. _changeDetectorRef = inject(ChangeDetectorRef);
  2504. _globalModel = inject(MatDateSelectionModel);
  2505. _dateAdapter = inject(DateAdapter);
  2506. _ngZone = inject(NgZone);
  2507. _rangeSelectionStrategy = inject(MAT_DATE_RANGE_SELECTION_STRATEGY, { optional: true });
  2508. _stateChanges;
  2509. _model;
  2510. _eventCleanups;
  2511. _animationFallback;
  2512. /** Reference to the internal calendar component. */
  2513. _calendar;
  2514. /**
  2515. * Theme color of the internal calendar. This API is supported in M2 themes
  2516. * only, it has no effect in M3 themes. For color customization in M3, see https://material.angular.dev/components/datepicker/styling.
  2517. *
  2518. * For information on applying color variants in M3, see
  2519. * https://material.angular.dev/guide/material-2-theming#optional-add-backwards-compatibility-styles-for-color-variants
  2520. */
  2521. color;
  2522. /** Reference to the datepicker that created the overlay. */
  2523. datepicker;
  2524. /** Start of the comparison range. */
  2525. comparisonStart;
  2526. /** End of the comparison range. */
  2527. comparisonEnd;
  2528. /** ARIA Accessible name of the `<input matStartDate/>` */
  2529. startDateAccessibleName;
  2530. /** ARIA Accessible name of the `<input matEndDate/>` */
  2531. endDateAccessibleName;
  2532. /** Whether the datepicker is above or below the input. */
  2533. _isAbove;
  2534. /** Emits when an animation has finished. */
  2535. _animationDone = new Subject();
  2536. /** Whether there is an in-progress animation. */
  2537. _isAnimating = false;
  2538. /** Text for the close button. */
  2539. _closeButtonText;
  2540. /** Whether the close button currently has focus. */
  2541. _closeButtonFocused;
  2542. /** Portal with projected action buttons. */
  2543. _actionsPortal = null;
  2544. /** Id of the label for the `role="dialog"` element. */
  2545. _dialogLabelId;
  2546. constructor() {
  2547. inject(_CdkPrivateStyleLoader).load(_VisuallyHiddenLoader);
  2548. this._closeButtonText = inject(MatDatepickerIntl).closeCalendarLabel;
  2549. if (!this._animationsDisabled) {
  2550. const element = this._elementRef.nativeElement;
  2551. const renderer = inject(Renderer2);
  2552. this._eventCleanups = this._ngZone.runOutsideAngular(() => [
  2553. renderer.listen(element, 'animationstart', this._handleAnimationEvent),
  2554. renderer.listen(element, 'animationend', this._handleAnimationEvent),
  2555. renderer.listen(element, 'animationcancel', this._handleAnimationEvent),
  2556. ]);
  2557. }
  2558. }
  2559. ngAfterViewInit() {
  2560. this._stateChanges = this.datepicker.stateChanges.subscribe(() => {
  2561. this._changeDetectorRef.markForCheck();
  2562. });
  2563. this._calendar.focusActiveCell();
  2564. }
  2565. ngOnDestroy() {
  2566. clearTimeout(this._animationFallback);
  2567. this._eventCleanups?.forEach(cleanup => cleanup());
  2568. this._stateChanges?.unsubscribe();
  2569. this._animationDone.complete();
  2570. }
  2571. _handleUserSelection(event) {
  2572. const selection = this._model.selection;
  2573. const value = event.value;
  2574. const isRange = selection instanceof DateRange;
  2575. // If we're selecting a range and we have a selection strategy, always pass the value through
  2576. // there. Otherwise don't assign null values to the model, unless we're selecting a range.
  2577. // A null value when picking a range means that the user cancelled the selection (e.g. by
  2578. // pressing escape), whereas when selecting a single value it means that the value didn't
  2579. // change. This isn't very intuitive, but it's here for backwards-compatibility.
  2580. if (isRange && this._rangeSelectionStrategy) {
  2581. const newSelection = this._rangeSelectionStrategy.selectionFinished(value, selection, event.event);
  2582. this._model.updateSelection(newSelection, this);
  2583. }
  2584. else if (value &&
  2585. (isRange || !this._dateAdapter.sameDate(value, selection))) {
  2586. this._model.add(value);
  2587. }
  2588. // Delegate closing the overlay to the actions.
  2589. if ((!this._model || this._model.isComplete()) && !this._actionsPortal) {
  2590. this.datepicker.close();
  2591. }
  2592. }
  2593. _handleUserDragDrop(event) {
  2594. this._model.updateSelection(event.value, this);
  2595. }
  2596. _startExitAnimation() {
  2597. this._elementRef.nativeElement.classList.add('mat-datepicker-content-exit');
  2598. if (this._animationsDisabled) {
  2599. this._animationDone.next();
  2600. }
  2601. else {
  2602. // Some internal apps disable animations in tests using `* {animation: none !important}`.
  2603. // If that happens, the animation events won't fire and we'll never clean up the overlay.
  2604. // Add a fallback that will fire if the animation doesn't run in a certain amount of time.
  2605. clearTimeout(this._animationFallback);
  2606. this._animationFallback = setTimeout(() => {
  2607. if (!this._isAnimating) {
  2608. this._animationDone.next();
  2609. }
  2610. }, 200);
  2611. }
  2612. }
  2613. _handleAnimationEvent = (event) => {
  2614. const element = this._elementRef.nativeElement;
  2615. if (event.target !== element || !event.animationName.startsWith('_mat-datepicker-content')) {
  2616. return;
  2617. }
  2618. clearTimeout(this._animationFallback);
  2619. this._isAnimating = event.type === 'animationstart';
  2620. element.classList.toggle('mat-datepicker-content-animating', this._isAnimating);
  2621. if (!this._isAnimating) {
  2622. this._animationDone.next();
  2623. }
  2624. };
  2625. _getSelected() {
  2626. return this._model.selection;
  2627. }
  2628. /** Applies the current pending selection to the global model. */
  2629. _applyPendingSelection() {
  2630. if (this._model !== this._globalModel) {
  2631. this._globalModel.updateSelection(this._model.selection, this);
  2632. }
  2633. }
  2634. /**
  2635. * Assigns a new portal containing the datepicker actions.
  2636. * @param portal Portal with the actions to be assigned.
  2637. * @param forceRerender Whether a re-render of the portal should be triggered. This isn't
  2638. * necessary if the portal is assigned during initialization, but it may be required if it's
  2639. * added at a later point.
  2640. */
  2641. _assignActions(portal, forceRerender) {
  2642. // If we have actions, clone the model so that we have the ability to cancel the selection,
  2643. // otherwise update the global model directly. Note that we want to assign this as soon as
  2644. // possible, but `_actionsPortal` isn't available in the constructor so we do it in `ngOnInit`.
  2645. this._model = portal ? this._globalModel.clone() : this._globalModel;
  2646. this._actionsPortal = portal;
  2647. if (forceRerender) {
  2648. this._changeDetectorRef.detectChanges();
  2649. }
  2650. }
  2651. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerContent, deps: [], target: i0.ɵɵFactoryTarget.Component });
  2652. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.6", type: MatDatepickerContent, isStandalone: true, selector: "mat-datepicker-content", inputs: { color: "color" }, host: { properties: { "class": "color ? \"mat-\" + color : \"\"", "class.mat-datepicker-content-touch": "datepicker.touchUi", "class.mat-datepicker-content-animations-enabled": "!_animationsDisabled" }, classAttribute: "mat-datepicker-content" }, viewQueries: [{ propertyName: "_calendar", first: true, predicate: MatCalendar, descendants: true }], exportAs: ["matDatepickerContent"], ngImport: i0, template: "<div\n cdkTrapFocus\n role=\"dialog\"\n [attr.aria-modal]=\"true\"\n [attr.aria-labelledby]=\"_dialogLabelId ?? undefined\"\n class=\"mat-datepicker-content-container\"\n [class.mat-datepicker-content-container-with-custom-header]=\"datepicker.calendarHeaderComponent\"\n [class.mat-datepicker-content-container-with-actions]=\"_actionsPortal\">\n <mat-calendar\n [id]=\"datepicker.id\"\n [class]=\"datepicker.panelClass\"\n [startAt]=\"datepicker.startAt\"\n [startView]=\"datepicker.startView\"\n [minDate]=\"datepicker._getMinDate()\"\n [maxDate]=\"datepicker._getMaxDate()\"\n [dateFilter]=\"datepicker._getDateFilter()\"\n [headerComponent]=\"datepicker.calendarHeaderComponent\"\n [selected]=\"_getSelected()\"\n [dateClass]=\"datepicker.dateClass\"\n [comparisonStart]=\"comparisonStart\"\n [comparisonEnd]=\"comparisonEnd\"\n [startDateAccessibleName]=\"startDateAccessibleName\"\n [endDateAccessibleName]=\"endDateAccessibleName\"\n (yearSelected)=\"datepicker._selectYear($event)\"\n (monthSelected)=\"datepicker._selectMonth($event)\"\n (viewChanged)=\"datepicker._viewChanged($event)\"\n (_userSelection)=\"_handleUserSelection($event)\"\n (_userDragDrop)=\"_handleUserDragDrop($event)\"></mat-calendar>\n\n <ng-template [cdkPortalOutlet]=\"_actionsPortal\"></ng-template>\n\n <!-- Invisible close button for screen reader users. -->\n <button\n type=\"button\"\n mat-raised-button\n [color]=\"color || 'primary'\"\n class=\"mat-datepicker-close-button\"\n [class.cdk-visually-hidden]=\"!_closeButtonFocused\"\n (focus)=\"_closeButtonFocused = true\"\n (blur)=\"_closeButtonFocused = false\"\n (click)=\"datepicker.close()\">{{ _closeButtonText }}</button>\n</div>\n", styles: ["@keyframes _mat-datepicker-content-dropdown-enter{from{opacity:0;transform:scaleY(0.8)}to{opacity:1;transform:none}}@keyframes _mat-datepicker-content-dialog-enter{from{opacity:0;transform:scale(0.8)}to{opacity:1;transform:none}}@keyframes _mat-datepicker-content-exit{from{opacity:1}to{opacity:0}}.mat-datepicker-content{display:block;border-radius:4px;background-color:var(--mat-datepicker-calendar-container-background-color, var(--mat-sys-surface-container-high));color:var(--mat-datepicker-calendar-container-text-color, var(--mat-sys-on-surface));box-shadow:var(--mat-datepicker-calendar-container-elevation-shadow, 0px 0px 0px 0px rgba(0, 0, 0, 0.2), 0px 0px 0px 0px rgba(0, 0, 0, 0.14), 0px 0px 0px 0px rgba(0, 0, 0, 0.12));border-radius:var(--mat-datepicker-calendar-container-shape, var(--mat-sys-corner-large))}.mat-datepicker-content.mat-datepicker-content-animations-enabled{animation:_mat-datepicker-content-dropdown-enter 120ms cubic-bezier(0, 0, 0.2, 1)}.mat-datepicker-content .mat-calendar{width:296px;height:354px}.mat-datepicker-content .mat-datepicker-content-container-with-custom-header .mat-calendar{height:auto}.mat-datepicker-content .mat-datepicker-close-button{position:absolute;top:100%;left:0;margin-top:8px}.mat-datepicker-content-animating .mat-datepicker-content .mat-datepicker-close-button{display:none}.mat-datepicker-content-container{display:flex;flex-direction:column;justify-content:space-between}.mat-datepicker-content-touch{display:block;max-height:80vh;box-shadow:var(--mat-datepicker-calendar-container-touch-elevation-shadow, 0px 0px 0px 0px rgba(0, 0, 0, 0.2), 0px 0px 0px 0px rgba(0, 0, 0, 0.14), 0px 0px 0px 0px rgba(0, 0, 0, 0.12));border-radius:var(--mat-datepicker-calendar-container-touch-shape, var(--mat-sys-corner-extra-large));position:relative;overflow:visible}.mat-datepicker-content-touch.mat-datepicker-content-animations-enabled{animation:_mat-datepicker-content-dialog-enter 150ms cubic-bezier(0, 0, 0.2, 1)}.mat-datepicker-content-touch .mat-datepicker-content-container{min-height:312px;max-height:788px;min-width:250px;max-width:750px}.mat-datepicker-content-touch .mat-calendar{width:100%;height:auto}.mat-datepicker-content-exit.mat-datepicker-content-animations-enabled{animation:_mat-datepicker-content-exit 100ms linear}@media all and (orientation: landscape){.mat-datepicker-content-touch .mat-datepicker-content-container{width:64vh;height:80vh}}@media all and (orientation: portrait){.mat-datepicker-content-touch .mat-datepicker-content-container{width:80vw;height:100vw}.mat-datepicker-content-touch .mat-datepicker-content-container-with-actions{height:115vw}}\n"], dependencies: [{ kind: "directive", type: CdkTrapFocus, selector: "[cdkTrapFocus]", inputs: ["cdkTrapFocus", "cdkTrapFocusAutoCapture"], exportAs: ["cdkTrapFocus"] }, { kind: "component", type: MatCalendar, selector: "mat-calendar", inputs: ["headerComponent", "startAt", "startView", "selected", "minDate", "maxDate", "dateFilter", "dateClass", "comparisonStart", "comparisonEnd", "startDateAccessibleName", "endDateAccessibleName"], outputs: ["selectedChange", "yearSelected", "monthSelected", "viewChanged", "_userSelection", "_userDragDrop"], exportAs: ["matCalendar"] }, { kind: "directive", type: CdkPortalOutlet, selector: "[cdkPortalOutlet]", inputs: ["cdkPortalOutlet"], outputs: ["attached"], exportAs: ["cdkPortalOutlet"] }, { kind: "component", type: MatButton, selector: " button[mat-button], button[mat-raised-button], button[mat-flat-button], button[mat-stroked-button] ", exportAs: ["matButton"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
  2653. }
  2654. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerContent, decorators: [{
  2655. type: Component,
  2656. args: [{ selector: 'mat-datepicker-content', host: {
  2657. 'class': 'mat-datepicker-content',
  2658. '[class]': 'color ? "mat-" + color : ""',
  2659. '[class.mat-datepicker-content-touch]': 'datepicker.touchUi',
  2660. '[class.mat-datepicker-content-animations-enabled]': '!_animationsDisabled',
  2661. }, exportAs: 'matDatepickerContent', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, imports: [CdkTrapFocus, MatCalendar, CdkPortalOutlet, MatButton], template: "<div\n cdkTrapFocus\n role=\"dialog\"\n [attr.aria-modal]=\"true\"\n [attr.aria-labelledby]=\"_dialogLabelId ?? undefined\"\n class=\"mat-datepicker-content-container\"\n [class.mat-datepicker-content-container-with-custom-header]=\"datepicker.calendarHeaderComponent\"\n [class.mat-datepicker-content-container-with-actions]=\"_actionsPortal\">\n <mat-calendar\n [id]=\"datepicker.id\"\n [class]=\"datepicker.panelClass\"\n [startAt]=\"datepicker.startAt\"\n [startView]=\"datepicker.startView\"\n [minDate]=\"datepicker._getMinDate()\"\n [maxDate]=\"datepicker._getMaxDate()\"\n [dateFilter]=\"datepicker._getDateFilter()\"\n [headerComponent]=\"datepicker.calendarHeaderComponent\"\n [selected]=\"_getSelected()\"\n [dateClass]=\"datepicker.dateClass\"\n [comparisonStart]=\"comparisonStart\"\n [comparisonEnd]=\"comparisonEnd\"\n [startDateAccessibleName]=\"startDateAccessibleName\"\n [endDateAccessibleName]=\"endDateAccessibleName\"\n (yearSelected)=\"datepicker._selectYear($event)\"\n (monthSelected)=\"datepicker._selectMonth($event)\"\n (viewChanged)=\"datepicker._viewChanged($event)\"\n (_userSelection)=\"_handleUserSelection($event)\"\n (_userDragDrop)=\"_handleUserDragDrop($event)\"></mat-calendar>\n\n <ng-template [cdkPortalOutlet]=\"_actionsPortal\"></ng-template>\n\n <!-- Invisible close button for screen reader users. -->\n <button\n type=\"button\"\n mat-raised-button\n [color]=\"color || 'primary'\"\n class=\"mat-datepicker-close-button\"\n [class.cdk-visually-hidden]=\"!_closeButtonFocused\"\n (focus)=\"_closeButtonFocused = true\"\n (blur)=\"_closeButtonFocused = false\"\n (click)=\"datepicker.close()\">{{ _closeButtonText }}</button>\n</div>\n", styles: ["@keyframes _mat-datepicker-content-dropdown-enter{from{opacity:0;transform:scaleY(0.8)}to{opacity:1;transform:none}}@keyframes _mat-datepicker-content-dialog-enter{from{opacity:0;transform:scale(0.8)}to{opacity:1;transform:none}}@keyframes _mat-datepicker-content-exit{from{opacity:1}to{opacity:0}}.mat-datepicker-content{display:block;border-radius:4px;background-color:var(--mat-datepicker-calendar-container-background-color, var(--mat-sys-surface-container-high));color:var(--mat-datepicker-calendar-container-text-color, var(--mat-sys-on-surface));box-shadow:var(--mat-datepicker-calendar-container-elevation-shadow, 0px 0px 0px 0px rgba(0, 0, 0, 0.2), 0px 0px 0px 0px rgba(0, 0, 0, 0.14), 0px 0px 0px 0px rgba(0, 0, 0, 0.12));border-radius:var(--mat-datepicker-calendar-container-shape, var(--mat-sys-corner-large))}.mat-datepicker-content.mat-datepicker-content-animations-enabled{animation:_mat-datepicker-content-dropdown-enter 120ms cubic-bezier(0, 0, 0.2, 1)}.mat-datepicker-content .mat-calendar{width:296px;height:354px}.mat-datepicker-content .mat-datepicker-content-container-with-custom-header .mat-calendar{height:auto}.mat-datepicker-content .mat-datepicker-close-button{position:absolute;top:100%;left:0;margin-top:8px}.mat-datepicker-content-animating .mat-datepicker-content .mat-datepicker-close-button{display:none}.mat-datepicker-content-container{display:flex;flex-direction:column;justify-content:space-between}.mat-datepicker-content-touch{display:block;max-height:80vh;box-shadow:var(--mat-datepicker-calendar-container-touch-elevation-shadow, 0px 0px 0px 0px rgba(0, 0, 0, 0.2), 0px 0px 0px 0px rgba(0, 0, 0, 0.14), 0px 0px 0px 0px rgba(0, 0, 0, 0.12));border-radius:var(--mat-datepicker-calendar-container-touch-shape, var(--mat-sys-corner-extra-large));position:relative;overflow:visible}.mat-datepicker-content-touch.mat-datepicker-content-animations-enabled{animation:_mat-datepicker-content-dialog-enter 150ms cubic-bezier(0, 0, 0.2, 1)}.mat-datepicker-content-touch .mat-datepicker-content-container{min-height:312px;max-height:788px;min-width:250px;max-width:750px}.mat-datepicker-content-touch .mat-calendar{width:100%;height:auto}.mat-datepicker-content-exit.mat-datepicker-content-animations-enabled{animation:_mat-datepicker-content-exit 100ms linear}@media all and (orientation: landscape){.mat-datepicker-content-touch .mat-datepicker-content-container{width:64vh;height:80vh}}@media all and (orientation: portrait){.mat-datepicker-content-touch .mat-datepicker-content-container{width:80vw;height:100vw}.mat-datepicker-content-touch .mat-datepicker-content-container-with-actions{height:115vw}}\n"] }]
  2662. }], ctorParameters: () => [], propDecorators: { _calendar: [{
  2663. type: ViewChild,
  2664. args: [MatCalendar]
  2665. }], color: [{
  2666. type: Input
  2667. }] } });
  2668. /** Base class for a datepicker. */
  2669. class MatDatepickerBase {
  2670. _overlay = inject(Overlay);
  2671. _viewContainerRef = inject(ViewContainerRef);
  2672. _dateAdapter = inject(DateAdapter, { optional: true });
  2673. _dir = inject(Directionality, { optional: true });
  2674. _model = inject(MatDateSelectionModel);
  2675. _scrollStrategy = inject(MAT_DATEPICKER_SCROLL_STRATEGY);
  2676. _inputStateChanges = Subscription.EMPTY;
  2677. _document = inject(DOCUMENT);
  2678. /** An input indicating the type of the custom header component for the calendar, if set. */
  2679. calendarHeaderComponent;
  2680. /** The date to open the calendar to initially. */
  2681. get startAt() {
  2682. // If an explicit startAt is set we start there, otherwise we start at whatever the currently
  2683. // selected value is.
  2684. return this._startAt || (this.datepickerInput ? this.datepickerInput.getStartValue() : null);
  2685. }
  2686. set startAt(value) {
  2687. this._startAt = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value));
  2688. }
  2689. _startAt;
  2690. /** The view that the calendar should start in. */
  2691. startView = 'month';
  2692. /**
  2693. * Theme color of the datepicker's calendar. This API is supported in M2 themes only, it
  2694. * has no effect in M3 themes. For color customization in M3, see https://material.angular.dev/components/datepicker/styling.
  2695. *
  2696. * For information on applying color variants in M3, see
  2697. * https://material.angular.dev/guide/material-2-theming#optional-add-backwards-compatibility-styles-for-color-variants
  2698. */
  2699. get color() {
  2700. return (this._color || (this.datepickerInput ? this.datepickerInput.getThemePalette() : undefined));
  2701. }
  2702. set color(value) {
  2703. this._color = value;
  2704. }
  2705. _color;
  2706. /**
  2707. * Whether the calendar UI is in touch mode. In touch mode the calendar opens in a dialog rather
  2708. * than a dropdown and elements have more padding to allow for bigger touch targets.
  2709. */
  2710. touchUi = false;
  2711. /** Whether the datepicker pop-up should be disabled. */
  2712. get disabled() {
  2713. return this._disabled === undefined && this.datepickerInput
  2714. ? this.datepickerInput.disabled
  2715. : !!this._disabled;
  2716. }
  2717. set disabled(value) {
  2718. if (value !== this._disabled) {
  2719. this._disabled = value;
  2720. this.stateChanges.next(undefined);
  2721. }
  2722. }
  2723. _disabled;
  2724. /** Preferred position of the datepicker in the X axis. */
  2725. xPosition = 'start';
  2726. /** Preferred position of the datepicker in the Y axis. */
  2727. yPosition = 'below';
  2728. /**
  2729. * Whether to restore focus to the previously-focused element when the calendar is closed.
  2730. * Note that automatic focus restoration is an accessibility feature and it is recommended that
  2731. * you provide your own equivalent, if you decide to turn it off.
  2732. */
  2733. restoreFocus = true;
  2734. /**
  2735. * Emits selected year in multiyear view.
  2736. * This doesn't imply a change on the selected date.
  2737. */
  2738. yearSelected = new EventEmitter();
  2739. /**
  2740. * Emits selected month in year view.
  2741. * This doesn't imply a change on the selected date.
  2742. */
  2743. monthSelected = new EventEmitter();
  2744. /**
  2745. * Emits when the current view changes.
  2746. */
  2747. viewChanged = new EventEmitter(true);
  2748. /** Function that can be used to add custom CSS classes to dates. */
  2749. dateClass;
  2750. /** Emits when the datepicker has been opened. */
  2751. openedStream = new EventEmitter();
  2752. /** Emits when the datepicker has been closed. */
  2753. closedStream = new EventEmitter();
  2754. /** Classes to be passed to the date picker panel. */
  2755. get panelClass() {
  2756. return this._panelClass;
  2757. }
  2758. set panelClass(value) {
  2759. this._panelClass = coerceStringArray(value);
  2760. }
  2761. _panelClass;
  2762. /** Whether the calendar is open. */
  2763. get opened() {
  2764. return this._opened;
  2765. }
  2766. set opened(value) {
  2767. if (value) {
  2768. this.open();
  2769. }
  2770. else {
  2771. this.close();
  2772. }
  2773. }
  2774. _opened = false;
  2775. /** The id for the datepicker calendar. */
  2776. id = inject(_IdGenerator).getId('mat-datepicker-');
  2777. /** The minimum selectable date. */
  2778. _getMinDate() {
  2779. return this.datepickerInput && this.datepickerInput.min;
  2780. }
  2781. /** The maximum selectable date. */
  2782. _getMaxDate() {
  2783. return this.datepickerInput && this.datepickerInput.max;
  2784. }
  2785. _getDateFilter() {
  2786. return this.datepickerInput && this.datepickerInput.dateFilter;
  2787. }
  2788. /** A reference to the overlay into which we've rendered the calendar. */
  2789. _overlayRef;
  2790. /** Reference to the component instance rendered in the overlay. */
  2791. _componentRef;
  2792. /** The element that was focused before the datepicker was opened. */
  2793. _focusedElementBeforeOpen = null;
  2794. /** Unique class that will be added to the backdrop so that the test harnesses can look it up. */
  2795. _backdropHarnessClass = `${this.id}-backdrop`;
  2796. /** Currently-registered actions portal. */
  2797. _actionsPortal;
  2798. /** The input element this datepicker is associated with. */
  2799. datepickerInput;
  2800. /** Emits when the datepicker's state changes. */
  2801. stateChanges = new Subject();
  2802. _injector = inject(Injector);
  2803. _changeDetectorRef = inject(ChangeDetectorRef);
  2804. constructor() {
  2805. if (!this._dateAdapter && (typeof ngDevMode === 'undefined' || ngDevMode)) {
  2806. throw createMissingDateImplError('DateAdapter');
  2807. }
  2808. this._model.selectionChanged.subscribe(() => {
  2809. this._changeDetectorRef.markForCheck();
  2810. });
  2811. }
  2812. ngOnChanges(changes) {
  2813. const positionChange = changes['xPosition'] || changes['yPosition'];
  2814. if (positionChange && !positionChange.firstChange && this._overlayRef) {
  2815. const positionStrategy = this._overlayRef.getConfig().positionStrategy;
  2816. if (positionStrategy instanceof FlexibleConnectedPositionStrategy) {
  2817. this._setConnectedPositions(positionStrategy);
  2818. if (this.opened) {
  2819. this._overlayRef.updatePosition();
  2820. }
  2821. }
  2822. }
  2823. this.stateChanges.next(undefined);
  2824. }
  2825. ngOnDestroy() {
  2826. this._destroyOverlay();
  2827. this.close();
  2828. this._inputStateChanges.unsubscribe();
  2829. this.stateChanges.complete();
  2830. }
  2831. /** Selects the given date */
  2832. select(date) {
  2833. this._model.add(date);
  2834. }
  2835. /** Emits the selected year in multiyear view */
  2836. _selectYear(normalizedYear) {
  2837. this.yearSelected.emit(normalizedYear);
  2838. }
  2839. /** Emits selected month in year view */
  2840. _selectMonth(normalizedMonth) {
  2841. this.monthSelected.emit(normalizedMonth);
  2842. }
  2843. /** Emits changed view */
  2844. _viewChanged(view) {
  2845. this.viewChanged.emit(view);
  2846. }
  2847. /**
  2848. * Register an input with this datepicker.
  2849. * @param input The datepicker input to register with this datepicker.
  2850. * @returns Selection model that the input should hook itself up to.
  2851. */
  2852. registerInput(input) {
  2853. if (this.datepickerInput && (typeof ngDevMode === 'undefined' || ngDevMode)) {
  2854. throw Error('A MatDatepicker can only be associated with a single input.');
  2855. }
  2856. this._inputStateChanges.unsubscribe();
  2857. this.datepickerInput = input;
  2858. this._inputStateChanges = input.stateChanges.subscribe(() => this.stateChanges.next(undefined));
  2859. return this._model;
  2860. }
  2861. /**
  2862. * Registers a portal containing action buttons with the datepicker.
  2863. * @param portal Portal to be registered.
  2864. */
  2865. registerActions(portal) {
  2866. if (this._actionsPortal && (typeof ngDevMode === 'undefined' || ngDevMode)) {
  2867. throw Error('A MatDatepicker can only be associated with a single actions row.');
  2868. }
  2869. this._actionsPortal = portal;
  2870. this._componentRef?.instance._assignActions(portal, true);
  2871. }
  2872. /**
  2873. * Removes a portal containing action buttons from the datepicker.
  2874. * @param portal Portal to be removed.
  2875. */
  2876. removeActions(portal) {
  2877. if (portal === this._actionsPortal) {
  2878. this._actionsPortal = null;
  2879. this._componentRef?.instance._assignActions(null, true);
  2880. }
  2881. }
  2882. /** Open the calendar. */
  2883. open() {
  2884. // Skip reopening if there's an in-progress animation to avoid overlapping
  2885. // sequences which can cause "changed after checked" errors. See #25837.
  2886. if (this._opened || this.disabled || this._componentRef?.instance._isAnimating) {
  2887. return;
  2888. }
  2889. if (!this.datepickerInput && (typeof ngDevMode === 'undefined' || ngDevMode)) {
  2890. throw Error('Attempted to open an MatDatepicker with no associated input.');
  2891. }
  2892. this._focusedElementBeforeOpen = _getFocusedElementPierceShadowDom();
  2893. this._openOverlay();
  2894. this._opened = true;
  2895. this.openedStream.emit();
  2896. }
  2897. /** Close the calendar. */
  2898. close() {
  2899. // Skip reopening if there's an in-progress animation to avoid overlapping
  2900. // sequences which can cause "changed after checked" errors. See #25837.
  2901. if (!this._opened || this._componentRef?.instance._isAnimating) {
  2902. return;
  2903. }
  2904. const canRestoreFocus = this.restoreFocus &&
  2905. this._focusedElementBeforeOpen &&
  2906. typeof this._focusedElementBeforeOpen.focus === 'function';
  2907. const completeClose = () => {
  2908. // The `_opened` could've been reset already if
  2909. // we got two events in quick succession.
  2910. if (this._opened) {
  2911. this._opened = false;
  2912. this.closedStream.emit();
  2913. }
  2914. };
  2915. if (this._componentRef) {
  2916. const { instance, location } = this._componentRef;
  2917. instance._animationDone.pipe(take(1)).subscribe(() => {
  2918. const activeElement = this._document.activeElement;
  2919. // Since we restore focus after the exit animation, we have to check that
  2920. // the user didn't move focus themselves inside the `close` handler.
  2921. if (canRestoreFocus &&
  2922. (!activeElement ||
  2923. activeElement === this._document.activeElement ||
  2924. location.nativeElement.contains(activeElement))) {
  2925. this._focusedElementBeforeOpen.focus();
  2926. }
  2927. this._focusedElementBeforeOpen = null;
  2928. this._destroyOverlay();
  2929. });
  2930. instance._startExitAnimation();
  2931. }
  2932. if (canRestoreFocus) {
  2933. // Because IE moves focus asynchronously, we can't count on it being restored before we've
  2934. // marked the datepicker as closed. If the event fires out of sequence and the element that
  2935. // we're refocusing opens the datepicker on focus, the user could be stuck with not being
  2936. // able to close the calendar at all. We work around it by making the logic, that marks
  2937. // the datepicker as closed, async as well.
  2938. setTimeout(completeClose);
  2939. }
  2940. else {
  2941. completeClose();
  2942. }
  2943. }
  2944. /** Applies the current pending selection on the overlay to the model. */
  2945. _applyPendingSelection() {
  2946. this._componentRef?.instance?._applyPendingSelection();
  2947. }
  2948. /** Forwards relevant values from the datepicker to the datepicker content inside the overlay. */
  2949. _forwardContentValues(instance) {
  2950. instance.datepicker = this;
  2951. instance.color = this.color;
  2952. instance._dialogLabelId = this.datepickerInput.getOverlayLabelId();
  2953. instance._assignActions(this._actionsPortal, false);
  2954. }
  2955. /** Opens the overlay with the calendar. */
  2956. _openOverlay() {
  2957. this._destroyOverlay();
  2958. const isDialog = this.touchUi;
  2959. const portal = new ComponentPortal(MatDatepickerContent, this._viewContainerRef);
  2960. const overlayRef = (this._overlayRef = this._overlay.create(new OverlayConfig({
  2961. positionStrategy: isDialog ? this._getDialogStrategy() : this._getDropdownStrategy(),
  2962. hasBackdrop: true,
  2963. backdropClass: [
  2964. isDialog ? 'cdk-overlay-dark-backdrop' : 'mat-overlay-transparent-backdrop',
  2965. this._backdropHarnessClass,
  2966. ],
  2967. direction: this._dir || 'ltr',
  2968. scrollStrategy: isDialog ? this._overlay.scrollStrategies.block() : this._scrollStrategy(),
  2969. panelClass: `mat-datepicker-${isDialog ? 'dialog' : 'popup'}`,
  2970. })));
  2971. this._getCloseStream(overlayRef).subscribe(event => {
  2972. if (event) {
  2973. event.preventDefault();
  2974. }
  2975. this.close();
  2976. });
  2977. // The `preventDefault` call happens inside the calendar as well, however focus moves into
  2978. // it inside a timeout which can give browsers a chance to fire off a keyboard event in-between
  2979. // that can scroll the page (see #24969). Always block default actions of arrow keys for the
  2980. // entire overlay so the page doesn't get scrolled by accident.
  2981. overlayRef.keydownEvents().subscribe(event => {
  2982. const keyCode = event.keyCode;
  2983. if (keyCode === UP_ARROW ||
  2984. keyCode === DOWN_ARROW ||
  2985. keyCode === LEFT_ARROW ||
  2986. keyCode === RIGHT_ARROW ||
  2987. keyCode === PAGE_UP ||
  2988. keyCode === PAGE_DOWN) {
  2989. event.preventDefault();
  2990. }
  2991. });
  2992. this._componentRef = overlayRef.attach(portal);
  2993. this._forwardContentValues(this._componentRef.instance);
  2994. // Update the position once the calendar has rendered. Only relevant in dropdown mode.
  2995. if (!isDialog) {
  2996. afterNextRender(() => {
  2997. overlayRef.updatePosition();
  2998. }, { injector: this._injector });
  2999. }
  3000. }
  3001. /** Destroys the current overlay. */
  3002. _destroyOverlay() {
  3003. if (this._overlayRef) {
  3004. this._overlayRef.dispose();
  3005. this._overlayRef = this._componentRef = null;
  3006. }
  3007. }
  3008. /** Gets a position strategy that will open the calendar as a dropdown. */
  3009. _getDialogStrategy() {
  3010. return this._overlay.position().global().centerHorizontally().centerVertically();
  3011. }
  3012. /** Gets a position strategy that will open the calendar as a dropdown. */
  3013. _getDropdownStrategy() {
  3014. const strategy = this._overlay
  3015. .position()
  3016. .flexibleConnectedTo(this.datepickerInput.getConnectedOverlayOrigin())
  3017. .withTransformOriginOn('.mat-datepicker-content')
  3018. .withFlexibleDimensions(false)
  3019. .withViewportMargin(8)
  3020. .withLockedPosition();
  3021. return this._setConnectedPositions(strategy);
  3022. }
  3023. /** Sets the positions of the datepicker in dropdown mode based on the current configuration. */
  3024. _setConnectedPositions(strategy) {
  3025. const primaryX = this.xPosition === 'end' ? 'end' : 'start';
  3026. const secondaryX = primaryX === 'start' ? 'end' : 'start';
  3027. const primaryY = this.yPosition === 'above' ? 'bottom' : 'top';
  3028. const secondaryY = primaryY === 'top' ? 'bottom' : 'top';
  3029. return strategy.withPositions([
  3030. {
  3031. originX: primaryX,
  3032. originY: secondaryY,
  3033. overlayX: primaryX,
  3034. overlayY: primaryY,
  3035. },
  3036. {
  3037. originX: primaryX,
  3038. originY: primaryY,
  3039. overlayX: primaryX,
  3040. overlayY: secondaryY,
  3041. },
  3042. {
  3043. originX: secondaryX,
  3044. originY: secondaryY,
  3045. overlayX: secondaryX,
  3046. overlayY: primaryY,
  3047. },
  3048. {
  3049. originX: secondaryX,
  3050. originY: primaryY,
  3051. overlayX: secondaryX,
  3052. overlayY: secondaryY,
  3053. },
  3054. ]);
  3055. }
  3056. /** Gets an observable that will emit when the overlay is supposed to be closed. */
  3057. _getCloseStream(overlayRef) {
  3058. const ctrlShiftMetaModifiers = ['ctrlKey', 'shiftKey', 'metaKey'];
  3059. return merge(overlayRef.backdropClick(), overlayRef.detachments(), overlayRef.keydownEvents().pipe(filter(event => {
  3060. // Closing on alt + up is only valid when there's an input associated with the datepicker.
  3061. return ((event.keyCode === ESCAPE && !hasModifierKey(event)) ||
  3062. (this.datepickerInput &&
  3063. hasModifierKey(event, 'altKey') &&
  3064. event.keyCode === UP_ARROW &&
  3065. ctrlShiftMetaModifiers.every((modifier) => !hasModifierKey(event, modifier))));
  3066. })));
  3067. }
  3068. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerBase, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  3069. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "19.2.6", type: MatDatepickerBase, isStandalone: true, inputs: { calendarHeaderComponent: "calendarHeaderComponent", startAt: "startAt", startView: "startView", color: "color", touchUi: ["touchUi", "touchUi", booleanAttribute], disabled: ["disabled", "disabled", booleanAttribute], xPosition: "xPosition", yPosition: "yPosition", restoreFocus: ["restoreFocus", "restoreFocus", booleanAttribute], dateClass: "dateClass", panelClass: "panelClass", opened: ["opened", "opened", booleanAttribute] }, outputs: { yearSelected: "yearSelected", monthSelected: "monthSelected", viewChanged: "viewChanged", openedStream: "opened", closedStream: "closed" }, usesOnChanges: true, ngImport: i0 });
  3070. }
  3071. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerBase, decorators: [{
  3072. type: Directive
  3073. }], ctorParameters: () => [], propDecorators: { calendarHeaderComponent: [{
  3074. type: Input
  3075. }], startAt: [{
  3076. type: Input
  3077. }], startView: [{
  3078. type: Input
  3079. }], color: [{
  3080. type: Input
  3081. }], touchUi: [{
  3082. type: Input,
  3083. args: [{ transform: booleanAttribute }]
  3084. }], disabled: [{
  3085. type: Input,
  3086. args: [{ transform: booleanAttribute }]
  3087. }], xPosition: [{
  3088. type: Input
  3089. }], yPosition: [{
  3090. type: Input
  3091. }], restoreFocus: [{
  3092. type: Input,
  3093. args: [{ transform: booleanAttribute }]
  3094. }], yearSelected: [{
  3095. type: Output
  3096. }], monthSelected: [{
  3097. type: Output
  3098. }], viewChanged: [{
  3099. type: Output
  3100. }], dateClass: [{
  3101. type: Input
  3102. }], openedStream: [{
  3103. type: Output,
  3104. args: ['opened']
  3105. }], closedStream: [{
  3106. type: Output,
  3107. args: ['closed']
  3108. }], panelClass: [{
  3109. type: Input
  3110. }], opened: [{
  3111. type: Input,
  3112. args: [{ transform: booleanAttribute }]
  3113. }] } });
  3114. // TODO(mmalerba): We use a component instead of a directive here so the user can use implicit
  3115. // template reference variables (e.g. #d vs #d="matDatepicker"). We can change this to a directive
  3116. // if angular adds support for `exportAs: '$implicit'` on directives.
  3117. /** Component responsible for managing the datepicker popup/dialog. */
  3118. class MatDatepicker extends MatDatepickerBase {
  3119. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepicker, deps: null, target: i0.ɵɵFactoryTarget.Component });
  3120. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.6", type: MatDatepicker, isStandalone: true, selector: "mat-datepicker", providers: [
  3121. MAT_SINGLE_DATE_SELECTION_MODEL_PROVIDER,
  3122. { provide: MatDatepickerBase, useExisting: MatDatepicker },
  3123. ], exportAs: ["matDatepicker"], usesInheritance: true, ngImport: i0, template: '', isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
  3124. }
  3125. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepicker, decorators: [{
  3126. type: Component,
  3127. args: [{
  3128. selector: 'mat-datepicker',
  3129. template: '',
  3130. exportAs: 'matDatepicker',
  3131. changeDetection: ChangeDetectionStrategy.OnPush,
  3132. encapsulation: ViewEncapsulation.None,
  3133. providers: [
  3134. MAT_SINGLE_DATE_SELECTION_MODEL_PROVIDER,
  3135. { provide: MatDatepickerBase, useExisting: MatDatepicker },
  3136. ],
  3137. }]
  3138. }] });
  3139. /**
  3140. * An event used for datepicker input and change events. We don't always have access to a native
  3141. * input or change event because the event may have been triggered by the user clicking on the
  3142. * calendar popup. For consistency, we always use MatDatepickerInputEvent instead.
  3143. */
  3144. class MatDatepickerInputEvent {
  3145. target;
  3146. targetElement;
  3147. /** The new value for the target datepicker input. */
  3148. value;
  3149. constructor(
  3150. /** Reference to the datepicker input component that emitted the event. */
  3151. target,
  3152. /** Reference to the native input element associated with the datepicker input. */
  3153. targetElement) {
  3154. this.target = target;
  3155. this.targetElement = targetElement;
  3156. this.value = this.target.value;
  3157. }
  3158. }
  3159. /** Base class for datepicker inputs. */
  3160. class MatDatepickerInputBase {
  3161. _elementRef = inject(ElementRef);
  3162. _dateAdapter = inject(DateAdapter, { optional: true });
  3163. _dateFormats = inject(MAT_DATE_FORMATS, { optional: true });
  3164. /** Whether the component has been initialized. */
  3165. _isInitialized;
  3166. /** The value of the input. */
  3167. get value() {
  3168. return this._model ? this._getValueFromModel(this._model.selection) : this._pendingValue;
  3169. }
  3170. set value(value) {
  3171. this._assignValueProgrammatically(value);
  3172. }
  3173. _model;
  3174. /** Whether the datepicker-input is disabled. */
  3175. get disabled() {
  3176. return !!this._disabled || this._parentDisabled();
  3177. }
  3178. set disabled(value) {
  3179. const newValue = value;
  3180. const element = this._elementRef.nativeElement;
  3181. if (this._disabled !== newValue) {
  3182. this._disabled = newValue;
  3183. this.stateChanges.next(undefined);
  3184. }
  3185. // We need to null check the `blur` method, because it's undefined during SSR.
  3186. // In Ivy static bindings are invoked earlier, before the element is attached to the DOM.
  3187. // This can cause an error to be thrown in some browsers (IE/Edge) which assert that the
  3188. // element has been inserted.
  3189. if (newValue && this._isInitialized && element.blur) {
  3190. // Normally, native input elements automatically blur if they turn disabled. This behavior
  3191. // is problematic, because it would mean that it triggers another change detection cycle,
  3192. // which then causes a changed after checked error if the input element was focused before.
  3193. element.blur();
  3194. }
  3195. }
  3196. _disabled;
  3197. /** Emits when a `change` event is fired on this `<input>`. */
  3198. dateChange = new EventEmitter();
  3199. /** Emits when an `input` event is fired on this `<input>`. */
  3200. dateInput = new EventEmitter();
  3201. /** Emits when the internal state has changed */
  3202. stateChanges = new Subject();
  3203. _onTouched = () => { };
  3204. _validatorOnChange = () => { };
  3205. _cvaOnChange = () => { };
  3206. _valueChangesSubscription = Subscription.EMPTY;
  3207. _localeSubscription = Subscription.EMPTY;
  3208. /**
  3209. * Since the value is kept on the model which is assigned in an Input,
  3210. * we might get a value before we have a model. This property keeps track
  3211. * of the value until we have somewhere to assign it.
  3212. */
  3213. _pendingValue;
  3214. /** The form control validator for whether the input parses. */
  3215. _parseValidator = () => {
  3216. return this._lastValueValid
  3217. ? null
  3218. : { 'matDatepickerParse': { 'text': this._elementRef.nativeElement.value } };
  3219. };
  3220. /** The form control validator for the date filter. */
  3221. _filterValidator = (control) => {
  3222. const controlValue = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(control.value));
  3223. return !controlValue || this._matchesFilter(controlValue)
  3224. ? null
  3225. : { 'matDatepickerFilter': true };
  3226. };
  3227. /** The form control validator for the min date. */
  3228. _minValidator = (control) => {
  3229. const controlValue = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(control.value));
  3230. const min = this._getMinDate();
  3231. return !min || !controlValue || this._dateAdapter.compareDate(min, controlValue) <= 0
  3232. ? null
  3233. : { 'matDatepickerMin': { 'min': min, 'actual': controlValue } };
  3234. };
  3235. /** The form control validator for the max date. */
  3236. _maxValidator = (control) => {
  3237. const controlValue = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(control.value));
  3238. const max = this._getMaxDate();
  3239. return !max || !controlValue || this._dateAdapter.compareDate(max, controlValue) >= 0
  3240. ? null
  3241. : { 'matDatepickerMax': { 'max': max, 'actual': controlValue } };
  3242. };
  3243. /** Gets the base validator functions. */
  3244. _getValidators() {
  3245. return [this._parseValidator, this._minValidator, this._maxValidator, this._filterValidator];
  3246. }
  3247. /** Registers a date selection model with the input. */
  3248. _registerModel(model) {
  3249. this._model = model;
  3250. this._valueChangesSubscription.unsubscribe();
  3251. if (this._pendingValue) {
  3252. this._assignValue(this._pendingValue);
  3253. }
  3254. this._valueChangesSubscription = this._model.selectionChanged.subscribe(event => {
  3255. if (this._shouldHandleChangeEvent(event)) {
  3256. const value = this._getValueFromModel(event.selection);
  3257. this._lastValueValid = this._isValidValue(value);
  3258. this._cvaOnChange(value);
  3259. this._onTouched();
  3260. this._formatValue(value);
  3261. this.dateInput.emit(new MatDatepickerInputEvent(this, this._elementRef.nativeElement));
  3262. this.dateChange.emit(new MatDatepickerInputEvent(this, this._elementRef.nativeElement));
  3263. }
  3264. });
  3265. }
  3266. /** Whether the last value set on the input was valid. */
  3267. _lastValueValid = false;
  3268. constructor() {
  3269. if (typeof ngDevMode === 'undefined' || ngDevMode) {
  3270. if (!this._dateAdapter) {
  3271. throw createMissingDateImplError('DateAdapter');
  3272. }
  3273. if (!this._dateFormats) {
  3274. throw createMissingDateImplError('MAT_DATE_FORMATS');
  3275. }
  3276. }
  3277. // Update the displayed date when the locale changes.
  3278. this._localeSubscription = this._dateAdapter.localeChanges.subscribe(() => {
  3279. this._assignValueProgrammatically(this.value);
  3280. });
  3281. }
  3282. ngAfterViewInit() {
  3283. this._isInitialized = true;
  3284. }
  3285. ngOnChanges(changes) {
  3286. if (dateInputsHaveChanged(changes, this._dateAdapter)) {
  3287. this.stateChanges.next(undefined);
  3288. }
  3289. }
  3290. ngOnDestroy() {
  3291. this._valueChangesSubscription.unsubscribe();
  3292. this._localeSubscription.unsubscribe();
  3293. this.stateChanges.complete();
  3294. }
  3295. /** @docs-private */
  3296. registerOnValidatorChange(fn) {
  3297. this._validatorOnChange = fn;
  3298. }
  3299. /** @docs-private */
  3300. validate(c) {
  3301. return this._validator ? this._validator(c) : null;
  3302. }
  3303. // Implemented as part of ControlValueAccessor.
  3304. writeValue(value) {
  3305. this._assignValueProgrammatically(value);
  3306. }
  3307. // Implemented as part of ControlValueAccessor.
  3308. registerOnChange(fn) {
  3309. this._cvaOnChange = fn;
  3310. }
  3311. // Implemented as part of ControlValueAccessor.
  3312. registerOnTouched(fn) {
  3313. this._onTouched = fn;
  3314. }
  3315. // Implemented as part of ControlValueAccessor.
  3316. setDisabledState(isDisabled) {
  3317. this.disabled = isDisabled;
  3318. }
  3319. _onKeydown(event) {
  3320. const ctrlShiftMetaModifiers = ['ctrlKey', 'shiftKey', 'metaKey'];
  3321. const isAltDownArrow = hasModifierKey(event, 'altKey') &&
  3322. event.keyCode === DOWN_ARROW &&
  3323. ctrlShiftMetaModifiers.every((modifier) => !hasModifierKey(event, modifier));
  3324. if (isAltDownArrow && !this._elementRef.nativeElement.readOnly) {
  3325. this._openPopup();
  3326. event.preventDefault();
  3327. }
  3328. }
  3329. _onInput(value) {
  3330. const lastValueWasValid = this._lastValueValid;
  3331. let date = this._dateAdapter.parse(value, this._dateFormats.parse.dateInput);
  3332. this._lastValueValid = this._isValidValue(date);
  3333. date = this._dateAdapter.getValidDateOrNull(date);
  3334. const hasChanged = !this._dateAdapter.sameDate(date, this.value);
  3335. // We need to fire the CVA change event for all
  3336. // nulls, otherwise the validators won't run.
  3337. if (!date || hasChanged) {
  3338. this._cvaOnChange(date);
  3339. }
  3340. else {
  3341. // Call the CVA change handler for invalid values
  3342. // since this is what marks the control as dirty.
  3343. if (value && !this.value) {
  3344. this._cvaOnChange(date);
  3345. }
  3346. if (lastValueWasValid !== this._lastValueValid) {
  3347. this._validatorOnChange();
  3348. }
  3349. }
  3350. if (hasChanged) {
  3351. this._assignValue(date);
  3352. this.dateInput.emit(new MatDatepickerInputEvent(this, this._elementRef.nativeElement));
  3353. }
  3354. }
  3355. _onChange() {
  3356. this.dateChange.emit(new MatDatepickerInputEvent(this, this._elementRef.nativeElement));
  3357. }
  3358. /** Handles blur events on the input. */
  3359. _onBlur() {
  3360. // Reformat the input only if we have a valid value.
  3361. if (this.value) {
  3362. this._formatValue(this.value);
  3363. }
  3364. this._onTouched();
  3365. }
  3366. /** Formats a value and sets it on the input element. */
  3367. _formatValue(value) {
  3368. this._elementRef.nativeElement.value =
  3369. value != null ? this._dateAdapter.format(value, this._dateFormats.display.dateInput) : '';
  3370. }
  3371. /** Assigns a value to the model. */
  3372. _assignValue(value) {
  3373. // We may get some incoming values before the model was
  3374. // assigned. Save the value so that we can assign it later.
  3375. if (this._model) {
  3376. this._assignValueToModel(value);
  3377. this._pendingValue = null;
  3378. }
  3379. else {
  3380. this._pendingValue = value;
  3381. }
  3382. }
  3383. /** Whether a value is considered valid. */
  3384. _isValidValue(value) {
  3385. return !value || this._dateAdapter.isValid(value);
  3386. }
  3387. /**
  3388. * Checks whether a parent control is disabled. This is in place so that it can be overridden
  3389. * by inputs extending this one which can be placed inside of a group that can be disabled.
  3390. */
  3391. _parentDisabled() {
  3392. return false;
  3393. }
  3394. /** Programmatically assigns a value to the input. */
  3395. _assignValueProgrammatically(value) {
  3396. value = this._dateAdapter.deserialize(value);
  3397. this._lastValueValid = this._isValidValue(value);
  3398. value = this._dateAdapter.getValidDateOrNull(value);
  3399. this._assignValue(value);
  3400. this._formatValue(value);
  3401. }
  3402. /** Gets whether a value matches the current date filter. */
  3403. _matchesFilter(value) {
  3404. const filter = this._getDateFilter();
  3405. return !filter || filter(value);
  3406. }
  3407. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerInputBase, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  3408. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "19.2.6", type: MatDatepickerInputBase, isStandalone: true, inputs: { value: "value", disabled: ["disabled", "disabled", booleanAttribute] }, outputs: { dateChange: "dateChange", dateInput: "dateInput" }, usesOnChanges: true, ngImport: i0 });
  3409. }
  3410. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerInputBase, decorators: [{
  3411. type: Directive
  3412. }], ctorParameters: () => [], propDecorators: { value: [{
  3413. type: Input
  3414. }], disabled: [{
  3415. type: Input,
  3416. args: [{ transform: booleanAttribute }]
  3417. }], dateChange: [{
  3418. type: Output
  3419. }], dateInput: [{
  3420. type: Output
  3421. }] } });
  3422. /**
  3423. * Checks whether the `SimpleChanges` object from an `ngOnChanges`
  3424. * callback has any changes, accounting for date objects.
  3425. */
  3426. function dateInputsHaveChanged(changes, adapter) {
  3427. const keys = Object.keys(changes);
  3428. for (let key of keys) {
  3429. const { previousValue, currentValue } = changes[key];
  3430. if (adapter.isDateInstance(previousValue) && adapter.isDateInstance(currentValue)) {
  3431. if (!adapter.sameDate(previousValue, currentValue)) {
  3432. return true;
  3433. }
  3434. }
  3435. else {
  3436. return true;
  3437. }
  3438. }
  3439. return false;
  3440. }
  3441. /** @docs-private */
  3442. const MAT_DATEPICKER_VALUE_ACCESSOR = {
  3443. provide: NG_VALUE_ACCESSOR,
  3444. useExisting: forwardRef(() => MatDatepickerInput),
  3445. multi: true,
  3446. };
  3447. /** @docs-private */
  3448. const MAT_DATEPICKER_VALIDATORS = {
  3449. provide: NG_VALIDATORS,
  3450. useExisting: forwardRef(() => MatDatepickerInput),
  3451. multi: true,
  3452. };
  3453. /** Directive used to connect an input to a MatDatepicker. */
  3454. class MatDatepickerInput extends MatDatepickerInputBase {
  3455. _formField = inject(MAT_FORM_FIELD, { optional: true });
  3456. _closedSubscription = Subscription.EMPTY;
  3457. _openedSubscription = Subscription.EMPTY;
  3458. /** The datepicker that this input is associated with. */
  3459. set matDatepicker(datepicker) {
  3460. if (datepicker) {
  3461. this._datepicker = datepicker;
  3462. this._ariaOwns.set(datepicker.opened ? datepicker.id : null);
  3463. this._closedSubscription = datepicker.closedStream.subscribe(() => {
  3464. this._onTouched();
  3465. this._ariaOwns.set(null);
  3466. });
  3467. this._openedSubscription = datepicker.openedStream.subscribe(() => {
  3468. this._ariaOwns.set(datepicker.id);
  3469. });
  3470. this._registerModel(datepicker.registerInput(this));
  3471. }
  3472. }
  3473. _datepicker;
  3474. /** The id of the panel owned by this input. */
  3475. _ariaOwns = signal(null);
  3476. /** The minimum valid date. */
  3477. get min() {
  3478. return this._min;
  3479. }
  3480. set min(value) {
  3481. const validValue = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value));
  3482. if (!this._dateAdapter.sameDate(validValue, this._min)) {
  3483. this._min = validValue;
  3484. this._validatorOnChange();
  3485. }
  3486. }
  3487. _min;
  3488. /** The maximum valid date. */
  3489. get max() {
  3490. return this._max;
  3491. }
  3492. set max(value) {
  3493. const validValue = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value));
  3494. if (!this._dateAdapter.sameDate(validValue, this._max)) {
  3495. this._max = validValue;
  3496. this._validatorOnChange();
  3497. }
  3498. }
  3499. _max;
  3500. /** Function that can be used to filter out dates within the datepicker. */
  3501. get dateFilter() {
  3502. return this._dateFilter;
  3503. }
  3504. set dateFilter(value) {
  3505. const wasMatchingValue = this._matchesFilter(this.value);
  3506. this._dateFilter = value;
  3507. if (this._matchesFilter(this.value) !== wasMatchingValue) {
  3508. this._validatorOnChange();
  3509. }
  3510. }
  3511. _dateFilter;
  3512. /** The combined form control validator for this input. */
  3513. _validator;
  3514. constructor() {
  3515. super();
  3516. this._validator = Validators.compose(super._getValidators());
  3517. }
  3518. /**
  3519. * Gets the element that the datepicker popup should be connected to.
  3520. * @return The element to connect the popup to.
  3521. */
  3522. getConnectedOverlayOrigin() {
  3523. return this._formField ? this._formField.getConnectedOverlayOrigin() : this._elementRef;
  3524. }
  3525. /** Gets the ID of an element that should be used a description for the calendar overlay. */
  3526. getOverlayLabelId() {
  3527. if (this._formField) {
  3528. return this._formField.getLabelId();
  3529. }
  3530. return this._elementRef.nativeElement.getAttribute('aria-labelledby');
  3531. }
  3532. /** Returns the palette used by the input's form field, if any. */
  3533. getThemePalette() {
  3534. return this._formField ? this._formField.color : undefined;
  3535. }
  3536. /** Gets the value at which the calendar should start. */
  3537. getStartValue() {
  3538. return this.value;
  3539. }
  3540. ngOnDestroy() {
  3541. super.ngOnDestroy();
  3542. this._closedSubscription.unsubscribe();
  3543. this._openedSubscription.unsubscribe();
  3544. }
  3545. /** Opens the associated datepicker. */
  3546. _openPopup() {
  3547. if (this._datepicker) {
  3548. this._datepicker.open();
  3549. }
  3550. }
  3551. _getValueFromModel(modelValue) {
  3552. return modelValue;
  3553. }
  3554. _assignValueToModel(value) {
  3555. if (this._model) {
  3556. this._model.updateSelection(value, this);
  3557. }
  3558. }
  3559. /** Gets the input's minimum date. */
  3560. _getMinDate() {
  3561. return this._min;
  3562. }
  3563. /** Gets the input's maximum date. */
  3564. _getMaxDate() {
  3565. return this._max;
  3566. }
  3567. /** Gets the input's date filtering function. */
  3568. _getDateFilter() {
  3569. return this._dateFilter;
  3570. }
  3571. _shouldHandleChangeEvent(event) {
  3572. return event.source !== this;
  3573. }
  3574. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerInput, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  3575. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.6", type: MatDatepickerInput, isStandalone: true, selector: "input[matDatepicker]", inputs: { matDatepicker: "matDatepicker", min: "min", max: "max", dateFilter: ["matDatepickerFilter", "dateFilter"] }, host: { listeners: { "input": "_onInput($event.target.value)", "change": "_onChange()", "blur": "_onBlur()", "keydown": "_onKeydown($event)" }, properties: { "attr.aria-haspopup": "_datepicker ? \"dialog\" : null", "attr.aria-owns": "_ariaOwns()", "attr.min": "min ? _dateAdapter.toIso8601(min) : null", "attr.max": "max ? _dateAdapter.toIso8601(max) : null", "attr.data-mat-calendar": "_datepicker ? _datepicker.id : null", "disabled": "disabled" }, classAttribute: "mat-datepicker-input" }, providers: [
  3576. MAT_DATEPICKER_VALUE_ACCESSOR,
  3577. MAT_DATEPICKER_VALIDATORS,
  3578. { provide: MAT_INPUT_VALUE_ACCESSOR, useExisting: MatDatepickerInput },
  3579. ], exportAs: ["matDatepickerInput"], usesInheritance: true, ngImport: i0 });
  3580. }
  3581. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerInput, decorators: [{
  3582. type: Directive,
  3583. args: [{
  3584. selector: 'input[matDatepicker]',
  3585. providers: [
  3586. MAT_DATEPICKER_VALUE_ACCESSOR,
  3587. MAT_DATEPICKER_VALIDATORS,
  3588. { provide: MAT_INPUT_VALUE_ACCESSOR, useExisting: MatDatepickerInput },
  3589. ],
  3590. host: {
  3591. 'class': 'mat-datepicker-input',
  3592. '[attr.aria-haspopup]': '_datepicker ? "dialog" : null',
  3593. '[attr.aria-owns]': '_ariaOwns()',
  3594. '[attr.min]': 'min ? _dateAdapter.toIso8601(min) : null',
  3595. '[attr.max]': 'max ? _dateAdapter.toIso8601(max) : null',
  3596. // Used by the test harness to tie this input to its calendar. We can't depend on
  3597. // `aria-owns` for this, because it's only defined while the calendar is open.
  3598. '[attr.data-mat-calendar]': '_datepicker ? _datepicker.id : null',
  3599. '[disabled]': 'disabled',
  3600. '(input)': '_onInput($event.target.value)',
  3601. '(change)': '_onChange()',
  3602. '(blur)': '_onBlur()',
  3603. '(keydown)': '_onKeydown($event)',
  3604. },
  3605. exportAs: 'matDatepickerInput',
  3606. }]
  3607. }], ctorParameters: () => [], propDecorators: { matDatepicker: [{
  3608. type: Input
  3609. }], min: [{
  3610. type: Input
  3611. }], max: [{
  3612. type: Input
  3613. }], dateFilter: [{
  3614. type: Input,
  3615. args: ['matDatepickerFilter']
  3616. }] } });
  3617. /** Can be used to override the icon of a `matDatepickerToggle`. */
  3618. class MatDatepickerToggleIcon {
  3619. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerToggleIcon, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  3620. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.6", type: MatDatepickerToggleIcon, isStandalone: true, selector: "[matDatepickerToggleIcon]", ngImport: i0 });
  3621. }
  3622. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerToggleIcon, decorators: [{
  3623. type: Directive,
  3624. args: [{
  3625. selector: '[matDatepickerToggleIcon]',
  3626. }]
  3627. }] });
  3628. class MatDatepickerToggle {
  3629. _intl = inject(MatDatepickerIntl);
  3630. _changeDetectorRef = inject(ChangeDetectorRef);
  3631. _stateChanges = Subscription.EMPTY;
  3632. /** Datepicker instance that the button will toggle. */
  3633. datepicker;
  3634. /** Tabindex for the toggle. */
  3635. tabIndex;
  3636. /** Screen-reader label for the button. */
  3637. ariaLabel;
  3638. /** Whether the toggle button is disabled. */
  3639. get disabled() {
  3640. if (this._disabled === undefined && this.datepicker) {
  3641. return this.datepicker.disabled;
  3642. }
  3643. return !!this._disabled;
  3644. }
  3645. set disabled(value) {
  3646. this._disabled = value;
  3647. }
  3648. _disabled;
  3649. /** Whether ripples on the toggle should be disabled. */
  3650. disableRipple;
  3651. /** Custom icon set by the consumer. */
  3652. _customIcon;
  3653. /** Underlying button element. */
  3654. _button;
  3655. constructor() {
  3656. const defaultTabIndex = inject(new HostAttributeToken('tabindex'), { optional: true });
  3657. const parsedTabIndex = Number(defaultTabIndex);
  3658. this.tabIndex = parsedTabIndex || parsedTabIndex === 0 ? parsedTabIndex : null;
  3659. }
  3660. ngOnChanges(changes) {
  3661. if (changes['datepicker']) {
  3662. this._watchStateChanges();
  3663. }
  3664. }
  3665. ngOnDestroy() {
  3666. this._stateChanges.unsubscribe();
  3667. }
  3668. ngAfterContentInit() {
  3669. this._watchStateChanges();
  3670. }
  3671. _open(event) {
  3672. if (this.datepicker && !this.disabled) {
  3673. this.datepicker.open();
  3674. event.stopPropagation();
  3675. }
  3676. }
  3677. _watchStateChanges() {
  3678. const datepickerStateChanged = this.datepicker ? this.datepicker.stateChanges : of();
  3679. const inputStateChanged = this.datepicker && this.datepicker.datepickerInput
  3680. ? this.datepicker.datepickerInput.stateChanges
  3681. : of();
  3682. const datepickerToggled = this.datepicker
  3683. ? merge(this.datepicker.openedStream, this.datepicker.closedStream)
  3684. : of();
  3685. this._stateChanges.unsubscribe();
  3686. this._stateChanges = merge(this._intl.changes, datepickerStateChanged, inputStateChanged, datepickerToggled).subscribe(() => this._changeDetectorRef.markForCheck());
  3687. }
  3688. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerToggle, deps: [], target: i0.ɵɵFactoryTarget.Component });
  3689. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.6", type: MatDatepickerToggle, isStandalone: true, selector: "mat-datepicker-toggle", inputs: { datepicker: ["for", "datepicker"], tabIndex: "tabIndex", ariaLabel: ["aria-label", "ariaLabel"], disabled: ["disabled", "disabled", booleanAttribute], disableRipple: "disableRipple" }, host: { listeners: { "click": "_open($event)" }, properties: { "attr.tabindex": "null", "class.mat-datepicker-toggle-active": "datepicker && datepicker.opened", "class.mat-accent": "datepicker && datepicker.color === \"accent\"", "class.mat-warn": "datepicker && datepicker.color === \"warn\"", "attr.data-mat-calendar": "datepicker ? datepicker.id : null" }, classAttribute: "mat-datepicker-toggle" }, queries: [{ propertyName: "_customIcon", first: true, predicate: MatDatepickerToggleIcon, descendants: true }], viewQueries: [{ propertyName: "_button", first: true, predicate: ["button"], descendants: true }], exportAs: ["matDatepickerToggle"], usesOnChanges: true, ngImport: i0, template: "<button\n #button\n mat-icon-button\n type=\"button\"\n [attr.aria-haspopup]=\"datepicker ? 'dialog' : null\"\n [attr.aria-label]=\"ariaLabel || _intl.openCalendarLabel\"\n [attr.tabindex]=\"disabled ? -1 : tabIndex\"\n [attr.aria-expanded]=\"datepicker ? datepicker.opened : null\"\n [disabled]=\"disabled\"\n [disableRipple]=\"disableRipple\">\n\n @if (!_customIcon) {\n <svg\n class=\"mat-datepicker-toggle-default-icon\"\n viewBox=\"0 0 24 24\"\n width=\"24px\"\n height=\"24px\"\n fill=\"currentColor\"\n focusable=\"false\"\n aria-hidden=\"true\">\n <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\"/>\n </svg>\n }\n\n <ng-content select=\"[matDatepickerToggleIcon]\"></ng-content>\n</button>\n", styles: [".mat-datepicker-toggle{pointer-events:auto;color:var(--mat-datepicker-toggle-icon-color, var(--mat-sys-on-surface-variant))}.mat-datepicker-toggle-active{color:var(--mat-datepicker-toggle-active-state-icon-color, var(--mat-sys-on-surface-variant))}@media(forced-colors: active){.mat-datepicker-toggle-default-icon{color:CanvasText}}\n"], dependencies: [{ kind: "component", type: MatIconButton, selector: "button[mat-icon-button]", exportAs: ["matButton"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
  3690. }
  3691. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerToggle, decorators: [{
  3692. type: Component,
  3693. args: [{ selector: 'mat-datepicker-toggle', host: {
  3694. 'class': 'mat-datepicker-toggle',
  3695. '[attr.tabindex]': 'null',
  3696. '[class.mat-datepicker-toggle-active]': 'datepicker && datepicker.opened',
  3697. '[class.mat-accent]': 'datepicker && datepicker.color === "accent"',
  3698. '[class.mat-warn]': 'datepicker && datepicker.color === "warn"',
  3699. // Used by the test harness to tie this toggle to its datepicker.
  3700. '[attr.data-mat-calendar]': 'datepicker ? datepicker.id : null',
  3701. // Bind the `click` on the host, rather than the inner `button`, so that we can call
  3702. // `stopPropagation` on it without affecting the user's `click` handlers. We need to stop
  3703. // it so that the input doesn't get focused automatically by the form field (See #21836).
  3704. '(click)': '_open($event)',
  3705. }, exportAs: 'matDatepickerToggle', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, imports: [MatIconButton], template: "<button\n #button\n mat-icon-button\n type=\"button\"\n [attr.aria-haspopup]=\"datepicker ? 'dialog' : null\"\n [attr.aria-label]=\"ariaLabel || _intl.openCalendarLabel\"\n [attr.tabindex]=\"disabled ? -1 : tabIndex\"\n [attr.aria-expanded]=\"datepicker ? datepicker.opened : null\"\n [disabled]=\"disabled\"\n [disableRipple]=\"disableRipple\">\n\n @if (!_customIcon) {\n <svg\n class=\"mat-datepicker-toggle-default-icon\"\n viewBox=\"0 0 24 24\"\n width=\"24px\"\n height=\"24px\"\n fill=\"currentColor\"\n focusable=\"false\"\n aria-hidden=\"true\">\n <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\"/>\n </svg>\n }\n\n <ng-content select=\"[matDatepickerToggleIcon]\"></ng-content>\n</button>\n", styles: [".mat-datepicker-toggle{pointer-events:auto;color:var(--mat-datepicker-toggle-icon-color, var(--mat-sys-on-surface-variant))}.mat-datepicker-toggle-active{color:var(--mat-datepicker-toggle-active-state-icon-color, var(--mat-sys-on-surface-variant))}@media(forced-colors: active){.mat-datepicker-toggle-default-icon{color:CanvasText}}\n"] }]
  3706. }], ctorParameters: () => [], propDecorators: { datepicker: [{
  3707. type: Input,
  3708. args: ['for']
  3709. }], tabIndex: [{
  3710. type: Input
  3711. }], ariaLabel: [{
  3712. type: Input,
  3713. args: ['aria-label']
  3714. }], disabled: [{
  3715. type: Input,
  3716. args: [{ transform: booleanAttribute }]
  3717. }], disableRipple: [{
  3718. type: Input
  3719. }], _customIcon: [{
  3720. type: ContentChild,
  3721. args: [MatDatepickerToggleIcon]
  3722. }], _button: [{
  3723. type: ViewChild,
  3724. args: ['button']
  3725. }] } });
  3726. class MatDateRangeInput {
  3727. _changeDetectorRef = inject(ChangeDetectorRef);
  3728. _elementRef = inject(ElementRef);
  3729. _dateAdapter = inject(DateAdapter, { optional: true });
  3730. _formField = inject(MAT_FORM_FIELD, { optional: true });
  3731. _closedSubscription = Subscription.EMPTY;
  3732. _openedSubscription = Subscription.EMPTY;
  3733. _startInput;
  3734. _endInput;
  3735. /** Current value of the range input. */
  3736. get value() {
  3737. return this._model ? this._model.selection : null;
  3738. }
  3739. /** Unique ID for the group. */
  3740. id = inject(_IdGenerator).getId('mat-date-range-input-');
  3741. /** Whether the control is focused. */
  3742. focused = false;
  3743. /** Whether the control's label should float. */
  3744. get shouldLabelFloat() {
  3745. return this.focused || !this.empty;
  3746. }
  3747. /** Name of the form control. */
  3748. controlType = 'mat-date-range-input';
  3749. /**
  3750. * Implemented as a part of `MatFormFieldControl`.
  3751. * Set the placeholder attribute on `matStartDate` and `matEndDate`.
  3752. * @docs-private
  3753. */
  3754. get placeholder() {
  3755. const start = this._startInput?._getPlaceholder() || '';
  3756. const end = this._endInput?._getPlaceholder() || '';
  3757. return start || end ? `${start} ${this.separator} ${end}` : '';
  3758. }
  3759. /** The range picker that this input is associated with. */
  3760. get rangePicker() {
  3761. return this._rangePicker;
  3762. }
  3763. set rangePicker(rangePicker) {
  3764. if (rangePicker) {
  3765. this._model = rangePicker.registerInput(this);
  3766. this._rangePicker = rangePicker;
  3767. this._closedSubscription.unsubscribe();
  3768. this._openedSubscription.unsubscribe();
  3769. this._ariaOwns.set(this.rangePicker.opened ? rangePicker.id : null);
  3770. this._closedSubscription = rangePicker.closedStream.subscribe(() => {
  3771. this._startInput?._onTouched();
  3772. this._endInput?._onTouched();
  3773. this._ariaOwns.set(null);
  3774. });
  3775. this._openedSubscription = rangePicker.openedStream.subscribe(() => {
  3776. this._ariaOwns.set(rangePicker.id);
  3777. });
  3778. this._registerModel(this._model);
  3779. }
  3780. }
  3781. _rangePicker;
  3782. /** The id of the panel owned by this input. */
  3783. _ariaOwns = signal(null);
  3784. /** Whether the input is required. */
  3785. get required() {
  3786. return (this._required ??
  3787. (this._isTargetRequired(this) ||
  3788. this._isTargetRequired(this._startInput) ||
  3789. this._isTargetRequired(this._endInput)) ??
  3790. false);
  3791. }
  3792. set required(value) {
  3793. this._required = value;
  3794. }
  3795. _required;
  3796. /** Function that can be used to filter out dates within the date range picker. */
  3797. get dateFilter() {
  3798. return this._dateFilter;
  3799. }
  3800. set dateFilter(value) {
  3801. const start = this._startInput;
  3802. const end = this._endInput;
  3803. const wasMatchingStart = start && start._matchesFilter(start.value);
  3804. const wasMatchingEnd = end && end._matchesFilter(start.value);
  3805. this._dateFilter = value;
  3806. if (start && start._matchesFilter(start.value) !== wasMatchingStart) {
  3807. start._validatorOnChange();
  3808. }
  3809. if (end && end._matchesFilter(end.value) !== wasMatchingEnd) {
  3810. end._validatorOnChange();
  3811. }
  3812. }
  3813. _dateFilter;
  3814. /** The minimum valid date. */
  3815. get min() {
  3816. return this._min;
  3817. }
  3818. set min(value) {
  3819. const validValue = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value));
  3820. if (!this._dateAdapter.sameDate(validValue, this._min)) {
  3821. this._min = validValue;
  3822. this._revalidate();
  3823. }
  3824. }
  3825. _min;
  3826. /** The maximum valid date. */
  3827. get max() {
  3828. return this._max;
  3829. }
  3830. set max(value) {
  3831. const validValue = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(value));
  3832. if (!this._dateAdapter.sameDate(validValue, this._max)) {
  3833. this._max = validValue;
  3834. this._revalidate();
  3835. }
  3836. }
  3837. _max;
  3838. /** Whether the input is disabled. */
  3839. get disabled() {
  3840. return this._startInput && this._endInput
  3841. ? this._startInput.disabled && this._endInput.disabled
  3842. : this._groupDisabled;
  3843. }
  3844. set disabled(value) {
  3845. if (value !== this._groupDisabled) {
  3846. this._groupDisabled = value;
  3847. this.stateChanges.next(undefined);
  3848. }
  3849. }
  3850. _groupDisabled = false;
  3851. /** Whether the input is in an error state. */
  3852. get errorState() {
  3853. if (this._startInput && this._endInput) {
  3854. return this._startInput.errorState || this._endInput.errorState;
  3855. }
  3856. return false;
  3857. }
  3858. /** Whether the datepicker input is empty. */
  3859. get empty() {
  3860. const startEmpty = this._startInput ? this._startInput.isEmpty() : false;
  3861. const endEmpty = this._endInput ? this._endInput.isEmpty() : false;
  3862. return startEmpty && endEmpty;
  3863. }
  3864. /** Value for the `aria-describedby` attribute of the inputs. */
  3865. _ariaDescribedBy = null;
  3866. /** Date selection model currently registered with the input. */
  3867. _model;
  3868. /** Separator text to be shown between the inputs. */
  3869. separator = '–';
  3870. /** Start of the comparison range that should be shown in the calendar. */
  3871. comparisonStart = null;
  3872. /** End of the comparison range that should be shown in the calendar. */
  3873. comparisonEnd = null;
  3874. /**
  3875. * Implemented as a part of `MatFormFieldControl`.
  3876. * TODO(crisbeto): change type to `AbstractControlDirective` after #18206 lands.
  3877. * @docs-private
  3878. */
  3879. ngControl;
  3880. /** Emits when the input's state has changed. */
  3881. stateChanges = new Subject();
  3882. /**
  3883. * Disable the automatic labeling to avoid issues like #27241.
  3884. * @docs-private
  3885. */
  3886. disableAutomaticLabeling = true;
  3887. constructor() {
  3888. if (!this._dateAdapter && (typeof ngDevMode === 'undefined' || ngDevMode)) {
  3889. throw createMissingDateImplError('DateAdapter');
  3890. }
  3891. // The datepicker module can be used both with MDC and non-MDC form fields. We have
  3892. // to conditionally add the MDC input class so that the range picker looks correctly.
  3893. if (this._formField?._elementRef.nativeElement.classList.contains('mat-mdc-form-field')) {
  3894. this._elementRef.nativeElement.classList.add('mat-mdc-input-element', 'mat-mdc-form-field-input-control', 'mdc-text-field__input');
  3895. }
  3896. // TODO(crisbeto): remove `as any` after #18206 lands.
  3897. this.ngControl = inject(ControlContainer, { optional: true, self: true });
  3898. }
  3899. /**
  3900. * Implemented as a part of `MatFormFieldControl`.
  3901. * @docs-private
  3902. */
  3903. setDescribedByIds(ids) {
  3904. this._ariaDescribedBy = ids.length ? ids.join(' ') : null;
  3905. }
  3906. /**
  3907. * Implemented as a part of `MatFormFieldControl`.
  3908. * @docs-private
  3909. */
  3910. onContainerClick() {
  3911. if (!this.focused && !this.disabled) {
  3912. if (!this._model || !this._model.selection.start) {
  3913. this._startInput.focus();
  3914. }
  3915. else {
  3916. this._endInput.focus();
  3917. }
  3918. }
  3919. }
  3920. ngAfterContentInit() {
  3921. if (typeof ngDevMode === 'undefined' || ngDevMode) {
  3922. if (!this._startInput) {
  3923. throw Error('mat-date-range-input must contain a matStartDate input');
  3924. }
  3925. if (!this._endInput) {
  3926. throw Error('mat-date-range-input must contain a matEndDate input');
  3927. }
  3928. }
  3929. if (this._model) {
  3930. this._registerModel(this._model);
  3931. }
  3932. // We don't need to unsubscribe from this, because we
  3933. // know that the input streams will be completed on destroy.
  3934. merge(this._startInput.stateChanges, this._endInput.stateChanges).subscribe(() => {
  3935. this.stateChanges.next(undefined);
  3936. });
  3937. }
  3938. ngOnChanges(changes) {
  3939. if (dateInputsHaveChanged(changes, this._dateAdapter)) {
  3940. this.stateChanges.next(undefined);
  3941. }
  3942. }
  3943. ngOnDestroy() {
  3944. this._closedSubscription.unsubscribe();
  3945. this._openedSubscription.unsubscribe();
  3946. this.stateChanges.complete();
  3947. }
  3948. /** Gets the date at which the calendar should start. */
  3949. getStartValue() {
  3950. return this.value ? this.value.start : null;
  3951. }
  3952. /** Gets the input's theme palette. */
  3953. getThemePalette() {
  3954. return this._formField ? this._formField.color : undefined;
  3955. }
  3956. /** Gets the element to which the calendar overlay should be attached. */
  3957. getConnectedOverlayOrigin() {
  3958. return this._formField ? this._formField.getConnectedOverlayOrigin() : this._elementRef;
  3959. }
  3960. /** Gets the ID of an element that should be used a description for the calendar overlay. */
  3961. getOverlayLabelId() {
  3962. return this._formField ? this._formField.getLabelId() : null;
  3963. }
  3964. /** Gets the value that is used to mirror the state input. */
  3965. _getInputMirrorValue(part) {
  3966. const input = part === 'start' ? this._startInput : this._endInput;
  3967. return input ? input.getMirrorValue() : '';
  3968. }
  3969. /** Whether the input placeholders should be hidden. */
  3970. _shouldHidePlaceholders() {
  3971. return this._startInput ? !this._startInput.isEmpty() : false;
  3972. }
  3973. /** Handles the value in one of the child inputs changing. */
  3974. _handleChildValueChange() {
  3975. this.stateChanges.next(undefined);
  3976. this._changeDetectorRef.markForCheck();
  3977. }
  3978. /** Opens the date range picker associated with the input. */
  3979. _openDatepicker() {
  3980. if (this._rangePicker) {
  3981. this._rangePicker.open();
  3982. }
  3983. }
  3984. /** Whether the separate text should be hidden. */
  3985. _shouldHideSeparator() {
  3986. return ((!this._formField ||
  3987. (this._formField.getLabelId() && !this._formField._shouldLabelFloat())) &&
  3988. this.empty);
  3989. }
  3990. /** Gets the value for the `aria-labelledby` attribute of the inputs. */
  3991. _getAriaLabelledby() {
  3992. const formField = this._formField;
  3993. return formField && formField._hasFloatingLabel() ? formField._labelId : null;
  3994. }
  3995. _getStartDateAccessibleName() {
  3996. return this._startInput._getAccessibleName();
  3997. }
  3998. _getEndDateAccessibleName() {
  3999. return this._endInput._getAccessibleName();
  4000. }
  4001. /** Updates the focused state of the range input. */
  4002. _updateFocus(origin) {
  4003. this.focused = origin !== null;
  4004. this.stateChanges.next();
  4005. }
  4006. /** Re-runs the validators on the start/end inputs. */
  4007. _revalidate() {
  4008. if (this._startInput) {
  4009. this._startInput._validatorOnChange();
  4010. }
  4011. if (this._endInput) {
  4012. this._endInput._validatorOnChange();
  4013. }
  4014. }
  4015. /** Registers the current date selection model with the start/end inputs. */
  4016. _registerModel(model) {
  4017. if (this._startInput) {
  4018. this._startInput._registerModel(model);
  4019. }
  4020. if (this._endInput) {
  4021. this._endInput._registerModel(model);
  4022. }
  4023. }
  4024. /** Checks whether a specific range input directive is required. */
  4025. _isTargetRequired(target) {
  4026. return target?.ngControl?.control?.hasValidator(Validators.required);
  4027. }
  4028. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDateRangeInput, deps: [], target: i0.ɵɵFactoryTarget.Component });
  4029. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "16.1.0", version: "19.2.6", type: MatDateRangeInput, isStandalone: true, selector: "mat-date-range-input", inputs: { rangePicker: "rangePicker", required: ["required", "required", booleanAttribute], dateFilter: "dateFilter", min: "min", max: "max", disabled: ["disabled", "disabled", booleanAttribute], separator: "separator", comparisonStart: "comparisonStart", comparisonEnd: "comparisonEnd" }, host: { attributes: { "role": "group" }, properties: { "class.mat-date-range-input-hide-placeholders": "_shouldHidePlaceholders()", "class.mat-date-range-input-required": "required", "attr.id": "id", "attr.aria-labelledby": "_getAriaLabelledby()", "attr.aria-describedby": "_ariaDescribedBy", "attr.data-mat-calendar": "rangePicker ? rangePicker.id : null" }, classAttribute: "mat-date-range-input" }, providers: [{ provide: MatFormFieldControl, useExisting: MatDateRangeInput }], exportAs: ["matDateRangeInput"], usesOnChanges: true, ngImport: i0, template: "<div\n class=\"mat-date-range-input-container\"\n cdkMonitorSubtreeFocus\n (cdkFocusChange)=\"_updateFocus($event)\">\n <div class=\"mat-date-range-input-wrapper\">\n <ng-content select=\"input[matStartDate]\"></ng-content>\n <span\n class=\"mat-date-range-input-mirror\"\n aria-hidden=\"true\">{{_getInputMirrorValue('start')}}</span>\n </div>\n\n <span\n class=\"mat-date-range-input-separator\"\n [class.mat-date-range-input-separator-hidden]=\"_shouldHideSeparator()\">{{separator}}</span>\n\n <div class=\"mat-date-range-input-wrapper mat-date-range-input-end-wrapper\">\n <ng-content select=\"input[matEndDate]\"></ng-content>\n <span\n class=\"mat-date-range-input-mirror\"\n aria-hidden=\"true\">{{_getInputMirrorValue('end')}}</span>\n </div>\n</div>\n\n", styles: [".mat-date-range-input{display:block;width:100%}.mat-date-range-input-container{display:flex;align-items:center}.mat-date-range-input-separator{transition:opacity 400ms 133.3333333333ms cubic-bezier(0.25, 0.8, 0.25, 1);margin:0 4px;color:var(--mat-datepicker-range-input-separator-color, var(--mat-sys-on-surface))}.mat-form-field-disabled .mat-date-range-input-separator{color:var(--mat-datepicker-range-input-disabled-state-separator-color, color-mix(in srgb, var(--mat-sys-on-surface) 38%, transparent))}._mat-animation-noopable .mat-date-range-input-separator{transition:none}.mat-date-range-input-separator-hidden{-webkit-user-select:none;user-select:none;opacity:0;transition:none}.mat-date-range-input-wrapper{position:relative;overflow:hidden;max-width:calc(50% - 4px)}.mat-date-range-input-end-wrapper{flex-grow:1}.mat-date-range-input-inner{position:absolute;top:0;left:0;font:inherit;background:rgba(0,0,0,0);color:currentColor;border:none;outline:none;padding:0;margin:0;vertical-align:bottom;text-align:inherit;-webkit-appearance:none;width:100%;height:100%}.mat-date-range-input-inner:-moz-ui-invalid{box-shadow:none}.mat-date-range-input-inner::placeholder{transition:color 400ms 133.3333333333ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-date-range-input-inner::-moz-placeholder{transition:color 400ms 133.3333333333ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-date-range-input-inner::-webkit-input-placeholder{transition:color 400ms 133.3333333333ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-date-range-input-inner:-ms-input-placeholder{transition:color 400ms 133.3333333333ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-date-range-input-inner[disabled]{color:var(--mat-datepicker-range-input-disabled-state-text-color, color-mix(in srgb, var(--mat-sys-on-surface) 38%, transparent))}.mat-form-field-hide-placeholder .mat-date-range-input-inner::placeholder,.mat-date-range-input-hide-placeholders .mat-date-range-input-inner::placeholder{-webkit-user-select:none;user-select:none;color:rgba(0,0,0,0) !important;-webkit-text-fill-color:rgba(0,0,0,0);transition:none}@media(forced-colors: active){.mat-form-field-hide-placeholder .mat-date-range-input-inner::placeholder,.mat-date-range-input-hide-placeholders .mat-date-range-input-inner::placeholder{opacity:0}}.mat-form-field-hide-placeholder .mat-date-range-input-inner::-moz-placeholder,.mat-date-range-input-hide-placeholders .mat-date-range-input-inner::-moz-placeholder{-webkit-user-select:none;user-select:none;color:rgba(0,0,0,0) !important;-webkit-text-fill-color:rgba(0,0,0,0);transition:none}@media(forced-colors: active){.mat-form-field-hide-placeholder .mat-date-range-input-inner::-moz-placeholder,.mat-date-range-input-hide-placeholders .mat-date-range-input-inner::-moz-placeholder{opacity:0}}.mat-form-field-hide-placeholder .mat-date-range-input-inner::-webkit-input-placeholder,.mat-date-range-input-hide-placeholders .mat-date-range-input-inner::-webkit-input-placeholder{-webkit-user-select:none;user-select:none;color:rgba(0,0,0,0) !important;-webkit-text-fill-color:rgba(0,0,0,0);transition:none}@media(forced-colors: active){.mat-form-field-hide-placeholder .mat-date-range-input-inner::-webkit-input-placeholder,.mat-date-range-input-hide-placeholders .mat-date-range-input-inner::-webkit-input-placeholder{opacity:0}}.mat-form-field-hide-placeholder .mat-date-range-input-inner:-ms-input-placeholder,.mat-date-range-input-hide-placeholders .mat-date-range-input-inner:-ms-input-placeholder{-webkit-user-select:none;user-select:none;color:rgba(0,0,0,0) !important;-webkit-text-fill-color:rgba(0,0,0,0);transition:none}@media(forced-colors: active){.mat-form-field-hide-placeholder .mat-date-range-input-inner:-ms-input-placeholder,.mat-date-range-input-hide-placeholders .mat-date-range-input-inner:-ms-input-placeholder{opacity:0}}._mat-animation-noopable .mat-date-range-input-inner::placeholder{transition:none}._mat-animation-noopable .mat-date-range-input-inner::-moz-placeholder{transition:none}._mat-animation-noopable .mat-date-range-input-inner::-webkit-input-placeholder{transition:none}._mat-animation-noopable .mat-date-range-input-inner:-ms-input-placeholder{transition:none}.mat-date-range-input-mirror{-webkit-user-select:none;user-select:none;visibility:hidden;white-space:nowrap;display:inline-block;min-width:2px}.mat-mdc-form-field-type-mat-date-range-input .mat-mdc-form-field-infix{width:200px}\n"], dependencies: [{ kind: "directive", type: CdkMonitorFocus, selector: "[cdkMonitorElementFocus], [cdkMonitorSubtreeFocus]", outputs: ["cdkFocusChange"], exportAs: ["cdkMonitorFocus"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
  4030. }
  4031. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDateRangeInput, decorators: [{
  4032. type: Component,
  4033. args: [{ selector: 'mat-date-range-input', exportAs: 'matDateRangeInput', host: {
  4034. 'class': 'mat-date-range-input',
  4035. '[class.mat-date-range-input-hide-placeholders]': '_shouldHidePlaceholders()',
  4036. '[class.mat-date-range-input-required]': 'required',
  4037. '[attr.id]': 'id',
  4038. 'role': 'group',
  4039. '[attr.aria-labelledby]': '_getAriaLabelledby()',
  4040. '[attr.aria-describedby]': '_ariaDescribedBy',
  4041. // Used by the test harness to tie this input to its calendar. We can't depend on
  4042. // `aria-owns` for this, because it's only defined while the calendar is open.
  4043. '[attr.data-mat-calendar]': 'rangePicker ? rangePicker.id : null',
  4044. }, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, providers: [{ provide: MatFormFieldControl, useExisting: MatDateRangeInput }], imports: [CdkMonitorFocus], template: "<div\n class=\"mat-date-range-input-container\"\n cdkMonitorSubtreeFocus\n (cdkFocusChange)=\"_updateFocus($event)\">\n <div class=\"mat-date-range-input-wrapper\">\n <ng-content select=\"input[matStartDate]\"></ng-content>\n <span\n class=\"mat-date-range-input-mirror\"\n aria-hidden=\"true\">{{_getInputMirrorValue('start')}}</span>\n </div>\n\n <span\n class=\"mat-date-range-input-separator\"\n [class.mat-date-range-input-separator-hidden]=\"_shouldHideSeparator()\">{{separator}}</span>\n\n <div class=\"mat-date-range-input-wrapper mat-date-range-input-end-wrapper\">\n <ng-content select=\"input[matEndDate]\"></ng-content>\n <span\n class=\"mat-date-range-input-mirror\"\n aria-hidden=\"true\">{{_getInputMirrorValue('end')}}</span>\n </div>\n</div>\n\n", styles: [".mat-date-range-input{display:block;width:100%}.mat-date-range-input-container{display:flex;align-items:center}.mat-date-range-input-separator{transition:opacity 400ms 133.3333333333ms cubic-bezier(0.25, 0.8, 0.25, 1);margin:0 4px;color:var(--mat-datepicker-range-input-separator-color, var(--mat-sys-on-surface))}.mat-form-field-disabled .mat-date-range-input-separator{color:var(--mat-datepicker-range-input-disabled-state-separator-color, color-mix(in srgb, var(--mat-sys-on-surface) 38%, transparent))}._mat-animation-noopable .mat-date-range-input-separator{transition:none}.mat-date-range-input-separator-hidden{-webkit-user-select:none;user-select:none;opacity:0;transition:none}.mat-date-range-input-wrapper{position:relative;overflow:hidden;max-width:calc(50% - 4px)}.mat-date-range-input-end-wrapper{flex-grow:1}.mat-date-range-input-inner{position:absolute;top:0;left:0;font:inherit;background:rgba(0,0,0,0);color:currentColor;border:none;outline:none;padding:0;margin:0;vertical-align:bottom;text-align:inherit;-webkit-appearance:none;width:100%;height:100%}.mat-date-range-input-inner:-moz-ui-invalid{box-shadow:none}.mat-date-range-input-inner::placeholder{transition:color 400ms 133.3333333333ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-date-range-input-inner::-moz-placeholder{transition:color 400ms 133.3333333333ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-date-range-input-inner::-webkit-input-placeholder{transition:color 400ms 133.3333333333ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-date-range-input-inner:-ms-input-placeholder{transition:color 400ms 133.3333333333ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-date-range-input-inner[disabled]{color:var(--mat-datepicker-range-input-disabled-state-text-color, color-mix(in srgb, var(--mat-sys-on-surface) 38%, transparent))}.mat-form-field-hide-placeholder .mat-date-range-input-inner::placeholder,.mat-date-range-input-hide-placeholders .mat-date-range-input-inner::placeholder{-webkit-user-select:none;user-select:none;color:rgba(0,0,0,0) !important;-webkit-text-fill-color:rgba(0,0,0,0);transition:none}@media(forced-colors: active){.mat-form-field-hide-placeholder .mat-date-range-input-inner::placeholder,.mat-date-range-input-hide-placeholders .mat-date-range-input-inner::placeholder{opacity:0}}.mat-form-field-hide-placeholder .mat-date-range-input-inner::-moz-placeholder,.mat-date-range-input-hide-placeholders .mat-date-range-input-inner::-moz-placeholder{-webkit-user-select:none;user-select:none;color:rgba(0,0,0,0) !important;-webkit-text-fill-color:rgba(0,0,0,0);transition:none}@media(forced-colors: active){.mat-form-field-hide-placeholder .mat-date-range-input-inner::-moz-placeholder,.mat-date-range-input-hide-placeholders .mat-date-range-input-inner::-moz-placeholder{opacity:0}}.mat-form-field-hide-placeholder .mat-date-range-input-inner::-webkit-input-placeholder,.mat-date-range-input-hide-placeholders .mat-date-range-input-inner::-webkit-input-placeholder{-webkit-user-select:none;user-select:none;color:rgba(0,0,0,0) !important;-webkit-text-fill-color:rgba(0,0,0,0);transition:none}@media(forced-colors: active){.mat-form-field-hide-placeholder .mat-date-range-input-inner::-webkit-input-placeholder,.mat-date-range-input-hide-placeholders .mat-date-range-input-inner::-webkit-input-placeholder{opacity:0}}.mat-form-field-hide-placeholder .mat-date-range-input-inner:-ms-input-placeholder,.mat-date-range-input-hide-placeholders .mat-date-range-input-inner:-ms-input-placeholder{-webkit-user-select:none;user-select:none;color:rgba(0,0,0,0) !important;-webkit-text-fill-color:rgba(0,0,0,0);transition:none}@media(forced-colors: active){.mat-form-field-hide-placeholder .mat-date-range-input-inner:-ms-input-placeholder,.mat-date-range-input-hide-placeholders .mat-date-range-input-inner:-ms-input-placeholder{opacity:0}}._mat-animation-noopable .mat-date-range-input-inner::placeholder{transition:none}._mat-animation-noopable .mat-date-range-input-inner::-moz-placeholder{transition:none}._mat-animation-noopable .mat-date-range-input-inner::-webkit-input-placeholder{transition:none}._mat-animation-noopable .mat-date-range-input-inner:-ms-input-placeholder{transition:none}.mat-date-range-input-mirror{-webkit-user-select:none;user-select:none;visibility:hidden;white-space:nowrap;display:inline-block;min-width:2px}.mat-mdc-form-field-type-mat-date-range-input .mat-mdc-form-field-infix{width:200px}\n"] }]
  4045. }], ctorParameters: () => [], propDecorators: { rangePicker: [{
  4046. type: Input
  4047. }], required: [{
  4048. type: Input,
  4049. args: [{ transform: booleanAttribute }]
  4050. }], dateFilter: [{
  4051. type: Input
  4052. }], min: [{
  4053. type: Input
  4054. }], max: [{
  4055. type: Input
  4056. }], disabled: [{
  4057. type: Input,
  4058. args: [{ transform: booleanAttribute }]
  4059. }], separator: [{
  4060. type: Input
  4061. }], comparisonStart: [{
  4062. type: Input
  4063. }], comparisonEnd: [{
  4064. type: Input
  4065. }] } });
  4066. // This file contains the `_computeAriaAccessibleName` function, which computes what the *expected*
  4067. // ARIA accessible name would be for a given element. Implements a subset of ARIA specification
  4068. // [Accessible Name and Description Computation 1.2](https://www.w3.org/TR/accname-1.2/).
  4069. //
  4070. // Specification accname-1.2 can be summarized by returning the result of the first method
  4071. // available.
  4072. //
  4073. // 1. `aria-labelledby` attribute
  4074. // ```
  4075. // <!-- example using aria-labelledby-->
  4076. // <label id='label-id'>Start Date</label>
  4077. // <input aria-labelledby='label-id'/>
  4078. // ```
  4079. // 2. `aria-label` attribute (e.g. `<input aria-label="Departure"/>`)
  4080. // 3. Label with `for`/`id`
  4081. // ```
  4082. // <!-- example using for/id -->
  4083. // <label for="current-node">Label</label>
  4084. // <input id="current-node"/>
  4085. // ```
  4086. // 4. `placeholder` attribute (e.g. `<input placeholder="06/03/1990"/>`)
  4087. // 5. `title` attribute (e.g. `<input title="Check-In"/>`)
  4088. // 6. text content
  4089. // ```
  4090. // <!-- example using text content -->
  4091. // <label for="current-node"><span>Departure</span> Date</label>
  4092. // <input id="current-node"/>
  4093. // ```
  4094. /**
  4095. * Computes the *expected* ARIA accessible name for argument element based on [accname-1.2
  4096. * specification](https://www.w3.org/TR/accname-1.2/). Implements a subset of accname-1.2,
  4097. * and should only be used for the Datepicker's specific use case.
  4098. *
  4099. * Intended use:
  4100. * This is not a general use implementation. Only implements the parts of accname-1.2 that are
  4101. * required for the Datepicker's specific use case. This function is not intended for any other
  4102. * use.
  4103. *
  4104. * Limitations:
  4105. * - Only covers the needs of `matStartDate` and `matEndDate`. Does not support other use cases.
  4106. * - See NOTES's in implementation for specific details on what parts of the accname-1.2
  4107. * specification are not implemented.
  4108. *
  4109. * @param element {HTMLInputElement} native &lt;input/&gt; element of `matStartDate` or
  4110. * `matEndDate` component. Corresponds to the 'Root Element' from accname-1.2
  4111. *
  4112. * @return expected ARIA accessible name of argument &lt;input/&gt;
  4113. */
  4114. function _computeAriaAccessibleName(element) {
  4115. return _computeAriaAccessibleNameInternal(element, true);
  4116. }
  4117. /**
  4118. * Determine if argument node is an Element based on `nodeType` property. This function is safe to
  4119. * use with server-side rendering.
  4120. */
  4121. function ssrSafeIsElement(node) {
  4122. return node.nodeType === Node.ELEMENT_NODE;
  4123. }
  4124. /**
  4125. * Determine if argument node is an HTMLInputElement based on `nodeName` property. This funciton is
  4126. * safe to use with server-side rendering.
  4127. */
  4128. function ssrSafeIsHTMLInputElement(node) {
  4129. return node.nodeName === 'INPUT';
  4130. }
  4131. /**
  4132. * Determine if argument node is an HTMLTextAreaElement based on `nodeName` property. This
  4133. * funciton is safe to use with server-side rendering.
  4134. */
  4135. function ssrSafeIsHTMLTextAreaElement(node) {
  4136. return node.nodeName === 'TEXTAREA';
  4137. }
  4138. /**
  4139. * Calculate the expected ARIA accessible name for given DOM Node. Given DOM Node may be either the
  4140. * "Root node" passed to `_computeAriaAccessibleName` or "Current node" as result of recursion.
  4141. *
  4142. * @return the accessible name of argument DOM Node
  4143. *
  4144. * @param currentNode node to determine accessible name of
  4145. * @param isDirectlyReferenced true if `currentNode` is the root node to calculate ARIA accessible
  4146. * name of. False if it is a result of recursion.
  4147. */
  4148. function _computeAriaAccessibleNameInternal(currentNode, isDirectlyReferenced) {
  4149. // NOTE: this differs from accname-1.2 specification.
  4150. // - Does not implement Step 1. of accname-1.2: '''If `currentNode`'s role prohibits naming,
  4151. // return the empty string ("")'''.
  4152. // - Does not implement Step 2.A. of accname-1.2: '''if current node is hidden and not directly
  4153. // referenced by aria-labelledby... return the empty string.'''
  4154. // acc-name-1.2 Step 2.B.: aria-labelledby
  4155. if (ssrSafeIsElement(currentNode) && isDirectlyReferenced) {
  4156. const labelledbyIds = currentNode.getAttribute?.('aria-labelledby')?.split(/\s+/g) || [];
  4157. const validIdRefs = labelledbyIds.reduce((validIds, id) => {
  4158. const elem = document.getElementById(id);
  4159. if (elem) {
  4160. validIds.push(elem);
  4161. }
  4162. return validIds;
  4163. }, []);
  4164. if (validIdRefs.length) {
  4165. return validIdRefs
  4166. .map(idRef => {
  4167. return _computeAriaAccessibleNameInternal(idRef, false);
  4168. })
  4169. .join(' ');
  4170. }
  4171. }
  4172. // acc-name-1.2 Step 2.C.: aria-label
  4173. if (ssrSafeIsElement(currentNode)) {
  4174. const ariaLabel = currentNode.getAttribute('aria-label')?.trim();
  4175. if (ariaLabel) {
  4176. return ariaLabel;
  4177. }
  4178. }
  4179. // acc-name-1.2 Step 2.D. attribute or element that defines a text alternative
  4180. //
  4181. // NOTE: this differs from accname-1.2 specification.
  4182. // Only implements Step 2.D. for `<label>`,`<input/>`, and `<textarea/>` element. Does not
  4183. // implement other elements that have an attribute or element that defines a text alternative.
  4184. if (ssrSafeIsHTMLInputElement(currentNode) || ssrSafeIsHTMLTextAreaElement(currentNode)) {
  4185. // use label with a `for` attribute referencing the current node
  4186. if (currentNode.labels?.length) {
  4187. return Array.from(currentNode.labels)
  4188. .map(x => _computeAriaAccessibleNameInternal(x, false))
  4189. .join(' ');
  4190. }
  4191. // use placeholder if available
  4192. const placeholder = currentNode.getAttribute('placeholder')?.trim();
  4193. if (placeholder) {
  4194. return placeholder;
  4195. }
  4196. // use title if available
  4197. const title = currentNode.getAttribute('title')?.trim();
  4198. if (title) {
  4199. return title;
  4200. }
  4201. }
  4202. // NOTE: this differs from accname-1.2 specification.
  4203. // - does not implement acc-name-1.2 Step 2.E.: '''if the current node is a control embedded
  4204. // within the label... then include the embedded control as part of the text alternative in
  4205. // the following manner...'''. Step 2E applies to embedded controls such as textbox, listbox,
  4206. // range, etc.
  4207. // - does not implement acc-name-1.2 step 2.F.: check that '''role allows name from content''',
  4208. // which applies to `currentNode` and its children.
  4209. // - does not implement acc-name-1.2 Step 2.F.ii.: '''Check for CSS generated textual content'''
  4210. // (e.g. :before and :after).
  4211. // - does not implement acc-name-1.2 Step 2.I.: '''if the current node has a Tooltip attribute,
  4212. // return its value'''
  4213. // Return text content with whitespace collapsed into a single space character. Accomplish
  4214. // acc-name-1.2 steps 2F, 2G, and 2H.
  4215. return (currentNode.textContent || '').replace(/\s+/g, ' ').trim();
  4216. }
  4217. /**
  4218. * Base class for the individual inputs that can be projected inside a `mat-date-range-input`.
  4219. */
  4220. class MatDateRangeInputPartBase extends MatDatepickerInputBase {
  4221. _rangeInput = inject(MatDateRangeInput);
  4222. _elementRef = inject(ElementRef);
  4223. _defaultErrorStateMatcher = inject(ErrorStateMatcher);
  4224. _injector = inject(Injector);
  4225. _parentForm = inject(NgForm, { optional: true });
  4226. _parentFormGroup = inject(FormGroupDirective, { optional: true });
  4227. /**
  4228. * Form control bound to this input part.
  4229. * @docs-private
  4230. */
  4231. ngControl;
  4232. _dir = inject(Directionality, { optional: true });
  4233. _errorStateTracker;
  4234. /** Object used to control when error messages are shown. */
  4235. get errorStateMatcher() {
  4236. return this._errorStateTracker.matcher;
  4237. }
  4238. set errorStateMatcher(value) {
  4239. this._errorStateTracker.matcher = value;
  4240. }
  4241. /** Whether the input is in an error state. */
  4242. get errorState() {
  4243. return this._errorStateTracker.errorState;
  4244. }
  4245. set errorState(value) {
  4246. this._errorStateTracker.errorState = value;
  4247. }
  4248. constructor() {
  4249. super();
  4250. this._errorStateTracker = new _ErrorStateTracker(this._defaultErrorStateMatcher, null, this._parentFormGroup, this._parentForm, this.stateChanges);
  4251. }
  4252. ngOnInit() {
  4253. // We need the date input to provide itself as a `ControlValueAccessor` and a `Validator`, while
  4254. // injecting its `NgControl` so that the error state is handled correctly. This introduces a
  4255. // circular dependency, because both `ControlValueAccessor` and `Validator` depend on the input
  4256. // itself. Usually we can work around it for the CVA, but there's no API to do it for the
  4257. // validator. We work around it here by injecting the `NgControl` in `ngOnInit`, after
  4258. // everything has been resolved.
  4259. const ngControl = this._injector.get(NgControl, null, { optional: true, self: true });
  4260. if (ngControl) {
  4261. this.ngControl = ngControl;
  4262. this._errorStateTracker.ngControl = ngControl;
  4263. }
  4264. }
  4265. ngAfterContentInit() {
  4266. this._register();
  4267. }
  4268. ngDoCheck() {
  4269. if (this.ngControl) {
  4270. // We need to re-evaluate this on every change detection cycle, because there are some
  4271. // error triggers that we can't subscribe to (e.g. parent form submissions). This means
  4272. // that whatever logic is in here has to be super lean or we risk destroying the performance.
  4273. this.updateErrorState();
  4274. }
  4275. }
  4276. /** Gets whether the input is empty. */
  4277. isEmpty() {
  4278. return this._elementRef.nativeElement.value.length === 0;
  4279. }
  4280. /** Gets the placeholder of the input. */
  4281. _getPlaceholder() {
  4282. return this._elementRef.nativeElement.placeholder;
  4283. }
  4284. /** Focuses the input. */
  4285. focus() {
  4286. this._elementRef.nativeElement.focus();
  4287. }
  4288. /** Gets the value that should be used when mirroring the input's size. */
  4289. getMirrorValue() {
  4290. const element = this._elementRef.nativeElement;
  4291. const value = element.value;
  4292. return value.length > 0 ? value : element.placeholder;
  4293. }
  4294. /** Refreshes the error state of the input. */
  4295. updateErrorState() {
  4296. this._errorStateTracker.updateErrorState();
  4297. }
  4298. /** Handles `input` events on the input element. */
  4299. _onInput(value) {
  4300. super._onInput(value);
  4301. this._rangeInput._handleChildValueChange();
  4302. }
  4303. /** Opens the datepicker associated with the input. */
  4304. _openPopup() {
  4305. this._rangeInput._openDatepicker();
  4306. }
  4307. /** Gets the minimum date from the range input. */
  4308. _getMinDate() {
  4309. return this._rangeInput.min;
  4310. }
  4311. /** Gets the maximum date from the range input. */
  4312. _getMaxDate() {
  4313. return this._rangeInput.max;
  4314. }
  4315. /** Gets the date filter function from the range input. */
  4316. _getDateFilter() {
  4317. return this._rangeInput.dateFilter;
  4318. }
  4319. _parentDisabled() {
  4320. return this._rangeInput._groupDisabled;
  4321. }
  4322. _shouldHandleChangeEvent({ source }) {
  4323. return source !== this._rangeInput._startInput && source !== this._rangeInput._endInput;
  4324. }
  4325. _assignValueProgrammatically(value) {
  4326. super._assignValueProgrammatically(value);
  4327. const opposite = (this === this._rangeInput._startInput
  4328. ? this._rangeInput._endInput
  4329. : this._rangeInput._startInput);
  4330. opposite?._validatorOnChange();
  4331. }
  4332. _formatValue(value) {
  4333. super._formatValue(value);
  4334. // Any time the input value is reformatted we need to tell the parent.
  4335. this._rangeInput._handleChildValueChange();
  4336. }
  4337. /** return the ARIA accessible name of the input element */
  4338. _getAccessibleName() {
  4339. return _computeAriaAccessibleName(this._elementRef.nativeElement);
  4340. }
  4341. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDateRangeInputPartBase, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  4342. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.6", type: MatDateRangeInputPartBase, isStandalone: true, inputs: { errorStateMatcher: "errorStateMatcher" }, usesInheritance: true, ngImport: i0 });
  4343. }
  4344. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDateRangeInputPartBase, decorators: [{
  4345. type: Directive
  4346. }], ctorParameters: () => [], propDecorators: { errorStateMatcher: [{
  4347. type: Input
  4348. }] } });
  4349. /** Input for entering the start date in a `mat-date-range-input`. */
  4350. class MatStartDate extends MatDateRangeInputPartBase {
  4351. /** Validator that checks that the start date isn't after the end date. */
  4352. _startValidator = (control) => {
  4353. const start = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(control.value));
  4354. const end = this._model ? this._model.selection.end : null;
  4355. return !start || !end || this._dateAdapter.compareDate(start, end) <= 0
  4356. ? null
  4357. : { 'matStartDateInvalid': { 'end': end, 'actual': start } };
  4358. };
  4359. _validator = Validators.compose([...super._getValidators(), this._startValidator]);
  4360. _register() {
  4361. this._rangeInput._startInput = this;
  4362. }
  4363. _getValueFromModel(modelValue) {
  4364. return modelValue.start;
  4365. }
  4366. _shouldHandleChangeEvent(change) {
  4367. if (!super._shouldHandleChangeEvent(change)) {
  4368. return false;
  4369. }
  4370. else {
  4371. return !change.oldValue?.start
  4372. ? !!change.selection.start
  4373. : !change.selection.start ||
  4374. !!this._dateAdapter.compareDate(change.oldValue.start, change.selection.start);
  4375. }
  4376. }
  4377. _assignValueToModel(value) {
  4378. if (this._model) {
  4379. const range = new DateRange(value, this._model.selection.end);
  4380. this._model.updateSelection(range, this);
  4381. this._rangeInput._handleChildValueChange();
  4382. }
  4383. }
  4384. _onKeydown(event) {
  4385. const endInput = this._rangeInput._endInput;
  4386. const element = this._elementRef.nativeElement;
  4387. const isLtr = this._dir?.value !== 'rtl';
  4388. // If the user hits RIGHT (LTR) when at the end of the input (and no
  4389. // selection), move the cursor to the start of the end input.
  4390. if (((event.keyCode === RIGHT_ARROW && isLtr) || (event.keyCode === LEFT_ARROW && !isLtr)) &&
  4391. element.selectionStart === element.value.length &&
  4392. element.selectionEnd === element.value.length) {
  4393. event.preventDefault();
  4394. endInput._elementRef.nativeElement.setSelectionRange(0, 0);
  4395. endInput.focus();
  4396. }
  4397. else {
  4398. super._onKeydown(event);
  4399. }
  4400. }
  4401. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatStartDate, deps: null, target: i0.ɵɵFactoryTarget.Directive });
  4402. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.6", type: MatStartDate, isStandalone: true, selector: "input[matStartDate]", outputs: { dateChange: "dateChange", dateInput: "dateInput" }, host: { attributes: { "type": "text" }, listeners: { "input": "_onInput($event.target.value)", "change": "_onChange()", "keydown": "_onKeydown($event)", "blur": "_onBlur()" }, properties: { "disabled": "disabled", "attr.aria-haspopup": "_rangeInput.rangePicker ? \"dialog\" : null", "attr.aria-owns": "_rangeInput._ariaOwns\n ? _rangeInput._ariaOwns()\n : (_rangeInput.rangePicker?.opened && _rangeInput.rangePicker.id) || null", "attr.min": "_getMinDate() ? _dateAdapter.toIso8601(_getMinDate()) : null", "attr.max": "_getMaxDate() ? _dateAdapter.toIso8601(_getMaxDate()) : null" }, classAttribute: "mat-start-date mat-date-range-input-inner" }, providers: [
  4403. { provide: NG_VALUE_ACCESSOR, useExisting: MatStartDate, multi: true },
  4404. { provide: NG_VALIDATORS, useExisting: MatStartDate, multi: true },
  4405. ], usesInheritance: true, ngImport: i0 });
  4406. }
  4407. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatStartDate, decorators: [{
  4408. type: Directive,
  4409. args: [{
  4410. selector: 'input[matStartDate]',
  4411. host: {
  4412. 'class': 'mat-start-date mat-date-range-input-inner',
  4413. '[disabled]': 'disabled',
  4414. '(input)': '_onInput($event.target.value)',
  4415. '(change)': '_onChange()',
  4416. '(keydown)': '_onKeydown($event)',
  4417. '[attr.aria-haspopup]': '_rangeInput.rangePicker ? "dialog" : null',
  4418. '[attr.aria-owns]': `_rangeInput._ariaOwns
  4419. ? _rangeInput._ariaOwns()
  4420. : (_rangeInput.rangePicker?.opened && _rangeInput.rangePicker.id) || null`,
  4421. '[attr.min]': '_getMinDate() ? _dateAdapter.toIso8601(_getMinDate()) : null',
  4422. '[attr.max]': '_getMaxDate() ? _dateAdapter.toIso8601(_getMaxDate()) : null',
  4423. '(blur)': '_onBlur()',
  4424. 'type': 'text',
  4425. },
  4426. providers: [
  4427. { provide: NG_VALUE_ACCESSOR, useExisting: MatStartDate, multi: true },
  4428. { provide: NG_VALIDATORS, useExisting: MatStartDate, multi: true },
  4429. ],
  4430. // These need to be specified explicitly, because some tooling doesn't
  4431. // seem to pick them up from the base class. See #20932.
  4432. outputs: ['dateChange', 'dateInput'],
  4433. }]
  4434. }] });
  4435. /** Input for entering the end date in a `mat-date-range-input`. */
  4436. class MatEndDate extends MatDateRangeInputPartBase {
  4437. /** Validator that checks that the end date isn't before the start date. */
  4438. _endValidator = (control) => {
  4439. const end = this._dateAdapter.getValidDateOrNull(this._dateAdapter.deserialize(control.value));
  4440. const start = this._model ? this._model.selection.start : null;
  4441. return !end || !start || this._dateAdapter.compareDate(end, start) >= 0
  4442. ? null
  4443. : { 'matEndDateInvalid': { 'start': start, 'actual': end } };
  4444. };
  4445. _register() {
  4446. this._rangeInput._endInput = this;
  4447. }
  4448. _validator = Validators.compose([...super._getValidators(), this._endValidator]);
  4449. _getValueFromModel(modelValue) {
  4450. return modelValue.end;
  4451. }
  4452. _shouldHandleChangeEvent(change) {
  4453. if (!super._shouldHandleChangeEvent(change)) {
  4454. return false;
  4455. }
  4456. else {
  4457. return !change.oldValue?.end
  4458. ? !!change.selection.end
  4459. : !change.selection.end ||
  4460. !!this._dateAdapter.compareDate(change.oldValue.end, change.selection.end);
  4461. }
  4462. }
  4463. _assignValueToModel(value) {
  4464. if (this._model) {
  4465. const range = new DateRange(this._model.selection.start, value);
  4466. this._model.updateSelection(range, this);
  4467. }
  4468. }
  4469. _moveCaretToEndOfStartInput() {
  4470. const startInput = this._rangeInput._startInput._elementRef.nativeElement;
  4471. const value = startInput.value;
  4472. if (value.length > 0) {
  4473. startInput.setSelectionRange(value.length, value.length);
  4474. }
  4475. startInput.focus();
  4476. }
  4477. _onKeydown(event) {
  4478. const element = this._elementRef.nativeElement;
  4479. const isLtr = this._dir?.value !== 'rtl';
  4480. // If the user is pressing backspace on an empty end input, move focus back to the start.
  4481. if (event.keyCode === BACKSPACE && !element.value) {
  4482. this._moveCaretToEndOfStartInput();
  4483. }
  4484. // If the user hits LEFT (LTR) when at the start of the input (and no
  4485. // selection), move the cursor to the end of the start input.
  4486. else if (((event.keyCode === LEFT_ARROW && isLtr) || (event.keyCode === RIGHT_ARROW && !isLtr)) &&
  4487. element.selectionStart === 0 &&
  4488. element.selectionEnd === 0) {
  4489. event.preventDefault();
  4490. this._moveCaretToEndOfStartInput();
  4491. }
  4492. else {
  4493. super._onKeydown(event);
  4494. }
  4495. }
  4496. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatEndDate, deps: null, target: i0.ɵɵFactoryTarget.Directive });
  4497. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.6", type: MatEndDate, isStandalone: true, selector: "input[matEndDate]", outputs: { dateChange: "dateChange", dateInput: "dateInput" }, host: { attributes: { "type": "text" }, listeners: { "input": "_onInput($event.target.value)", "change": "_onChange()", "keydown": "_onKeydown($event)", "blur": "_onBlur()" }, properties: { "disabled": "disabled", "attr.aria-haspopup": "_rangeInput.rangePicker ? \"dialog\" : null", "attr.aria-owns": "_rangeInput._ariaOwns\n ? _rangeInput._ariaOwns()\n : (_rangeInput.rangePicker?.opened && _rangeInput.rangePicker.id) || null", "attr.min": "_getMinDate() ? _dateAdapter.toIso8601(_getMinDate()) : null", "attr.max": "_getMaxDate() ? _dateAdapter.toIso8601(_getMaxDate()) : null" }, classAttribute: "mat-end-date mat-date-range-input-inner" }, providers: [
  4498. { provide: NG_VALUE_ACCESSOR, useExisting: MatEndDate, multi: true },
  4499. { provide: NG_VALIDATORS, useExisting: MatEndDate, multi: true },
  4500. ], usesInheritance: true, ngImport: i0 });
  4501. }
  4502. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatEndDate, decorators: [{
  4503. type: Directive,
  4504. args: [{
  4505. selector: 'input[matEndDate]',
  4506. host: {
  4507. 'class': 'mat-end-date mat-date-range-input-inner',
  4508. '[disabled]': 'disabled',
  4509. '(input)': '_onInput($event.target.value)',
  4510. '(change)': '_onChange()',
  4511. '(keydown)': '_onKeydown($event)',
  4512. '[attr.aria-haspopup]': '_rangeInput.rangePicker ? "dialog" : null',
  4513. '[attr.aria-owns]': `_rangeInput._ariaOwns
  4514. ? _rangeInput._ariaOwns()
  4515. : (_rangeInput.rangePicker?.opened && _rangeInput.rangePicker.id) || null`,
  4516. '[attr.min]': '_getMinDate() ? _dateAdapter.toIso8601(_getMinDate()) : null',
  4517. '[attr.max]': '_getMaxDate() ? _dateAdapter.toIso8601(_getMaxDate()) : null',
  4518. '(blur)': '_onBlur()',
  4519. 'type': 'text',
  4520. },
  4521. providers: [
  4522. { provide: NG_VALUE_ACCESSOR, useExisting: MatEndDate, multi: true },
  4523. { provide: NG_VALIDATORS, useExisting: MatEndDate, multi: true },
  4524. ],
  4525. // These need to be specified explicitly, because some tooling doesn't
  4526. // seem to pick them up from the base class. See #20932.
  4527. outputs: ['dateChange', 'dateInput'],
  4528. }]
  4529. }] });
  4530. // TODO(mmalerba): We use a component instead of a directive here so the user can use implicit
  4531. // template reference variables (e.g. #d vs #d="matDateRangePicker"). We can change this to a
  4532. // directive if angular adds support for `exportAs: '$implicit'` on directives.
  4533. /** Component responsible for managing the date range picker popup/dialog. */
  4534. class MatDateRangePicker extends MatDatepickerBase {
  4535. _forwardContentValues(instance) {
  4536. super._forwardContentValues(instance);
  4537. const input = this.datepickerInput;
  4538. if (input) {
  4539. instance.comparisonStart = input.comparisonStart;
  4540. instance.comparisonEnd = input.comparisonEnd;
  4541. instance.startDateAccessibleName = input._getStartDateAccessibleName();
  4542. instance.endDateAccessibleName = input._getEndDateAccessibleName();
  4543. }
  4544. }
  4545. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDateRangePicker, deps: null, target: i0.ɵɵFactoryTarget.Component });
  4546. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.6", type: MatDateRangePicker, isStandalone: true, selector: "mat-date-range-picker", providers: [
  4547. MAT_RANGE_DATE_SELECTION_MODEL_PROVIDER,
  4548. MAT_CALENDAR_RANGE_STRATEGY_PROVIDER,
  4549. { provide: MatDatepickerBase, useExisting: MatDateRangePicker },
  4550. ], exportAs: ["matDateRangePicker"], usesInheritance: true, ngImport: i0, template: '', isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
  4551. }
  4552. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDateRangePicker, decorators: [{
  4553. type: Component,
  4554. args: [{
  4555. selector: 'mat-date-range-picker',
  4556. template: '',
  4557. exportAs: 'matDateRangePicker',
  4558. changeDetection: ChangeDetectionStrategy.OnPush,
  4559. encapsulation: ViewEncapsulation.None,
  4560. providers: [
  4561. MAT_RANGE_DATE_SELECTION_MODEL_PROVIDER,
  4562. MAT_CALENDAR_RANGE_STRATEGY_PROVIDER,
  4563. { provide: MatDatepickerBase, useExisting: MatDateRangePicker },
  4564. ],
  4565. }]
  4566. }] });
  4567. /** Button that will close the datepicker and assign the current selection to the data model. */
  4568. class MatDatepickerApply {
  4569. _datepicker = inject(MatDatepickerBase);
  4570. constructor() { }
  4571. _applySelection() {
  4572. this._datepicker._applyPendingSelection();
  4573. this._datepicker.close();
  4574. }
  4575. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerApply, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  4576. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.6", type: MatDatepickerApply, isStandalone: true, selector: "[matDatepickerApply], [matDateRangePickerApply]", host: { listeners: { "click": "_applySelection()" } }, ngImport: i0 });
  4577. }
  4578. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerApply, decorators: [{
  4579. type: Directive,
  4580. args: [{
  4581. selector: '[matDatepickerApply], [matDateRangePickerApply]',
  4582. host: { '(click)': '_applySelection()' },
  4583. }]
  4584. }], ctorParameters: () => [] });
  4585. /** Button that will close the datepicker and discard the current selection. */
  4586. class MatDatepickerCancel {
  4587. _datepicker = inject(MatDatepickerBase);
  4588. constructor() { }
  4589. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerCancel, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  4590. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.6", type: MatDatepickerCancel, isStandalone: true, selector: "[matDatepickerCancel], [matDateRangePickerCancel]", host: { listeners: { "click": "_datepicker.close()" } }, ngImport: i0 });
  4591. }
  4592. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerCancel, decorators: [{
  4593. type: Directive,
  4594. args: [{
  4595. selector: '[matDatepickerCancel], [matDateRangePickerCancel]',
  4596. host: { '(click)': '_datepicker.close()' },
  4597. }]
  4598. }], ctorParameters: () => [] });
  4599. /**
  4600. * Container that can be used to project a row of action buttons
  4601. * to the bottom of a datepicker or date range picker.
  4602. */
  4603. class MatDatepickerActions {
  4604. _datepicker = inject(MatDatepickerBase);
  4605. _viewContainerRef = inject(ViewContainerRef);
  4606. _template;
  4607. _portal;
  4608. constructor() { }
  4609. ngAfterViewInit() {
  4610. this._portal = new TemplatePortal(this._template, this._viewContainerRef);
  4611. this._datepicker.registerActions(this._portal);
  4612. }
  4613. ngOnDestroy() {
  4614. this._datepicker.removeActions(this._portal);
  4615. // Needs to be null checked since we initialize it in `ngAfterViewInit`.
  4616. if (this._portal && this._portal.isAttached) {
  4617. this._portal?.detach();
  4618. }
  4619. }
  4620. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerActions, deps: [], target: i0.ɵɵFactoryTarget.Component });
  4621. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.6", type: MatDatepickerActions, isStandalone: true, selector: "mat-datepicker-actions, mat-date-range-picker-actions", viewQueries: [{ propertyName: "_template", first: true, predicate: TemplateRef, descendants: true }], ngImport: i0, template: `
  4622. <ng-template>
  4623. <div class="mat-datepicker-actions">
  4624. <ng-content></ng-content>
  4625. </div>
  4626. </ng-template>
  4627. `, isInline: true, styles: [".mat-datepicker-actions{display:flex;justify-content:flex-end;align-items:center;padding:0 8px 8px 8px}.mat-datepicker-actions .mat-mdc-button-base+.mat-mdc-button-base{margin-left:8px}[dir=rtl] .mat-datepicker-actions .mat-mdc-button-base+.mat-mdc-button-base{margin-left:0;margin-right:8px}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
  4628. }
  4629. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerActions, decorators: [{
  4630. type: Component,
  4631. args: [{ selector: 'mat-datepicker-actions, mat-date-range-picker-actions', template: `
  4632. <ng-template>
  4633. <div class="mat-datepicker-actions">
  4634. <ng-content></ng-content>
  4635. </div>
  4636. </ng-template>
  4637. `, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, styles: [".mat-datepicker-actions{display:flex;justify-content:flex-end;align-items:center;padding:0 8px 8px 8px}.mat-datepicker-actions .mat-mdc-button-base+.mat-mdc-button-base{margin-left:8px}[dir=rtl] .mat-datepicker-actions .mat-mdc-button-base+.mat-mdc-button-base{margin-left:0;margin-right:8px}\n"] }]
  4638. }], ctorParameters: () => [], propDecorators: { _template: [{
  4639. type: ViewChild,
  4640. args: [TemplateRef]
  4641. }] } });
  4642. class MatDatepickerModule {
  4643. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
  4644. static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerModule, imports: [MatButtonModule,
  4645. OverlayModule,
  4646. A11yModule,
  4647. PortalModule,
  4648. MatCommonModule,
  4649. MatCalendar,
  4650. MatCalendarBody,
  4651. MatDatepicker,
  4652. MatDatepickerContent,
  4653. MatDatepickerInput,
  4654. MatDatepickerToggle,
  4655. MatDatepickerToggleIcon,
  4656. MatMonthView,
  4657. MatYearView,
  4658. MatMultiYearView,
  4659. MatCalendarHeader,
  4660. MatDateRangeInput,
  4661. MatStartDate,
  4662. MatEndDate,
  4663. MatDateRangePicker,
  4664. MatDatepickerActions,
  4665. MatDatepickerCancel,
  4666. MatDatepickerApply], exports: [CdkScrollableModule,
  4667. MatCalendar,
  4668. MatCalendarBody,
  4669. MatDatepicker,
  4670. MatDatepickerContent,
  4671. MatDatepickerInput,
  4672. MatDatepickerToggle,
  4673. MatDatepickerToggleIcon,
  4674. MatMonthView,
  4675. MatYearView,
  4676. MatMultiYearView,
  4677. MatCalendarHeader,
  4678. MatDateRangeInput,
  4679. MatStartDate,
  4680. MatEndDate,
  4681. MatDateRangePicker,
  4682. MatDatepickerActions,
  4683. MatDatepickerCancel,
  4684. MatDatepickerApply] });
  4685. static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerModule, providers: [MatDatepickerIntl, MAT_DATEPICKER_SCROLL_STRATEGY_FACTORY_PROVIDER], imports: [MatButtonModule,
  4686. OverlayModule,
  4687. A11yModule,
  4688. PortalModule,
  4689. MatCommonModule,
  4690. MatDatepickerContent,
  4691. MatDatepickerToggle,
  4692. MatCalendarHeader, CdkScrollableModule] });
  4693. }
  4694. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: MatDatepickerModule, decorators: [{
  4695. type: NgModule,
  4696. args: [{
  4697. imports: [
  4698. MatButtonModule,
  4699. OverlayModule,
  4700. A11yModule,
  4701. PortalModule,
  4702. MatCommonModule,
  4703. MatCalendar,
  4704. MatCalendarBody,
  4705. MatDatepicker,
  4706. MatDatepickerContent,
  4707. MatDatepickerInput,
  4708. MatDatepickerToggle,
  4709. MatDatepickerToggleIcon,
  4710. MatMonthView,
  4711. MatYearView,
  4712. MatMultiYearView,
  4713. MatCalendarHeader,
  4714. MatDateRangeInput,
  4715. MatStartDate,
  4716. MatEndDate,
  4717. MatDateRangePicker,
  4718. MatDatepickerActions,
  4719. MatDatepickerCancel,
  4720. MatDatepickerApply,
  4721. ],
  4722. exports: [
  4723. CdkScrollableModule,
  4724. MatCalendar,
  4725. MatCalendarBody,
  4726. MatDatepicker,
  4727. MatDatepickerContent,
  4728. MatDatepickerInput,
  4729. MatDatepickerToggle,
  4730. MatDatepickerToggleIcon,
  4731. MatMonthView,
  4732. MatYearView,
  4733. MatMultiYearView,
  4734. MatCalendarHeader,
  4735. MatDateRangeInput,
  4736. MatStartDate,
  4737. MatEndDate,
  4738. MatDateRangePicker,
  4739. MatDatepickerActions,
  4740. MatDatepickerCancel,
  4741. MatDatepickerApply,
  4742. ],
  4743. providers: [MatDatepickerIntl, MAT_DATEPICKER_SCROLL_STRATEGY_FACTORY_PROVIDER],
  4744. }]
  4745. }] });
  4746. /**
  4747. * Animations used by the Material datepicker.
  4748. * @docs-private
  4749. * @deprecated No longer used, will be removed.
  4750. * @breaking-change 21.0.0
  4751. */
  4752. const matDatepickerAnimations = {
  4753. // Represents:
  4754. // trigger('transformPanel', [
  4755. // transition(
  4756. // 'void => enter-dropdown',
  4757. // animate(
  4758. // '120ms cubic-bezier(0, 0, 0.2, 1)',
  4759. // keyframes([
  4760. // style({opacity: 0, transform: 'scale(1, 0.8)'}),
  4761. // style({opacity: 1, transform: 'scale(1, 1)'}),
  4762. // ]),
  4763. // ),
  4764. // ),
  4765. // transition(
  4766. // 'void => enter-dialog',
  4767. // animate(
  4768. // '150ms cubic-bezier(0, 0, 0.2, 1)',
  4769. // keyframes([
  4770. // style({opacity: 0, transform: 'scale(0.7)'}),
  4771. // style({transform: 'none', opacity: 1}),
  4772. // ]),
  4773. // ),
  4774. // ),
  4775. // transition('* => void', animate('100ms linear', style({opacity: 0}))),
  4776. // ])
  4777. /** Transforms the height of the datepicker's calendar. */
  4778. transformPanel: {
  4779. type: 7,
  4780. name: 'transformPanel',
  4781. definitions: [
  4782. {
  4783. type: 1,
  4784. expr: 'void => enter-dropdown',
  4785. animation: {
  4786. type: 4,
  4787. styles: {
  4788. type: 5,
  4789. steps: [
  4790. { type: 6, styles: { opacity: 0, transform: 'scale(1, 0.8)' }, offset: null },
  4791. { type: 6, styles: { opacity: 1, transform: 'scale(1, 1)' }, offset: null },
  4792. ],
  4793. },
  4794. timings: '120ms cubic-bezier(0, 0, 0.2, 1)',
  4795. },
  4796. options: null,
  4797. },
  4798. {
  4799. type: 1,
  4800. expr: 'void => enter-dialog',
  4801. animation: {
  4802. type: 4,
  4803. styles: {
  4804. type: 5,
  4805. steps: [
  4806. { type: 6, styles: { opacity: 0, transform: 'scale(0.7)' }, offset: null },
  4807. { type: 6, styles: { transform: 'none', opacity: 1 }, offset: null },
  4808. ],
  4809. },
  4810. timings: '150ms cubic-bezier(0, 0, 0.2, 1)',
  4811. },
  4812. options: null,
  4813. },
  4814. {
  4815. type: 1,
  4816. expr: '* => void',
  4817. animation: {
  4818. type: 4,
  4819. styles: { type: 6, styles: { opacity: 0 }, offset: null },
  4820. timings: '100ms linear',
  4821. },
  4822. options: null,
  4823. },
  4824. ],
  4825. options: {},
  4826. },
  4827. // Represents:
  4828. // trigger('fadeInCalendar', [
  4829. // state('void', style({opacity: 0})),
  4830. // state('enter', style({opacity: 1})),
  4831. // // TODO(crisbeto): this animation should be removed since it isn't quite on spec, but we
  4832. // // need to keep it until #12440 gets in, otherwise the exit animation will look glitchy.
  4833. // transition('void => *', animate('120ms 100ms cubic-bezier(0.55, 0, 0.55, 0.2)')),
  4834. // ])
  4835. /** Fades in the content of the calendar. */
  4836. fadeInCalendar: {
  4837. type: 7,
  4838. name: 'fadeInCalendar',
  4839. definitions: [
  4840. { type: 0, name: 'void', styles: { type: 6, styles: { opacity: 0 }, offset: null } },
  4841. { type: 0, name: 'enter', styles: { type: 6, styles: { opacity: 1 }, offset: null } },
  4842. {
  4843. type: 1,
  4844. expr: 'void => *',
  4845. animation: {
  4846. type: 4,
  4847. styles: null,
  4848. timings: '120ms 100ms cubic-bezier(0.55, 0, 0.55, 0.2)',
  4849. },
  4850. options: null,
  4851. },
  4852. ],
  4853. options: {},
  4854. },
  4855. };
  4856. export { DateRange, DefaultMatCalendarRangeStrategy, MAT_DATEPICKER_SCROLL_STRATEGY, MAT_DATEPICKER_SCROLL_STRATEGY_FACTORY, MAT_DATEPICKER_SCROLL_STRATEGY_FACTORY_PROVIDER, MAT_DATEPICKER_VALIDATORS, MAT_DATEPICKER_VALUE_ACCESSOR, MAT_DATE_RANGE_SELECTION_STRATEGY, MAT_RANGE_DATE_SELECTION_MODEL_FACTORY, MAT_RANGE_DATE_SELECTION_MODEL_PROVIDER, MAT_SINGLE_DATE_SELECTION_MODEL_FACTORY, MAT_SINGLE_DATE_SELECTION_MODEL_PROVIDER, MatCalendar, MatCalendarBody, MatCalendarCell, MatCalendarHeader, MatDateRangeInput, MatDateRangePicker, MatDateSelectionModel, MatDatepicker, MatDatepickerActions, MatDatepickerApply, MatDatepickerCancel, MatDatepickerContent, MatDatepickerInput, MatDatepickerInputEvent, MatDatepickerIntl, MatDatepickerModule, MatDatepickerToggle, MatDatepickerToggleIcon, MatEndDate, MatMonthView, MatMultiYearView, MatRangeDateSelectionModel, MatSingleDateSelectionModel, MatStartDate, MatYearView, matDatepickerAnimations, yearsPerPage, yearsPerRow };
  4857. //# sourceMappingURL=datepicker.mjs.map