Enhancing the appearance of the MUI DatePicker

I'm currently using a DatePicker component from Mui Lab and I'm attempting to customize the appearance of the Calendar component by incorporating some border or background color. Although I've tried utilizing the PaperProps prop for DatePicker, it hasn't achieved the desired styling effect. I'm puzzled as to why I can't simply apply an SX prop for this purpose

here is the calendar where I intend to include a border

import PropTypes from 'prop-types';
import { TextField } from '@material-ui/core';
import { alpha } from '@material-ui/core/styles';
import DatePicker from '@material-ui/lab/DatePicker';
import { AppBorderStyle } from '../theme';

export const DateField = (props) => {
  const {
    error,
    fullWidth,
    helperText,
    label,
    onChange,
    onBlur,
    placeholder,
    disabled,
    value,
    name,
    ...other
  } = props;

  return (
    <DatePicker
      PopperProps={{
        sx: {
          '& .MuiPaper-root': {
            backgroundColor: 'red',
            border: '1px solid black',
          }
        }
      }}
      onChange={onChange}
      renderInput={({ InputProps, ...rest }) => (
        <TextField
          {...rest}
          disabled={disabled}
          onBlur={onBlur}
          name={name}
          error={error}
          fullWidth={fullWidth}
          helperText={helperText}
          label={label}
          placeholder={placeholder}
          sx={{
            '& .MuiFilledInput-root': {
              backgroundColor: 'background.paper',
              borderRadius: 1,
              border: AppBorderStyle,
              px: 1.5,
              py: 0.75,
              transition: (theme) => theme.transitions.create([
                'border-color',
              ]),
              '&:hover': {
                backgroundColor: 'background.paper'
              },
              '&.Mui-focused': {
                backgroundColor: 'background.paper',
                boxShadow: (theme) => `${alpha(theme.palette.primary.main,
                  0.25)} 0 0 0 0.2rem`
              },
              '& .MuiFilledInput-input': {
                fontSize: 14,
                height: 'unset',
                lineHeight: 1.6,
                p: 0
              },
              '&.Mui-disabled': {
                backgroundColor: 'action.disabledBackground',
                boxShadow: 'none',
                borderColor: alpha('#D6DBE1', 0.5)
              }
            }
          }}
          variant="filled"
          InputProps={{
            disableUnderline: true,
            ...InputProps
          }}
          InputLabelProps={{
            shrink: true,
            sx: {
              color: 'text.primary',
              fontSize: 14,
              fontWeight: 500,
              mb: 0.5,
              position: 'relative',
              transform: 'none'
            }
          }}
        />
      )}
      value={value}
      {...other}
    />
  );
};

DateField.defaultProps = {
  disabled: false,
};

DateField.propTypes = {
  disabled: PropTypes.bool,
  error: PropTypes.bool,
  fullWidth: PropTypes.bool,
  helperText: PropTypes.string,
  label: PropTypes.string,
  name: PropTypes.string,
  onChange: PropTypes.func.isRequired,
  onBlur: PropTypes.func.isRequired,
  placeholder: PropTypes.string,
  value: PropTypes.instanceOf(Date)
};

Answer №1

It has come to my attention that you are utilizing an outdated version of mui, as you can verify here. For the most recent iterations of material UI components, we now import material components from @mui rather than @material-ui.

I am uncertain if the classes align with those in your current version. Nonetheless, it appears that the issue at hand is related to targeting an incorrect class for adding a border. You should focus on the MuiPickersPopper-root class to modify the border.

PopperProps={{
        sx: {'&.MuiPickersPopper-root': {border: '4px solid red'},},
      }}

I have devised a solution for DatePicker with a border available here. Enjoy!

Answer №2

Here's the updated method for achieving this on mui version 5:

slotProps={{
      popper: {
        sx: {
          ".MuiPaper-root": { border: "1px solid blue", borderRadius: "10px" },
        },
      },
    }}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Internet Explorer is unable to recognize the .less file format

I have created a less file that works perfectly in Chrome and Firefox, but it is not being recognized in IE 9. Does anyone have suggestions on how to make it run in IE 9.0? Below is a sample of the CSS code: @import "../core/variables.less"; @import "Mi ...

How about: "Interactive web form featuring customizable options to determine which fields are shown?"

How can I design a dynamic web form that changes based on selected options? This form will include standard fields as well as customized fields depending on the user's previous selections. There are approximately 120 different combinations of forms p ...

Transform all characters to lowercase, then capitalize them using only CSS

I came across a discussion on this topic at: First lowercase the text then capitalize it. Is it possible with CSS? However, the solution provided was not purely based on CSS. I have a div that contains the following text: <div> RaWr rAwR </div&g ...

How can you customize the transition of a drawer in your app?

I have a unique setup where I have two drawers, one on the left and one on the bottom. My goal is to create an interactive effect when the left drawer opens - specifically by increasing the marginLeft and reducing the width of the bottom drawer using some ...

A guide on updating the color of a Button component (Material UI) when dynamically disabling it

In a React table, I have a button that is disabled based on the value in an adjacent column. For example, if the value in the adjacent column is "Claimed", the button is disabled. However, if the value is "Failed" or blank, the button can be clicked. Curre ...

Obtain the name and current state of a checkbox in a React.js application

Upon clicking on a checkbox, I aim to retrieve the unique name (containing IDs from a GET API) and current value of the checkboxes (DefaultChecked containing values "true or false"). <td style={styles.gridrow}> {this.state.items.map ...

The React Bootstrap modal refuses to fully close no matter how many times I click away or even on the close button

I am facing an issue with a modal in my React component. When I open the modal, it does not completely close when I try to click away or hit the close button. The backdrop disappears but the modal itself remains on the screen. (Screenshots attached for r ...

How to exclude elements nested inside another element using CSS or XPath techniques

Presented here is a snippet of XML code: <xml> <section> <element>good</element> <section class="ignored"> <element>bad</element> </section> </section> </xml> Identifying a ...

After the custom drop down is opened and closed, the form input in React becomes unresponsive

Having trouble with a custom drop-down component in a form? I've been struggling to identify the issue all day. I've tried various solutions like using useRef and leveraging defaultValue from SO answers. The text input for 'Menu Name' ...

Enhance Bootstrap modals by automatically adjusting the background shadow mask when resizing or changing the content within the modal window

Incorporated within my bootstrap modal window is a form alongside a link that triggers the jQuery functionality of .slideToggle(). By interacting with this link, a concealed div expands. Consequently, the size of the modal popover becomes fluid. Upon click ...

I am experiencing issues with my Jest unit test case for Material UI's multi select component failing

I've been working on writing a unit test case for the material UI multi select component. The code for the parent component is as follows: import {myData} from '../constant'; export const Parent = () => { const onChangeStatus= (sel ...

Tips for preventing the appearance of two horizontal scroll bars on Firefox

Greetings, I am having an issue with double horizontal scroll bars appearing in Firefox but not in Internet Explorer. When the content exceeds a certain limit, these scroll bars show up. Can someone please advise me on how to resolve this problem? Is ther ...

Creating a versatile "successive snack bars" module using React and Material UI: A Step-by-Step Guide

In the Material UI documentation, there is a reference to "Consecutive Snackbars" but it lacks information on how to modularize this logic into a reusable component for use across our application. My technology stack includes React v18 and Material UI v5. ...

The requested property map cannot be found within the Array

I am working on a project using redux with react typescript. I have an external JSON file that contains employee data categorized by department id. To properly map the data with types in my application, I have created specific types. Check out this demo o ...

Tips on aligning text to the left on mobile devices using CSS and HTML

When viewed on a standard 16:9 computer screen, everything looks perfect with text on the left and an image on the right. However, when it comes to smaller screens like phones, the picture appears on top of the paragraph instead. I am new to this, so any a ...

Incorporating a unique font into your SAPUI5 application

While experimenting with an expense app design, I decided to incorporate a receipt-like font for a unique look and feel. After discovering the FakeReceipt font, I placed my woff and woff2 files in the same directory as my style.css file, and it worked like ...

Difficulty encountered in getting html email signature to appear correctly on Outlook

I have developed a personalized email signature using HTML. Here's the unique code: <html> <!-- Insert your company logo here --> <div id="far_left" style="width: 50px; height: 50px; float: left; ...

I'm trying to set an object value for this select element, and while I have managed to do so, I am struggling to display the title of the selected object. Can anyone help me

I am struggling to display the title of the selected object in this select element. Can anyone help me understand why my code is not showing the title? Here is the code snippet: const [selectedCategory, setSelectedCategory] = useState(""); const categor ...

Modify the CSS using JavaScript after a brief delay

I'm creating a homepage that includes animations. Inside a div, I initially have display: none, but I want it to change to display: block after a few seconds. I've been trying to use JavaScript for this purpose, but I'm struggling to find th ...

Leveraging the Power of SASS Variables Across Your Entire NativeScript Application

Currently, I am in the process of developing an app using NativeScript 6.4.1 along with Angular 8. In order to enhance my styling capabilities, I have decided to incorporate SASS due to its advantageous features like variable names. My designer has suppli ...