11import { html } from 'lit' ;
2- import { property } from 'lit/decorators.js' ;
2+ import { eventOptions , property } from 'lit/decorators.js' ;
33import { ifDefined } from 'lit/directives/if-defined.js' ;
44import { live } from 'lit/directives/live.js' ;
55
@@ -17,6 +17,10 @@ import { watch } from '../common/decorators/watch.js';
1717import { registerComponent } from '../common/definitions/register.js' ;
1818import type { AbstractConstructor } from '../common/mixins/constructor.js' ;
1919import { EventEmitterMixin } from '../common/mixins/event-emitter.js' ;
20+ import {
21+ type FormValue ,
22+ createFormValueState ,
23+ } from '../common/mixins/forms/form-value.js' ;
2024import { noop , partNameMap } from '../common/util.js' ;
2125import type { IgcInputComponentEventMap } from '../input/input-base.js' ;
2226import {
@@ -81,8 +85,9 @@ export default class IgcDateTimeInputComponent extends EventEmitterMixin<
8185 return dateTimeInputValidators ;
8286 }
8387
88+ protected override _formValue : FormValue < Date | null > ;
89+
8490 protected _defaultMask ! : string ;
85- protected _value : Date | null = null ;
8691 private _oldValue : Date | null = null ;
8792 private _min : Date | null = null ;
8893 private _max : Date | null = null ;
@@ -118,7 +123,7 @@ export default class IgcDateTimeInputComponent extends EventEmitterMixin<
118123 }
119124
120125 public get value ( ) : Date | null {
121- return this . _value ;
126+ return this . _formValue . value ;
122127 }
123128
124129 /* @tsTwoWayProperty (true, "igcChange", "detail", false) */
@@ -128,8 +133,7 @@ export default class IgcDateTimeInputComponent extends EventEmitterMixin<
128133 */
129134 @property ( { converter : convertToDate } )
130135 public set value ( value : Date | string | null | undefined ) {
131- this . _value = convertToDate ( value ) ;
132- this . _setFormValue ( getDateFormValue ( this . _value ) ) ;
136+ this . _formValue . setValueAndFormState ( value as Date | null ) ;
133137 this . updateMask ( ) ;
134138 this . _validate ( ) ;
135139 }
@@ -276,6 +280,15 @@ export default class IgcDateTimeInputComponent extends EventEmitterMixin<
276280 constructor ( ) {
277281 super ( ) ;
278282
283+ this . _formValue = createFormValueState ( this , {
284+ initialValue : null ,
285+ transformers : {
286+ setValue : convertToDate ,
287+ setDefaultValue : convertToDate ,
288+ setFormValue : getDateFormValue ,
289+ } ,
290+ } ) ;
291+
279292 addKeybindings ( this , {
280293 skip : ( ) => this . readOnly ,
281294 bindingDefaults : { preventDefault : true , triggers : [ 'keydownRepeat' ] } ,
@@ -464,6 +477,7 @@ export default class IgcDateTimeInputComponent extends EventEmitterMixin<
464477 return newDate ;
465478 }
466479
480+ @eventOptions ( { passive : false } )
467481 private async onWheel ( event : WheelEvent ) {
468482 if ( ! this . focused || this . readOnly ) {
469483 return ;
@@ -587,7 +601,7 @@ export default class IgcDateTimeInputComponent extends EventEmitterMixin<
587601 this . _oldValue = this . value ;
588602 const areFormatsDifferent = this . displayFormat !== this . inputFormat ;
589603
590- if ( ! this . _value ) {
604+ if ( ! this . value ) {
591605 this . maskedValue = this . emptyMask ;
592606 await this . updateComplete ;
593607 this . select ( ) ;
0 commit comments