Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close DatePicker Modal, by a button or after selecting date #113

Open
HaminJuri opened this issue Jul 29, 2023 · 8 comments
Open

Close DatePicker Modal, by a button or after selecting date #113

HaminJuri opened this issue Jul 29, 2023 · 8 comments
Labels
bug Something isn't working question Further information is requested

Comments

@HaminJuri
Copy link

Hey, as it's on the title:
How do you close DatePicker Modal by using a button or after the user selects its desired date?
package.json:
"...",
"react": "18.2.0",
"next": "13.4.12",
"zaman": "^2.0.7"

@sepehrsamavati
Copy link

sepehrsamavati commented Aug 15, 2023

I couldn't close it either, so I did it by clicking its input, which involves DOM manipulation and is not considered best practice:

// in Component.tsx
const toggleModal = useCallback(() => {
    const dateInput: HTMLInputElement | null = wrapperRef.current?.querySelector(`.${dateInputClassName}`) ?? null;
    dateInput?.click();
}, []);

wrapperRef: reference to the parent of <DatePicker /> component
dateInputClassName: class name used in <DatePicker inputClass={dateInputClassName} />

This can be called in onChange callback:

<DatePicker
    inputClass={dateInputClassName}
    onChange={() => toggleModal()}
/>

@rzkhosroshahi
Copy link
Owner

rzkhosroshahi commented Aug 28, 2023

There are two ways you can achieve it. The calendar will be closed when the user clicks outside the date picker, however, you can also pass the show prop if you want to close the date picker manually.

@rzkhosroshahi rzkhosroshahi added the question Further information is requested label Aug 28, 2023
@mahbobJan
Copy link

There are two ways you can achieve it. The calendar will be closed when the user clicks outside the date picker, however, you can also pass the show prop if you want to close the date picker manually.

show prop not work

@rzkhosroshahi rzkhosroshahi added the bug Something isn't working label Sep 25, 2023
@mmsadati
Copy link

There are two ways you can achieve it. The calendar will be closed when the user clicks outside the date picker, however, you can also pass the show prop if you want to close the date picker manually.

show prop not work

I have the same issue
When is this bug going to be fixed?

@MHMighani
Copy link

H @rzkhosroshahi
I'm working on this issue. I want to know that when the show prop is passed, do you want the calendar window still closes when the user clicks outside or nothing happens and it is fully controlled by the show prop?

@rzkhosroshahi
Copy link
Owner

I might change the show prop to the defaultShow. it won't control the inside component state. In other words, it gonna just set the default behavior of showing date-picker, and my component its not going to listen to the prop.

@MahdiFarzami
Copy link

i have same issue and handle it with this code

function simulateClick(x, y) {
const event = new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true,
clientX: x,
clientY: y
});

const target = document.elementFromPoint(x, y);
if (target) {
  target.dispatchEvent(event);
}

}

its not best way but there is no ohter way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

8 participants
@MahdiFarzami @rzkhosroshahi @sepehrsamavati @MHMighani @mahbobJan @mmsadati @HaminJuri and others