Adjust the height of the dropdown list in react-select (React Material UI)

I recently added a dropdown feature using react-select to my project. However, I encountered an issue where the dropdown list was initially too large and taking up the entire page. I am looking for a solution on how to style the react-select dropdown list with a fixed height and add scroll functionality when it overflows. Learn more about react-select here

Below is a snippet of my code:

class Project extends React.Component {
  render() {
    const selectStyles = {
      input: base => ({
        ...base,
        color: theme.palette.text.primary,
        '& input': {
          font: 'inherit',
        },
      })
    };
    return ( <
      SelectN inputProps = {
        {
          name: 'headedByUserId',
          id: 'headedByUserId',
        }
      }
      classes = {
        classes
      }
      styles = {
        selectStyles
      }
      options = {
        suggestions
      }
      components = {
        components
      }
      value = {
        this.state.fields["headedByUserId"]
      }
      onChange = {
        this.handleChangeDropdown.bind(this, "headedByUserId")
      }
      placeholder = "select owner"

      /
      >
    )
  }
}

Answer №1

react-select offers a unique attribute

maxMenuHeight="200"

By utilizing this feature, the height of the dropdown list can be customized. Furthermore, if the dropdown is contained within a material dialog, you have the option to set the dialog property "overflow":"visible" in order for the dropdown to be properly displayed.

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

What's causing the `sx` prop to lag behind in performance?

According to MUI's own documentation, and this answer, components utilizing the sx feature exhibit noticeably slower rendering speeds compared to components using alternative styling methods. At first glance, it may seem that sx is simply a more conv ...

Simple linking inside a Div container

I'm working on a div that has the following markup: <div class="col-sm-12"> <p class="bg-info">Basic Information</p> </div> Here's how it currently looks: I want to add an 'Add /Edit' link to t ...

Subpar mobile performance on a React/Next.js website

Can someone assist me with improving my website's loading times? While the desktop version has a pagespeed ranking of 99, the mobile version only ranks 75. Click here to view the report on pagespeed.web.dev What steps can I take to improve this? I a ...

Facing difficulty observing Content-Disposition header in create-react-app project

I am using a create-react-app that is being served by express. Express is acting as a proxy for the app and all the application logic resides in CRA. My issue lies in calling an API to download a file. The API sends back a "Content-Disposition" header wit ...

scrapy css last-child selector unable to target text

I am currently facing a challenge in selecting and matching elements within an HTML document using CSS selectors in the Scrapy framework. My issue lies with extracting information from a specific field using the last-child selector. Below is the snippet o ...

Use jQuery to calculate the width of the wrapper and evenly divide it among the div elements inside

Seeking assistance with a dynamic div wrapper containing multiple inner divs. The number of inner divs will vary, requiring a script to determine how many are present and adjust their widths to fit perfectly within the wrapper. <div id="wrapper"> &l ...

Having trouble saving the server-sent cookie on the browser. Employing Axios on the client side

Here is my express code where I am utilizing express-session to manage storage and work with cookies. Since version 1.5.0, the module no longer requires cookie-parser to handle storing the cookie in req/res. The session data is stored in a PSQL database h ...

Tips for bridging the space between jumbotron and about section using Bootstrap

How can I eliminate the gap between the jumbotron and the about section? I have attempted to reduce the margin between the two sections, but it is not working properly. <section id="atas"> <div class="jumbotron jumbotron-flu ...

Material-ui allows for easy customization of text with a maximum of 2 lines and an ellipsis

When developing a reactjs app, I decided to use Material-ui for the design elements. One issue I encountered was trying to ensure that text in a card displayed exactly two lines. My current implementation works fine for short text that fits within one or ...

In React and Node Js, the setState function will return a value of NULL

My Node Js API utilizes a find function to retrieve data from the database, which works flawlessly and returns the results. However, when I pass this data into setState using React and Axios, it ends up returning null. Below is my API's find() functi ...

How to Align Text and Image Inside a JavaScript-Generated Div

I am attempting to use JavaScript to generate a div with an image on the left and text that can dynamically switch on the right side. What I envision is something like this: [IMAGE] "text" Currently, my attempt has resulted in the text showing ...

Using a Material-UI Switch component within a table layout

I've written the code below to showcase switch state in a table using Material UI. However, I'm currently facing a challenge on how to incorporate onChange behavior for each individual row's switches. Any suggestions on how I can achieve thi ...

Set a unique class for several elements depending on a given condition

Is there a way to assign a color class based on the element's value without looping through all elements? Check out my jsfiddle HTML <div> <ul> <li class="MyScore">90</li> <li class="MyScore"> ...

I am having trouble setting a component to show up as inline-block in Angular2

Within my Angular2 application, I am facing an issue with displaying multiple instances of a child component - app-video-container - in a grid layout using inline-block. The parent component generates these instances using an ngFor loop but they appear sta ...

Initial page load does not trigger dispatch of Redux state

I am facing an issue with my redux state not being dispatched when the page loads, even though there is a dispatch event when the Component mounts Here is a simple example illustrating my problem: export const SET_SITE_NAME = "SET_SITE_NAME"; A ...

When using Router.push() in next.js, the error TypeError: products.map is not a function may arise

Currently, I am implementing redux saga in my project. Here is how the state looks: const productList = useSelector((state: RootState) => state.productList); const { loading, error, products, page, pages } = productList; In the useEffect hook, I dispa ...

By utilizing the "order" property, I can arrange divs to start at the bottom and ascend as additional elements are added

Exploring the use of display: flex and order:, I noticed a curious behavior. When I set the order for my first div to 0 (order: 0;), it appears at the top of the page. However, as I add more divs with different orders, they initially show up in unexpected ...

Batch script prematurely ends when compiling .less files in a batch for-loop

Recently, I decided to try my hand at using batch scripts as a way to compile the .less files for my website into .css files before deploying. It seemed like an efficient solution for my needs. However, after successfully utilizing a for loop in my batch ...

What could be the reason my CSS styles are not taking effect when trying to flip an image?

I am facing an issue with an app that has a two-sided HTML element. The goal is to flip the element when a user clicks a button. I have been experimenting with different approaches without success. Here is the code snippet I have been working on: HTML < ...

End-to-end Testing Material-UI's Select Component Using Puppeteer

I am encountering difficulty in retrieving dropdown values (<MenuItem>) within the dropdown menu of a Material-UI Select component. The goal is to click on an input with id='x', wait for the dropdown to appear (a div containing ul and li e ...