Different ways to adjust the height of the date picker in Material UI

I am attempting to customize the mui date picker, but I am facing issues with applying CSS styles to it. I have tried using both inline styles and external styling by assigning classes, but nothing seems to work. I specifically want to adjust its height.

<DatePicker
            sx={{height:'35px'}} //the height adjustment is not taking effect!!
            label="Due Date"
            className="DatePicker"
            renderInput={(params) => <TextField {...params} />}
            value={selectedDate}
            onChange={(newValue) => setSelectedDate(newValue)}
/>

Answer №1

In my recent experience, I encountered a similar scenario while utilizing the new @mui/x-date-pickers to adjust the size from medium to small.

To achieve this, I had to utilize the slotProps feature within the DatePicker component in the following manner:

<LocalizationProvider dateAdapter={AdapterDayjs}>
  <DatePicker slotProps={{ textField: { size: 'small' } }} />
</LocalizationProvider>

Refer to the documentation for more information.

Answer №2

To add a style, you must use the sx property within the <TextField> component and target the element with the class .MuiInputBase-input.

Below is the necessary code snippet. You can also access the codesandbox link to experiment with.

<DateTimePicker
      label="Due Date"
      className="DatePicker"
      renderInput={(params) => (
        <TextField
          sx={{
            "& .MuiInputBase-input": {
              height: "80px" // Adjust the height as needed
            }
          }}
          {...params}
        />
      )}
      value={selectedDate}
      onChange={(newValue) => setSelectedDate(newValue)}
    />

Update for version 6.xx of DatePicker:

<DateTimePicker
      label="Due Date"
      className="DatePicker"
      slotProps={{textField:{size:'small'}}}
       sx={{"& .MuiInputBase-input": {
          height: "80px"
        }}}
      value={value}
      onChange={handleChange}
    />

Answer №3

Consider using a different kind of date picker. You could try implementing the StaticDatePicker for instances where you need a data picker with a larger height:

<StaticDatePicker
  value={selectedDate}
  onChange={(newValue) => {
  setSelectedDate(newValue);
  }}
  renderInput={(params) => <TextField {...params} />}
/>

Answer №4

Here is a solution that worked well for me:

        <DatePicker slotProps={{textField:{size:'small'}}}
           sx={{"& .MuiInputBase-input": {
              width: "120px"
            }}} />

The answer provided by @Akis was not effective in version 6.18 of the software.

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

Is there a way for me to include a transition in the text of the picture's caption?

I've been attempting to incorporate a transition:1s; and transition the text to color:#0000. The specific text I'm working with is 'Joe Doe' in the image caption below my image. I've experimented with various placements in my CSS, ...

Enhance your images with a hover zoom effect while viewing an overlay on top

Is there a way to make an image still zoom in on hover even when it has an overlay using CSS? I am currently working with Bootstrap 5.2 Thank you in advance. .trip-card { position: relative; } .trip-card img { border-radius: 30px; } .overlay { ...

unable to retrieve data using ajax

Having some trouble with my ajax code that is supposed to print values: success: function(returndata) { $('#first').html("<div id='first' class='progress-bar progress-bar-primary' role='progressbar' aria-valu ...

Is there a way to make those three elements line up in a row side by side?

I'm working on a layout using HTML and CSS that will display two images on the left and right sides of the browser window, with text in between them. I want them all to be horizontally aligned within a container. Here is the code snippet: <div cla ...

Step by step guide on how to connect a stylesheet in CSS

Hey there, I recently attempted to link a style sheet in my HTML for the first time. Unfortunately, I encountered an issue where it didn't work. Here's the code I used: <link href="css/StyleSheet.css" rel="stylesheet" type="text/css" /> W ...

Devices are not displaying media queries as expected

@media screen (max-width: 750px) or (screen and (max-width: 750px) (-webkit-min-device-pixel-ratio: 2),(min-resolution: 192dpi)) { div.body, div.body div.links, div.body div.links div, div.footer, div.footer div { display: block ...

Within the .module.scss file, there exist multiple classes that are identical; however, only one classname is reflected

How can I differentiate elements with the same class name? :S In Next.js, only one column1 is generated for each end cell1, cell2 class, etc.. Is there a way to solve this??: className={styles.left.column1}, className={styles.left.column1.cell1}, className ...

"Creating a link to a button with the type of 'submit' in HTML - a step-by-step

Found the solution on this interesting page: In a list, there's a button: <form> <ul> <li> <a href="account.html" class="button"> <button type="submit">Submit</button> ...

The error message "Cannot read property 'match' of undefined (evaluating 'global.navigator.userAgent.match')" is occurring in a React

I recently downloaded a Time picker from react-times -npm (found the source code on github) After running the app, I encountered a syntax error stating "Undefined is not an object (evaluating 'global.navigator.userAgent.match)". I'm having troub ...

How the MUI Grid Component is Creating a Horizontal Scrolling Issue

Title. function DisplayTimes() { const styles = { sectionStyles: { height: 700, backgroundImage: `url(${image})`, backgroundSize: 'cover', backgroundPosition: 'center', ...

Tips for configuring JWT to have global validation

I have implemented authorization using JWT in React for the frontend and Django for the backend. Whenever an access token expires, I automatically refresh it using axios interceptors. If the refresh token also expires, the user is logged out. The tokens a ...

Is it possible to establish globally applicable values using CSS?

Is it possible to set global attributes within a wordpress site to override all instances of specific CSS styles across multiple locations for themes, 3rd party plugins and more? For instance, if I want to apply 'border-radius: 0px;' to all butt ...

Optimal Method for altering Material UI Icon's height

Placing two icons from Material UI Icons side by side in a row reveals that although their heights are both set to 24px, the actual height of the paths within each icon differs - one being 18px and the other being 22px. This inconsistency in height is not ...

React Prop Local Modal Redux

Just diving into the world of React and Redux, and I'm a bit lost on how to effectively utilize both local properties and redux properties simultaneously. After trying different approaches without success, I'm reaching out for guidance. My goal i ...

Having trouble entering text in material ui Textfield component in React?

One feature of my react application is a simple login dialog implemented in a Modal component. The code for the login dialog includes: import Jenkins_logo from "images/Jenkins_logo.svg"; import Typography from "@material-ui/core/Typography ...

Can I align HTML elements to the left side within a Material UI grid?

Utilizing material UI for the styling. Can an HTML element or Typography element be positioned to the left side of a Grid and still remain on the same line? Below is a brief code snippet: return ( <Wrapper> <form> <Gri ...

Tips for centering a <div> vertically within another <div> ?

I have a project to develop a shopping cart, and I am currently working on aligning my item total in the center of its container. Here is the code snippet I have so far: .itemInfo { display: table; width: 100%; } .itemTotal { display: table-cel ...

Tips on adjusting font size of element when using dark mode in MUI React Framework

I am currently using the makeStyles method in MUI for CSS. Now, I want to implement an if-else condition for dark mode and light mode. const useStyles = makeStyles(theme => ({ titleNew: { color: theme.palette.text.primary, marginBottom: '8 ...

Tips for bypassing the use of SetState in the componentWillMount method

I have implemented a Welcome Screen that I want to display to users only once. My approach involves using AsyncStorage to save the token, which then triggers a change in the state of ShowWelcomeSlides, allowing me to set up a condition. However, I encounte ...

Gulp does not generate any files

Hey there, I'm brand new to using node.js and coding in general. I recently attempted to convert SCSS to CSS using gulp. My gulpfile.js seems to be correct, but when I try running "gulp styles" in the node.js command prompt, I receive the following ou ...