@@ -301,6 +301,11 @@ export class Datepicker extends Component<DatepickerOptions> {
301301 this . gotoDate ( new Date ( ) ) ;
302302 }
303303 this . isOpen = false ;
304+
305+ // HTML5 input date field support
306+ if ( this . el . type == 'date' ) {
307+ this . el . classList . add ( 'datepicker-date-input' ) ;
308+ }
304309 }
305310
306311 static get defaults ( ) {
@@ -417,6 +422,10 @@ export class Datepicker extends Component<DatepickerOptions> {
417422 if ( typeof format === 'function' ) return format ( this . date ) ;
418423 if ( ! Datepicker . _isDate ( this . date ) ) return '' ;
419424 // String Format
425+ return this . formatDate ( format ) ;
426+ }
427+
428+ formatDate ( format ) {
420429 const formatArray = format . split ( / ( d { 1 , 4 } | m { 1 , 4 } | y { 4 } | y y | ! .) / g) ;
421430 const formattedDate = formatArray
422431 . map ( label => this . formats [ label ] ? this . formats [ label ] ( ) : label )
@@ -458,11 +467,23 @@ export class Datepicker extends Component<DatepickerOptions> {
458467 }
459468 }
460469
470+ /**
471+ * Sets the data-date attribute on the date input field
472+ */
473+ setDataDate ( ) {
474+ this . el . setAttribute ( 'data-date' , this . toString ( ) )
475+ }
476+
461477 /**
462478 * Sets current date as the input value.
463479 */
464480 setInputValue ( ) {
465- this . el . value = this . toString ( ) ;
481+ if ( this . el . type == 'date' ) {
482+ this . setDataDate ( )
483+ this . el . value = this . formatDate ( 'yyyy-mm-dd' )
484+ } else {
485+ this . el . value = this . toString ( ) ;
486+ }
466487 this . el . dispatchEvent ( new CustomEvent ( 'change' , { bubbles :true , cancelable :true , composed :true , detail : { firedBy : this } } ) ) ;
467488 }
468489
@@ -925,7 +946,11 @@ export class Datepicker extends Component<DatepickerOptions> {
925946 this . calendarEl . removeEventListener ( 'click' , this . _handleCalendarClick ) ;
926947 }
927948
928- _handleInputClick = ( ) => {
949+ _handleInputClick = ( e ) => {
950+ // Prevents default browser datepicker modal rendering
951+ if ( this . el . type == 'date' ) {
952+ e . preventDefault ( )
953+ }
929954 this . open ( ) ;
930955 }
931956
@@ -1008,7 +1033,12 @@ export class Datepicker extends Component<DatepickerOptions> {
10081033 else {
10091034 date = new Date ( Date . parse ( this . el . value ) ) ;
10101035 }
1011- if ( Datepicker . _isDate ( date ) ) this . setDate ( date ) ;
1036+ if ( Datepicker . _isDate ( date ) ) {
1037+ this . setDate ( date ) ;
1038+ if ( this . el . type == 'date' ) {
1039+ this . setDataDate ( ) ;
1040+ }
1041+ }
10121042 }
10131043
10141044 renderDayName ( opts , day , abbr : boolean = false ) {
0 commit comments