You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The example already has the modal opened by default. Click on the date input, and no matter where you click inside the <ComposedModal> and outside of the calendar, the calendar just does not close. It can only be closed by tab away or select the date.
Close the modal by clicking the close button.
There is another <DatePicker outside of <ComposedModal>. It has no problem closes its calendar popover by clicking elsewhere in the page.
I believe the underlying flatpickr calendar library attaches the eventhandler to close calendar on click at higher element in the DOM hierarhcy, maybe document or body, and the <ComposedModal> component just stops the event from bubbling up.
I haven't found flatpickr API to specify the element to listen to the click event, but I can work around this issue by listening to MouseDown event when the event is triggered from element other than the <DateInput> or <DatePicker> elements, and call the flatpickrInstance.close() imperative API.
Something like this should work around the issue:
// in the rendering body of the component rendering `<Modal>`functioncloseCalendarWhenClickingOutsideOfDateSection(e){if(dateSectionRef.current.contains(e.target)){return;}flatpickrInstanceRef.current.close();}return(<ComposedModal><divonMouseDown={closeCalendarWhenClickingOutsideOfDateSection}><divref={dateSectionRef}><!--othermodalbodyelements--><DatePickeronOpen={(...args)=>flatpickrInstanceRef.current=args[2]}><DateInput><!--othermodalbodyelements-->
Package
@carbon/react
Browser
Chrome, Firefox
Package version
v1.56.0
React version
v18
Description
When a is hosted inside of either or , click on the and the calendar popover can not be dismissed by clicking outside of the calendar.
datpicker-calendar-does-not-dismiss.mov
Reproduction/example
https://stackblitz.com/edit/github-datbmn?file=src%2FApp.jsx
Steps to reproduce
<ComposedModal>
and outside of the calendar, the calendar just does not close. It can only be closed by tab away or select the date.<DatePicker
outside of<ComposedModal>
. It has no problem closes its calendar popover by clicking elsewhere in the page.Suggested Severity
None
Application/PAL
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: