Skip to content

Commit 949e180

Browse files
committed
fix: don't trigger onChange twice when clicking on calendar
1 parent 08d9258 commit 949e180

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

packages/form/src/components/DateInputField/__tests__/index.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('DateInputField', () => {
3838
await userEvent.click(input)
3939
await userEvent.click(screen.getByText('15'))
4040
await waitFor(() => {
41-
expect(onChange).toBeCalledTimes(2)
41+
expect(onChange).toBeCalledTimes(1)
4242
})
4343

4444
expect(resultForm.current.getValues('test')).toEqual(
@@ -72,7 +72,7 @@ describe('DateInputField', () => {
7272
await userEvent.click(screen.getByText('15'))
7373

7474
await waitFor(() => {
75-
expect(onChange).toBeCalledTimes(3)
75+
expect(onChange).toBeCalledTimes(2)
7676
})
7777

7878
expect(resultForm.current.getValues('test')).toEqual([

packages/ui/src/components/DateInput/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ export const DateInput = <IsRange extends undefined | boolean>({
151151
)
152152
const [hoveredDate, setHoveredDate] = useState<Date | null>(null)
153153
const refInput = useRef<HTMLInputElement>(null)
154+
const popupRef = useRef<HTMLDivElement>(null)
154155
const MONTHS = getMonths(locale)
155156
const DAYS = getDays(locale)
156157
const MONTHS_ARR = getLocalizedMonths(locale)
@@ -274,6 +275,7 @@ export const DateInput = <IsRange extends undefined | boolean>({
274275
onClick={() => {
275276
if (!isPopupVisible) setVisible(true)
276277
}}
278+
ref={popupRef}
277279
>
278280
{input === 'text' ? (
279281
<CalendarPopup

0 commit comments

Comments
 (0)