Get started with @mantine/dates package
After installation import package styles at the root of your application:
Followed the installation instructions above but something is not working (calendars and date pickers have no styles and look broken)? You've fallen into the trap of not importing dates styles! To fix this issue, import dates styles at the root of your application:
After installing the @mantine/dates package and importing styles, you can use all components from it:
@mantine/dates components work with date strings: YYYY-MM-DD or YYYY-MM-DD HH:mm:ss depending on the component. Those strings do not include any timezone-specific information.
@mantine/dates components use dayjs under the hood for date manipulations and formatting. dayjs is a required dependency – you cannot change it to another date library. If you want to use a different date library in your application, you will need to install it separately.
The DatesProvider component lets you set various settings that are shared across all components exported from the @mantine/dates package. DatesProvider supports the following settings:
If you want to avoid layout shifts, set consistentWeeks: true in the DatesProvider settings. This will ensure that every month has 6 weeks, even if outside days are not in the same month.
All formatting props accept a function in addition to a dayjs format string. The function receives the date as a YYYY-MM-DD string (or YYYY-MM-DD HH:mm:ss for components that include time) and returns the label to display. Use it to format dates with Intl.DateTimeFormat instead of dayjs – this way you do not need to import dayjs/locale/* modules for every language that your application supports:
The following props accept a function:
| Prop | Components | | --- | --- | | valueFormatter | DatePickerInput , MonthPickerInput , YearPickerInput | | valueFormat | DateInput , DateTimePicker , InlineDateTimePicker | | monthLabelFormat | Calendar , DatePicker , DateInput , MiniCalendar , MonthLevel and all components that use them | | yearLabelFormat | Calendar , DatePicker , YearLevel and all components that use them | | decadeLabelFormat | Calendar , DatePicker , DecadeLevel and all components that use them | | weekdayFormat | Calendar , DatePicker , Month , WeekdaysRow and all components that use them | | monthsListFormat | Calendar , MonthPicker , MonthsList and all components that use them | | yearsListFormat | Calendar , YearPicker , YearsList and all components that use them |
Note that DateInput.valueFormat is also used to parse user input. When it is set to a function, the component can no longer parse arbitrary formats – set the dateParser prop to handle typed values.
To apply formatters to all instances of a component, define them in theme.components instead of setting them on every usage:
Formatters do not remove the dayjs dependency – it is still used internally for date parsing and arithmetic. What they do remove is the need to import a dayjs locale module per supported language.
Some components like DateInput require the custom parse format dayjs plugin. You need to extend dayjs with this plugin before using components that require it. Note that this is usually done once in your application root file, so you don't need to do it every time you use the component.
To add localization, you must import import 'dayjs/locale/x'; in your application ( x is the locale name) and set locale either on DatesProvider or on each component individually.
Example of setting the locale on DatesProvider:
The code above works in all environments, except Next.js app router. If you are using Next.js app router, you must add 'use client'; to the top of the file where you are importing dayjs/locale/x – locale data is required both on client and server.