Reputation: 223
I can't add my icon to the component.
https://codesandbox.io/s/materialuipickers-material-demo-forked-soctc
Upvotes: 22
Views: 39100
Reputation: 31
If you want to customize icon before passing to mui x date picker, you can assign arrow function which returns customized icon
import CalendarIcon"../Components/CalendarIcon";
//…
<DatePicker
slots={{
openPickerIcon: () => <CalendarMonthOutlinedIcon sx={{ fill: 'black' }} />
}}
/>
Upvotes: 1
Reputation: 915
Just add the openPickerIcon property in slots of DatePicker, DateTimePicker etc to acheive it. (For adding custom svg icon)
import CalendarIcon"../Components/CalendarIcon";
//…
<DatePicker
slots={{
openPickerIcon: CalendarIcon
}}
/>
Create an SVG Component
import React from 'react';
import calendarSVG from './../calenderIcon/calendar.svg';
const CalendarIcon = () => (
<img src={calendarSVG} alt="Calendar" />
);
export default CalendarIcon;
Upvotes: 2
Reputation: 81623
The slots
prop of DatePicker
lets you override the inner components including the OpenPickerIcon
, so this is how you override it:
import AccessibleIcon from "@mui/icons-material/Accessible";
//…
<DatePicker
slots={{
openPickerIcon: AccessibleIcon
}}
{...}
This is the list of icon components that can be customized:
{
leftArrowIcon?: elementType,
openPickerIcon?: elementType,
rightArrowIcon?: elementType,
switchViewIcon?: elementType
}
https://mui.com/x/api/date-pickers/date-picker/#slots
Upvotes: 52