Picker inside Modal does not select date on MacOS 12 / Safari 15
See original GitHub issueTLDR: 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
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:
- Created a year ago
- Comments:6 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What do you mean “in a modal”? Do you have time to create reproducible example on CodeSandbox?
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.