React.js Material UI Dropdown Component

Is it possible to modify the behavior of the dropdown in Material UI Select? I would like to customize the appearance of <ul> so that it does not resemble a pop-up.

My goal is for the selected item to be contained within the <li> element, similar to the layout shown in the second image below:

Here is the current Select Component of Material UI: https://i.sstatic.net/AbrdY.png

What I aspire to achieve is something like this: https://i.sstatic.net/F6Rzf.png

This is my code:

<FormControl
  variant="outlined"
  className={clsx(
    classes.formControl,
    success && classes.success,
    danger && classes.danger
  )}
  required={isRequired}
>
  <InputLabel>{label}</InputLabel>
  <Select
    value={value}
    onChange={e => handleOnChange(e)}
    // MenuProps={{ classes: { paper: classes.dropdownPaper }}}
    label={label}
    name={name}
    MenuProps={{
      classes: { paper: classes.dropdownPaper },
      anchorOrigin: {
        vertical: "bottom",
        horizontal: "left"
      },
      getContentAnchorEl: null
    }}
  >
    {options.map((opt, index) => {
      return (
        <MenuItem value={opt.value} key={index}>
          {opt.text}
        </MenuItem>
      );
    })}
  </Select>
</FormControl>;

Answer №1

I hope this information is useful to you:

Instead of searching within the textfield component section, I recommend navigating to the menu components section. Look for the selected menu component or a customized menu component where the items pop up above the button. Here is a link to guide you: https://material-ui.com/components/menus/

You can also consider customizing the "split button component," which already includes the desired features. Simply adjust the color as needed. For more details, visit the following link and scroll to the bottom of the page to find the "split button" component: https://material-ui.com/components/button-group/

I trust this will be helpful for your needs.

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

Looking to adjust the fill pattern dynamically

I previously implemented this code: Is there a way to modify the fill image on my 3 buttons to display in 3 distinct colors instead? ...

Dynamic content in a CSS animation that rolls credits as they scroll

Currently, I'm working on creating a credit scrolling effect that pulls data from the JustGiving API to display a list of donors. I have successfully populated the list of donors and connected to the API without any issues. However, the challenge lies ...

Convert an HTML file to .msg format or prevent the send button from functioning in Outlook messages

I am trying to figure out how to save an HTML file as a .msg format in order to send it later. The HTML is basically a mock of a regular email with just the basic features like from, to, cc, subject, and body. I'm not quite sure how to go about achiev ...

Creating a Dynamic Layout with Varying Items in an Array Using PHP

Suppose I provide you with an array of objects, where x represents the number of objects. How would you achieve the following using a grid system (bootstrap, foundation, etc.)? Loop over the array and generate something similar to: https://i.sstatic.net/ ...

Display a pop-up when hovering over a layer with react-leaflet

I am attempting to display a popup when hovering over a layer in react leaflet. Utilizing GeoJson to render all layers on the map and onEachFeature() to trigger the popup on hover, I encountered an issue where the popup only appeared upon click, not hover. ...

Encountering a type error with gatsby-plugin-dark-mode in a Typescript Gatsby setup

Issue with Layout warning in index.tsx when hovering: (alias) const Layout: ({ children }: Props) => JSX.Element import Layout Type '{ children: Element[]; }' is missing the following properties from type 'Props': theme, >toggle ...

What is the best approach to updating a single item within a list using React Context?

React context is great, but I feel like there's something missing in my understanding of it. Let's say I have a list of todos and its corresponding provider set up like this: const Home = () => ( <div className="container"> <T ...

focusing on two different sections with a single hover effect

Is it possible to modify the styles of two different divs using CSS when hovering over one div? #down-icn { position: absolute; bottom: 0; right: 25px; color: #fff; -webkit-transition: color 0.25s ease; border-color 0.5s ease; -moz-transition: colo ...

Navigating around web pages with Python and Selenium: How to interact with non-button elements through clicking

I am currently working with Python's selenium library and trying to interact with an element that is not of the button class. My browser/web driver setup involves Google Chrome. Below is my code snippet for reference: from selenium import webdriver ...

Issue with jQuery UI: Accordion not functioning properly

I have created a nested sortable accordion, but there seems to be an issue. Within the 'accordion2' id, the heights of each item are too small and a vertical scroll bar appears. The content of the item labeled '1' is being cut off, show ...

What is the best way to update state from a triple-layered object?

I am currently working with a nested object that I need to update using setState. Payloads export interface DentistPayload { croNumber: string; person: PersonPayload; } export interface PersonPayload { fullName: string; birthdate: string; cpfNu ...

Using objects and map in React with i18next

I am trying to figure out how to translate data that is stored in objects and exported as a separate file. I have two components: The first component is the city component: import React from "react"; import { useTranslation } from "react-i ...

The initial value for the `useState` is not defined at the

Here's a simplified version of my requirement that demonstrates the issue. The ColorBox component receives a prop called "isVisible" from the ShowColorComponent component, which is used to initially set the state of the ColorBox.visible variable. impo ...

Show button image beyond the limits of the hyperlink

Is it possible to create a button with a background image that changes on hover and when active, while also having the active state display an image that extends beyond the anchor's bounds? Check out my sprite here: The top half of the sprite represe ...

ReactJS: An error occurred - TypeError: this.state.items.map is not a function

As a beginner in ReactJS, I am working on my first project which is a To-Do List with drag and drop feature, add, delete, and edit functionalities. I encountered an error while trying to map an array upon submitting a text to add an item to the items array ...

Turning off FavIcon.ico Can Enhance Performance

element: Currently, I have two websites being hosted on AEM or cq5 with distinct domains. Both websites share the same favicon on the new domain. I have attempted to remove this in the head.jsp template, but the favicon continues to display. Despite remo ...

Error message: "Window object not defined during NextJS build process."

Why am I encountering a 'window not defined' error? I haven't referenced window or document in my code, and it runs without issues during development but throws an error during the build process. ReferenceError: window is not defined at ...

We were unable to locate an available port at xxx.heroku.com

I'm in the process of deploying a react frontend on Heroku. Initially, I encountered an "Invalid Host Header" error due to using the proxy in my package.json file. To address this, I created a .env.development file and specified the Host to my Heroku ...

Parsing HTML with a simple DOM parser

I am utilizing the simple php dom parser in my project. Within my loaded dom, there is a link that appears like this in html: <a href="...">Some const tesxt</a> I am wondering how I can utilize the find function to select this particular obje ...

No declaration file was located for the module '@handsontable/react' despite the presence of a 'd.ts' file

Embarking on a fresh project using vite+react+ts+swc by executing the command below as per the vite documentation. npm create vite@latest -- --template react-swc-ts Additionally, I integrated the handsontable library into my setup with the following comm ...