1- import React , { useState , useEffect } from 'react'
1+ import React , { useState , useEffect , useRef } from 'react'
22import PropTypes from 'prop-types'
33import momentPropTypes from 'react-moment-proptypes'
44
@@ -40,6 +40,7 @@ const getIcon = type => <DecorativeIcon symbol={type} size={16} />
4040
4141const DatePicker = ( { id, date, copy, onDateChange, isDayDisabled, inline, label, ...props } ) => {
4242 const [ isFocused , setIsFocused ] = useState ( false )
43+ const labelRef = useRef ( null )
4344
4445 useEffect ( ( ) => {
4546 window . addEventListener ( 'resize' , getResponsiveDaySize ( inline ) )
@@ -49,6 +50,12 @@ const DatePicker = ({ id, date, copy, onDateChange, isDayDisabled, inline, label
4950 }
5051 } )
5152
53+ useEffect ( ( ) => {
54+ if ( ! isFocused ) {
55+ labelRef . current . control . blur ( )
56+ }
57+ } , [ isFocused ] )
58+
5259 const onFocusChange = ( { focused } ) => {
5360 setIsFocused ( focused )
5461 }
@@ -60,7 +67,7 @@ const DatePicker = ({ id, date, copy, onDateChange, isDayDisabled, inline, label
6067 const daySize = getResponsiveDaySize ( inline ) ( )
6168 return (
6269 < CalendarContainer { ...safeRest ( propsWithoutStyling ) } daySize = { daySize } >
63- < label htmlFor = { id } >
70+ < label htmlFor = { id } ref = { labelRef } >
6471 < LabelText > { label } </ LabelText >
6572 { inline && (
6673 < React . Fragment >
0 commit comments