Bobb Bi
Bobb Bi

Reputation: 17

Fire a function when clicking on a button inside a mui component

I have a MUI static date picker looking as following:

enter image description here

How can i detect clicks on the arrows in order to fire a function? I have a calendar next to this component - and i want to show the corresponding month to the datepicker.

I'm new to this, so pardon me for asking for something that is not possible.

import { StaticDatePicker } from '@mui/x-date-pickers/StaticDatePicker';

Upvotes: 0

Views: 170

Answers (1)

Borys Kupar
Borys Kupar

Reputation: 1721

You can try using onMonthChange property to listen for changes in a month. The callback returns Date string which you can convert to a date object:

<StaticDatePicker onMonthChange={(date) => {
   console.log(new Date(date).getMonth())
}}/>

Upvotes: 1

Related Questions