-
-
Notifications
You must be signed in to change notification settings - Fork 197
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
In Gatsby, in Firefox, all click events close calendar #274
Comments
Sorry for the delay. Been super busy in commercial projects. Found the reason. The reason is that we have a method, onOutsideClick. react-date-picker/src/DatePicker.jsx Lines 53 to 57 in e520a0b
If the method detects a click outside React-Date-Picker's wrapper, it closes the calendar. The thing is, in Gatsby, clicking on the calendar causes We could do this awful, awful hack: import React, { useEffect, useRef, useState } from "react"
import DatePicker from "react-date-picker"
import Layout from "../components/layout"
function MyApp() {
const [value, onChange] = useState();
const datePicker = useRef();
useEffect(() => {
if (!datePicker.current) {
return;
}
// Replace DatePicker's onOutsideAction with our own that takes Gatsby's focus wrapper into account
const _this = datePicker.current;
_this.onOutsideAction = (event) => {
if (
_this.wrapper
&& !_this.wrapper.contains(event.target)
// This is the line that fixes it
&& event.target.id !== 'gatsby-focus-wrapper'
) {
_this.closeCalendar();
}
}
});
return (
<DatePicker
ref={datePicker}
onChange={onChange}
value={value}
/>
);
};
export default MyApp; When you're done vomiting, it should work just fine :D |
#15 (comment) |
I suggest placing a breakpoint in line with |
@wojtekmaj I'm no longer working on the project that was running into this bug. I think your fix worked, but I never finished up the PR there before moving onto other features. I gave them a link to this Issue in case they want to implement it themselves, but otherwise you could close this issue if you want. |
@wojtekmaj on my end, setting the condition as |
@wojtekmaj The issue happens when the date picker is inside the MUI Dialog, this isn't related with gatsby. Check the demo below: You have the normal working date picker on the page, and then you have the date picker inside the MUI Dialog. Click the button, open the calendar, click on the "month" to select the month on the month view: |
Adding import { Dialog } from '@material-ui/core'
<Dialog disableEnforceFocus={true} ></Dialog> |
Facing a similar issue with a custom calendar implementation. Maybe a |
Good idea, I think it's worth implementing. |
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 14 days. |
This issue was closed because it has been stalled for 14 days with no activity. |
When react-date-picker is used in a Gatsby app within a Firefox browser all click events (whether on the calendar days or the navigation arrows at the top) all close the calendar instantly. When I click on a day, the calendar closes without inputting a date. All click events seem to trigger
react-date-picker--open
class to change toreact-date-picker--closed
before anything else can happen.To reproduce, spin up a new gatsby project and drop the datepicker in anywhere. I did not see this problem with a create-react-app.
If I mount the react-date-picker component on the DOM via ReactDOM, this fixes the problem, but that doesn't seem like a good workaround in my use case.
The text was updated successfully, but these errors were encountered: