primereact icon indicating copy to clipboard operation
primereact copied to clipboard

Calendar: The date cannot be selected from the first click in the opened popup

Open safronov-dmitrii opened this issue 2 years ago • 14 comments

Describe the bug

The date cannot be selected from the first click in the opened popup. You have to double-click on the date in the opened calendar to display the selected date in the input.

It is important that the popup is opened by clicking on the input field. If the popup is opened via icon, then the problem is not reproduced.

The bug cannot be reproduced in version 9.5.0.

Reproducer

https://stackblitz.com/edit/react-w6bsse

PrimeReact version

9.6.0

React version

18.x

Language

TypeScript

Build / Runtime

Create React App (CRA)

Browser(s)

No response

Steps to reproduce the behavior

  1. Click on the input field (not on the icon button) to open the calendar;
  2. Click on any date.

Expected behavior

The date can be selected in the calendar with a single mouse click.

safronov-dmitrii avatar Jun 28 '23 17:06 safronov-dmitrii

I updated your ticket with a reproducer.

melloware avatar Jun 28 '23 19:06 melloware

Why was this fix not included in 9.6.1? How much time will version 10 take to be released?

djapal avatar Aug 01 '23 18:08 djapal

From PrimeTek: " 9.6.1 just includes our PRO support fixes that's why we didn't apply other PRs"

melloware avatar Aug 01 '23 20:08 melloware

Fixed in 9.6.2 if you want to give it a try

melloware avatar Aug 17 '23 11:08 melloware

Hi @melloware

I'm using 9.6.2 and this issue is still there, I need to click twice to select date.

Reproducer: https://codesandbox.io/p/sandbox/hardcore-hooks-rvkpxr

maitrungduc1410 avatar Sep 04 '23 16:09 maitrungduc1410

@maitrungduc1410 it looks like Vite is processing faster or differently than Create React App but I am pretty sure this is fixed for 10.0.0

melloware avatar Sep 04 '23 16:09 melloware

@maitrungduc1410 I also have the same problem with version 9.6.2, for now I have solved it like this:

      <Calendar
        onFocus={handleCalendarFocus}
        ...
        />
const handleCalendarFocus = () => {
   setTimeout(() => {
     const datePickerCollection =
       document.getElementsByClassName('p-datepicker');
     if (datePickerCollection.length) {
       const datePicker = datePickerCollection.item(0) as HTMLDivElement;
       datePicker.setAttribute('tabindex', '0');
       datePicker.focus();
     }
   }, 500);
 };

joseanfernandez avatar Sep 07 '23 11:09 joseanfernandez

@melloware, Somehow I'm still facing same issue in my NextJS project (next 13.4.12 and PrimeReact 9.6.2), it's hard to tell what's going on

The example is this, this Sandbox works: https://codesandbox.io/p/sandbox/beautiful-sky-6gf553

In my production code, I copy exactly same as above example, but it doesn't work:

ezgif-4-0133cf8636

as you can see, everytime I select a date, the overlay is closed, and I have to click again.

Weird, exactly same code as the Sandbox (both are NextJS, same version of all packages: next, primereact...)

I think I should wait for primereact v10 and try again

maitrungduc1410 avatar Sep 10 '23 03:09 maitrungduc1410

Yes I am pretty sure this is fixed in V10 because I am testing using NextJS and the showcase right now and the Calendar seems to be working fine in 10.0.0. Let me know when 10.0.0 comes out if it is still not working.

melloware avatar Sep 10 '23 11:09 melloware

Version 10.6.3 still has this same problem :/ so silly, the workaround mentioned by @joseanfernandez works

pedrofg avatar May 02 '24 01:05 pedrofg

Version 10.6.3 still has this same problem , the workaround mentioned by @joseanfernandez not working if you use mask or type the date on input, it triggers focus on panel and is not possible to write.

sevastosm avatar Jul 07 '24 13:07 sevastosm

Version 10.7 with Vite still happens. I have the problem that @sevastosm said, can't use workaround because I need a mask and input type available =/. Downgraded back to 9.6.3 and works just fine. PS: I'm using calendar inside an Datatable, with "cell" edit mode, rendering the Calender inside the "editor" prop.

MarcoCPinho avatar Jul 16 '24 23:07 MarcoCPinho

Using this in Version 10.8.0 with Vite and still have the same issue. Similar Problem as @MarcoCPinho can't use the workaround because we need to use a mask and the input field. Can use the workaround with the onShow instead of the onFocus though, but still not very nice behaviour of the component then.

F4ssi avatar Aug 01 '24 15:08 F4ssi

Now the calendar popup does not close on first time click outside.

lekhnath avatar Aug 30 '24 04:08 lekhnath

In 10.9.1 here it is working in both CRA and Vite:

CRA: https://stackblitz.com/edit/react-w6bsse?file=package.json

Vite: https://stackblitz.com/edit/hwr9uvkw?file=src%2FApp.jsx

melloware avatar Jan 06 '25 12:01 melloware