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

Clicking anywhere that is not an active button when placed in react-modal triggers outsideAction and closes the calendar #640

Open
2 tasks done
copperseed opened this issue Nov 3, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@copperseed
Copy link

Before you start - checklist

  • I followed instructions in documentation written for my React-Date-Picker version
  • I have checked if this bug is not already reported

Description

Somewhat related to #636. The issue occurs when using the react-modal package and placing the date picker in a modal. On opening of the calendar, the buttons in the calendar wrapper all function as they should but clicking anywhere else in the calendar wrapper including disabled calendar tiles and disabled buttons triggers an outsideAction and therefore closes the calendar.

Steps to reproduce

  1. Install react-modal
  2. Create a modal
  3. Place a datepicker input into the modal
  4. Open the datepicker calendar
  5. Click anywhere but on an active button
  6. Datepicker closes with outsideAction

Expected behavior

Expecting the calendar not to close when clicking anywhere in the calendar area.

Actual behavior

Calendar closes when clicking anywhere in the calendar area that is not an active button .

Additional information

No response

Environment

  • Browser (if applicable):
  • React-Date-Picker version: Latest
  • React version: 17.0.2
@copperseed copperseed added the bug Something isn't working label Nov 3, 2023
@tjhart
Copy link

tjhart commented Dec 20, 2023

+1.

Worse when using react-bootstrap/Modal All buttons (calendar days, calendar navigation, etc) trigger outsideAction

@JoaoVSouto
Copy link

One workaround I found that did the job for me:

<ReactDatePicker
  inputRef={ref => {
    ref?.setAttribute('tabindex', '0');
  }}
/>

@sergioUjo
Copy link

Having the same issue, workaround not working for me :(

@judsonjuniorr
Copy link

Had the same issue here, I'm using this workaround:

import 'react-date-picker/dist/DatePicker.css';
import 'react-calendar/dist/Calendar.css';

import { useRef, useState } from 'react';
import DatePickerComponent from 'react-date-picker';
import { useOnClickOutside } from 'usehooks-ts';

const DatePicker = () => {
  const [calendarOpen, setCalendarOpen] = useState(false);
  const ref = useRef<HTMLDivElement>(null);

  const handleClickOutside = () => {
    if (calendarOpen) {
      setCalendarOpen(false);
    }
  };
  useOnClickOutside(ref, handleClickOutside);


  return (
    <DatePickerComponent
      inputRef={ref}
      isOpen={calendarOpen}
      shouldCloseCalendar={e => e.reason !== 'outsideAction'}
      onCalendarOpen={() => {
        setCalendarOpen(true);
      }}
      onCalendarClose={() => {
          setCalendarOpen(false);
      }}
    />
  );
};

export default DatePicker;

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 Jul 22, 2024
@nicoletailiuha
Copy link

Same issue and for me it happens on Safari but works fine on Chrome.

@jmorey28
Copy link

jmorey28 commented Aug 2, 2024

Able to reproduce with Radix dialog as well, clicking on a month or a year just closes the date picker.
Code sandbox example: https://codesandbox.io/p/devbox/fervent-boyd-cv8zjh

adding event.preventDefault(); to the onOutsideAction function fixes it but may not be ideal for some implementations, the main issue seems to be that the modal pulls focus off of the calendar when a month is clicked, removing the focusin event listener also fixes the issue, but still moves focus to the modal, which essentially has the same effect of @judsonjuniorr workaround

@github-actions github-actions bot removed the stale label Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants