Stop MUI multi-select from stretching parent flexbox beyond the limits of the screen

On small screens, selecting multiple items in a multi-select MUI element can cause the parent container to expand and require scrolling to view all selected items.

Is there a solution for this issue?

<Box
  display={"flex"}
  flexDirection={"column"}
  rowGap={3}
  sx={{
    mb: 1,
    px: 2,
  }}
>
  <FormControl>
    <InputLabel id="simple-select-label">
      Job completed by
    </InputLabel>
    <Select
      label="Job completed by"
      name="employeeID"
      multiple={true}
      id="simple-select"
      sx={{
      }}
      required
      value={values.employeeID}
      onChange={(e) => {
        setValues({
          ...values,
          employeeID: e.target.value,
        })
      }}
    >
      {employeesLists?.map((employee) => (
        <MenuItem value={employee.id} key={employee.id}>
          {employee.firstName} {employee.lastName}
        </MenuItem>
      ))}
    </Select>
  </FormControl>
</Box>

Answer №1

In order to resolve this issue, I implemented the strategy of using override nested components. You can find more information about it here: https://mui.com/material-ui/customization/how-to-customize/#1-one-off-customization

Adding this code snippet helped me rectify the problem by overriding the default styles. It should be included within the <Select> component.

                    sx={{
                      '& #simple-select': {
                        whiteSpace: 'normal',
                      },
                    }}
``

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

Tips and tricks for stopping a jquery animation

I have created a hover effect for list items. When I hover over an item, it triggers an animation using the .animate() method. However, when I move my cursor away from the item, the hover animation continues until it reaches its end point. Is there a way ...

Struggling to center a modal at the exact middle of the page using Bootstrap 5

My navigation bar has a button that, when clicked, triggers a modal to appear at the top of the page. I am trying to center it horizontally. Here is the HTML code: </button> <!-- </button> --> <div class="text-dark "> < ...

Is it possible to use a base64 encoded animated gif as a background in CSS

I embedded an animated gif into my CSS code like this: .magicBg { background-image: url(data:image/gif;base64,R0lGODlhAQBkAPcAAAAAAAEBAQICAgMDAwQEBAUFBQYGBgcHBwgICAkJCQoKCgsLCwwMDA0ND ... } This animated gif is set to play only once. However, after the ...

Using JavaScript to implement CSS3 with multiple background images

Is there a way to programmatically define multiple background images in CSS3 using JavaScript? While the common approach would be: var element = document.createElement( 'div' ); element.style.backgroundImage = "url('a.png') 0 100%, ur ...

Customize each carousel item by adding a unique background image to enhance the visual appeal

I'm looking to customize my Bootstrap carousel by adding unique background images to each item. Here's a snippet of my HTML: <!-- Start of carousel --> <div id="mainCarousel" class="carousel slide carousel-fade" d ...

Creating a unique and personalized dual-row navigation bar using Bootstrap

Currently, I am striving to achieve a "conflict free" two-row fixed-top navbar in Bootstrap 3. I am unsure if it necessitates two separate "navbars" according to the official Bootstrap definition. While I possess decent coding skills, my knowledge of the B ...

Ways to prevent image toggling when the mouse moves out of it or when the hover effect stops

I'm looking to toggle between two images on mouseover/hover and stop the toggling when hovering stops. Here is the HTML code I have: <div class="fader"> <img src="image1" /> <img src="image2" /> </div> This is the JQuery ...

Adding a custom class to a select2 dropdown: How can it be done?

I have customized select2 using CSS with its general classes and IDs. Currently, I am attempting to customize a specific class that will be assigned to select2 and then applied in the CSS. The problem lies not within the select itself, but within its dro ...

`Set the body height to equal that of the entire document`

Currently facing an issue on the test page when scrolling down: The body element is set to have a height of 100%, but it only takes up the viewport's height, not the entire document height. The goal is for the page to always display at 100% of the d ...

Material UI version 3 featuring minimal styling

I am currently working with Material UI 3 in React JS and I am interested in finding out how to incorporate Less styling for components. I am aware that Material UI primarily uses JSS, but I am curious about the correct approach for using Less. The type o ...

What are the steps to access ember paper icons without an internet connection?

I'm currently working on a web module using Ember Paper that I need to be able to use offline. However, when in offline mode, the Ember Paper icons are not displaying and only text is visible. Can someone assist me in making Ember Paper work properly ...

What are some techniques for integrating MUI v5 styles and Mui* classes into non-MUI components and elements?

In the previous version of Material-UI, version 4, it was possible to utilize the Mui* class names on various elements and see the styles from those classes applied, as long as the MUI components that use those classes were included somewhere (thus injecti ...

Troubleshooting MaterialUI: Is there a way to prevent the InputLabel text from disappearing when setting a background color on the Select component?

My goal is to change the background color on dropdown elements while keeping the default text visible. Currently, if I don't explicitly set a background color on the Select component, the text specified in the InputLabel displays correctly. However, o ...

Why is my link not being acknowledged by its parent <div>?

I am facing an issue where a <a> tag inside a <div> element is not being recognized properly, causing the <div> height to remain unchanged and not accommodate the link as intended. You can view my HTML/CSS code here: http://jsfiddle.net/ ...

What is the best way to send the value of a Select component from a child to a parent component in

Users have the ability to select a category, triggering the appearance of another dropdown menu based on their selection. I have created a separate component in a different file (.js) to handle this second dropdown. While I can see the data, I am wondering ...

Adjust the text orientation using CSS within an SVG element

Here is the SVG code snippet that I am working with: https://jsfiddle.net/danpan/m3ofzrc1/. It generates the image shown below. The image consists of two lines of text wrapped around a circle: HELLO_WORLD_1 HELLO_WORLD_2 I want to change the direction ...

Retrieve the value of material user interface buttons

I am facing a challenge with Material UI. I have two buttons with values, and I want to run a function that console logs the value when someone clicks on them. However, when using e.target.value in Material UI, it returns undefined. While searching for a ...

Toggle button in VueJS that dynamically shows/hides based on the state of other buttons

In my table, I have included options for the days of the week such as Everyday, Weekdays, and Weekend. Each row contains 2 select items to choose start and end times for updates. Additionally, there is a toggle button at the end of each row that enables or ...

Encountering a Module not found error with a ValidationError when trying to import an SVG file within a React

I've set up a manual Webpack 5 configuration for my React project with TypeScript. I am facing an issue while trying to import an SVG icon and using Material UI in the project. The error message I'm encountering is: Module not found: ValidationEr ...

Special design of a compact navbar (2 columns, each column including 2 rows of items)

I have designed a unique collapsed bootstrap navbar that showcases my menu items and social media icons in two separate sets. When expanded, everything looks great across all browsers, including IE11. However, when collapsed, the layout seems to be slight ...