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

Troubleshooting error in Next.js when adding "sizes" attribute to Image component with layout set to "responsive"

When you use the following code: <Image src="/images/lorem.jpg" height={150} width={850} layout="responsive" sizes="50vw" // <== ...

How can the data label name be displayed on the y-axis using recharts?

Issue: I've utilized recharts to create vertical bar charts, and here is the code I am using. import React, { Component, PureComponent } from "react"; import { Card, CardBody, CardTitle } from "reactstrap"; import { Bar, BarChart, Tooltip, ...

React/Redux Web Applications Hosting (front-end)

I'm grappling with something at the moment. Consider a scenario where I have developed a website or single-page application using React/Redux. Let's assume that there are no API calls involved, meaning it's solely focused on the front-end as ...

What could be causing the background color opacity of the HTML hr tag to decrease?

I am trying to modify the height and background color of the <hr> HTML tag. However, even though the height and color are changing, it appears that the background color opacity is decreasing slightly. What could be causing this issue? Here is my cod ...

In Vue, it is not accurate to measure overflow

I am working on creating an overflow effect with tagging that fades out at the beginning to provide a subtle hint to users that there is more content. Here is what it currently looks like: https://i.stack.imgur.com/fXGBR.png To achieve this, I added a fa ...

Unable to change the disabled color of the Fab material in UI

Unable to customize the appearance of the disabled button. Attempted the solutions provided in this GitHub thread Material-UI version: "@material-ui/core": "3.8.1", "@material-ui/icons": "3.0.1", const styles = theme => ({ ...

Is it necessary to specify the JavaScript version for Firefox? (UPDATE: How can I enable `let` in FF version 44 and below)

Our recent deployment of JavaScript includes the use of the let statement. This feature is not supported in Firefox browsers prior to version 44, unless JavaScript1.7 or JavaScript1.8 is explicitly declared. I am concerned about the potential risks of usi ...

What is the relationship between html, body, and window when scrolling through code?

I've been working on adding a scroll-to-top button to my website. After doing some research online, I came across this code snippet: $('html, body').animate({scrollTop:0}, 'slow'); It's interesting that they are trying to scr ...

Tips for passing parameters to a function in stateless React components!

I'm working with a component that looks something like this (a simplified version): const MyComponent = () => { const handleClick = param => { console.log(param); } return ( <Link to={'/'} onClick={handleClick} v ...

Generate text in reStructuredText with columns

I'm attempting to style a reStructuredText segment in the following layout: type1 : this type4 : this type7 : this type2 : this type5 : this type8 : this type3 : this type6 : this type9 : this I want to fill the page with tex ...

Encountering an issue with React Native where initializing a project with npx leads to a "

Running the command: npx react-native init MyApp An error occurred while downloading and copying the template. Error message: Cannot find module 'C:\Users\%%%%\AppData\Local\Temp\rncli-init-template-rVvcjE\node_ ...

Tips for adjusting the height of a jQuery UI widget control through CSS

I have implemented a jquery widget on my asp.net webforms and am trying to adjust the height of the select control from the default 22px to 33px. I noticed in Google developer that the height is originally set like this: The current height setting is loca ...

Show or conceal a child component within a React application

In my React render function, I am working with the following code: <div> <InnerBox> <div>Box 1</div> <HiddenBox /> </InnerBox> <InnerBox> <div>Box 2</div> & ...

Tips for automatically adjusting the height of the footer

Is there a way to dynamically adjust the height of the footer based on the content length inside the body? I've been exploring solutions like setting the position of the footer as "fixed," but it seems to stay at the bottom of the screen, which is no ...

Sticky header in React data grid

Is there a way to implement a sticky header for a data grid in react? I have tried various methods but haven't been able to figure it out. Any suggestions would be appreciated. You can find my code sandbox example here. #react code export const Styl ...

Is it possible to customize the border-radius for a Raised Button?

After attempting to apply the border-radius in this manner: const styles = { btn:{ height: 30, fontSize: 11, borderRadius: 50 } } I encountered an issue as the desired effect was not achieved. I have reviewed the document ...

Is there a way to display fontawesome icons in the navbar similar to those shown in the react-bootstrap documentation?

I'm attempting to display icons similar to the ones shown in the documentation found at but I'm having trouble achieving the same outcome: <Nav.Item> <Nav.Link className="text-white" target="_blank" href="#"> <OverlayTrigge ...

Adjust the width of the indicator on Tabs in Material-UI

Essentially, this is the functionality I am trying to achieve. The "indicatorClassName" attribute is not providing the desired result for me, and even after attempting to use the indicator from the provided CodeSandbox link, there was no change. Upon revie ...

Scaling Images using HTML and CSS

Hey there, I'm currently learning web development and running into a bit of trouble with creating responsive images. Can anyone give me some guidance on what changes I should make in the code below? Here's the HTML code: <div class="caro ...

The Label method in the Html helper does not display the id

The creation of the checkbox and its label was done using an HTML helper: @Html.CheckBoxFor(m=>m[i].checkExport) @Html.LabelFor(m=>m[i].checkExport) To customize the label, I added the following CSS in a separate file: input[type="checkbox"] + l ...