Skip to content

Commit 2b8e22a

Browse files
royNanodevbilltelus
authored andcommitted
fix(community-date-picker): remove blur on scroll end
1 parent 671b951 commit 2b8e22a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/DatePicker/DatePicker.jsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect } from 'react'
1+
import React, { useState, useEffect, useRef } from 'react'
22
import PropTypes from 'prop-types'
33
import momentPropTypes from 'react-moment-proptypes'
44

@@ -40,6 +40,7 @@ const getIcon = type => <DecorativeIcon symbol={type} size={16} />
4040

4141
const 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

Comments
 (0)