React-calendar: How can I prevent the list of months being shown on clicking the month name?

Created on 23 Jun 2020  路  6Comments  路  Source: wojtekmaj/react-calendar

I'm using this plugin within a date picker component. I want the user to be able to navigate back and forth between dates, BUT I don't want them to be able to click the Month ('June 2020') in the navigation bar. I think it will be confusing for my users if they click that and the months appear.

Is there a way to disable this functionality?

question

Most helpful comment

You can use minDetail and maxDetail props to limit the views users will be able to navigate through.

All 6 comments

HI @SharonGilmore
You can try adding pointer-events:none to the .react-calendar__navigation__label.

Anyway you will be making some style changes to the calendar. There is an option to provide our own class name to the calendar wrapper. So we can override the styles using that.

The style would look like:
Note: you need to do this within your custom class to avoid style bleeding.

button.react-calendar__navigation__label {
  pointer-events: none;
}

Thank you! That worked!

You can use minDetail and maxDetail props to limit the views users will be able to navigate through.

Oh, brilliant, thank you!

The CSS pointer events solution didn't work for me. Although clicking is disabled you can still tab on to the button and click enter to open it. Also AFAIK you can't set maxDetail to "day" so the month calendar can still be opened. I love this calendar but I'm thinking the ability to open the month calendar might be confusing to vision impaired users. If I'm missing something please let me know.

I found a hacky solution to this issue using CSS below:

button.react-calendar__navigation__label {
  visibility: hidden;
}

.react-date-picker, .react-date-picker *, .react-date-picker *:before, .react-date-picker *:after {
  visibility: visible;
}

If there are any problems with this or anyone knows a better solution let me know.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Hubro picture Hubro  路  3Comments

wojtekmaj picture wojtekmaj  路  3Comments

wojtekmaj picture wojtekmaj  路  5Comments

spoldman picture spoldman  路  4Comments

Chusynuk picture Chusynuk  路  3Comments