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

Date selection does not work inside MUI Modal #184

Closed
seb-lie opened this issue May 5, 2022 · 7 comments
Closed

Date selection does not work inside MUI Modal #184

seb-lie opened this issue May 5, 2022 · 7 comments
Labels
help wanted Extra attention is needed question Further information is requested stale

Comments

@seb-lie
Copy link

seb-lie commented May 5, 2022

TLDR: This is a clone of wojtekmaj/react-date-picker#288 for the datetime-picker. The suggested fix solution worked on the 3.5.0 release of datetime-picker.

The bug

The issues is that the calendar popup closes, but does not propagate the selected date, when clicking on a date when it is itself is within a Modal on Safari. It is very specific to the last two conditions, but well, that's exactly our scenario :)

Steps to reproduce it

To reproduce:

Expected:

  • Selected date is set (value updates to 2022/5/10)

Actual:

  • Selected date is not set (value remains 2022/5/5)

Screenshot

image

A Validated solution

For the 3.5.0 release was the below patch (from the wojtekmaj/react-date-picker#288) :

index 5d60e42..32cc7e5 100644
--- a/node_modules/react-datetime-picker/dist/DateTimePicker.js
+++ b/node_modules/react-datetime-picker/dist/DateTimePicker.js
@@ -98,11 +98,14 @@ var DateTimePicker = /*#__PURE__*/function (_PureComponent) {
     _defineProperty(_assertThisInitialized(_this), "state", {});
 
     _defineProperty(_assertThisInitialized(_this), "onOutsideAction", function (event) {
-      // Try event.composedPath first to handle clicks inside a Shadow DOM.
-      var target = 'composedPath' in event ? event.composedPath()[0] : event.target;
-
-      if (_this.wrapper && !_this.wrapper.contains(target)) {
-        _this.closeWidgets();
+      // fix from https://github.com/wojtekmaj/react-date-picker/issues/288
+      if (
+        _this.wrapper &&
+        !_this.wrapper.contains(event.target) &&
+        (typeof  event?.target?.className === 'string' && !event?.target?.className?.indexOf('react-calendar'))
+      ) {
+        _this.closeCalendar()
+        event.stopPropagation()
       }
     });

3.5.0 vs latest main

I'm not sure whether the issue reproduces on current main (2dce2af) as the onOutsideAction part changed slightly.

@rscotten
Copy link

hey, @wojtekmaj I'd really appreciate a fix to this. If the datepicker is in a modal in the Safari Browser on MacOSX, and you click the input to open the datepicker dropdown, the calendar days and month don't update when clicking the right and left arrows.

@rscotten
Copy link

rscotten commented Sep 14, 2022

@wojtekmaj This is what happens when I open the datepicker and click the right arrow twice:

(again, it only happens in MacOS Safari in a modal)

Screen Shot 2022-09-14 at 2 09 56 PM

Screen Shot 2022-09-14 at 2 10 02 PM

Screen Shot 2022-09-14 at 2 10 08 PM

Screen Shot 2022-09-14 at 2 10 14 PM

@wojtekmaj
Copy link
Owner

What do you mean "in a modal"? Do you have time to create reproducible example on CodeSandbox?

@seb-lie
Copy link
Author

seb-lie commented Sep 15, 2022

I've updated the example to use v4.0.0 from yesterday - instructions are still valid from above (section "Steps to reproduce it"). It's still 100% reproducible.

https://codesandbox.io/s/react-datetime-picker-61wq02?file=/index.js

@wojtekmaj
Copy link
Owner

It looks like MUI is messing the styles up. Safari has nothing to do with it, on Chrome it's the same story.

Here it is compared to native <dialog>:

https://codesandbox.io/s/react-datetime-picker-mui-and-native-dialogs-r6vnf9

I don't know anything about MUI specifics, and I don't know how they manipulate Dialog's children, so I won't be able to help you with it personally, but I'll keep it open if anyone from the community would be willing to help.

@wojtekmaj wojtekmaj added help wanted Extra attention is needed question Further information is requested labels Sep 19, 2022
@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot added the stale label Dec 19, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jan 2, 2023

This issue was closed because it has been stalled for 14 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 2, 2023
@wojtekmaj wojtekmaj changed the title Picker inside Modal does not select date on MacOS 12 / Safari 15 Date selection does not work inside MUI Modal May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested stale
Projects
None yet
Development

No branches or pull requests

3 participants