1
- import React , { useState , useEffect } from 'react'
1
+ import React , { useState , useEffect , useRef } from 'react'
2
2
import PropTypes from 'prop-types'
3
3
import momentPropTypes from 'react-moment-proptypes'
4
4
@@ -40,6 +40,7 @@ const getIcon = type => <DecorativeIcon symbol={type} size={16} />
40
40
41
41
const DatePicker = ( { id, date, copy, onDateChange, isDayDisabled, inline, label, ...props } ) => {
42
42
const [ isFocused , setIsFocused ] = useState ( false )
43
+ const labelRef = useRef ( null )
43
44
44
45
useEffect ( ( ) => {
45
46
window . addEventListener ( 'resize' , getResponsiveDaySize ( inline ) )
@@ -49,6 +50,12 @@ const DatePicker = ({ id, date, copy, onDateChange, isDayDisabled, inline, label
49
50
}
50
51
} )
51
52
53
+ useEffect ( ( ) => {
54
+ if ( ! isFocused ) {
55
+ labelRef . current . control . blur ( )
56
+ }
57
+ } , [ isFocused ] )
58
+
52
59
const onFocusChange = ( { focused } ) => {
53
60
setIsFocused ( focused )
54
61
}
@@ -60,7 +67,7 @@ const DatePicker = ({ id, date, copy, onDateChange, isDayDisabled, inline, label
60
67
const daySize = getResponsiveDaySize ( inline ) ( )
61
68
return (
62
69
< CalendarContainer { ...safeRest ( propsWithoutStyling ) } daySize = { daySize } >
63
- < label htmlFor = { id } >
70
+ < label htmlFor = { id } ref = { labelRef } >
64
71
< LabelText > { label } </ LabelText >
65
72
{ inline && (
66
73
< React . Fragment >
0 commit comments