question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Picker inside Modal does not select date on MacOS 12 / Safari 15

See original GitHub issue

TLDR: This is a clone of https://github.com/wojtekmaj/react-date-picker/issues/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:

  • you need macOS and a recent Safari (tested with 15.4)
  • go to https://codesandbox.io/s/react-datetime-picker-61wq02?file=/index.js
  • click on button “not working datetime picker”
  • click on the date text (2022/5/5 in the screenshot)
  • dialog pops up with a calendar view (as in the screenshot below)
  • hover over a date (e.g. 10) and with click

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 https://github.com/wojtekmaj/react-date-picker/issues/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.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
wojtekmajcommented, Sep 14, 2022

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

0reactions
github-actions[bot]commented, Dec 19, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

new UIDatePicker as inputView | Apple Developer Forums
We are aware of this issue. As a workaround for now you can call sizeToFit on the date picker before assigning it as...
Read more >
HTML5 date picker doesn't show on Safari - Stack Overflow
On the documentation, it says Safari is supported: however, it currently shows just a text field (whereas Chrome and other browsers show the...
Read more >
Date Picker - SwiftUI Handbook - Design+Code
Alternatively you can set it to starting from the present date with Date().... DatePicker("Range", selection: $selectedDate, in ...
Read more >
Selecting dates and times with DatePicker - Hacking with Swift
But if you do that you now have two problems: the date picker still makes space for a label even though it's empty,...
Read more >
<input type="time"> - HTML: HyperText Markup Language | MDN
Depending on what browser you're using, you might find that times outside the specified range might not even be selectable in the time...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found