The height of the Material UI dropdown is displaying in an improper manner

I'm currently experimenting with the Material UI dropdown on my website, utilizing the react-select library. However, I've encountered an issue where the UI gets compromised when using an option that exceeds the width of the dropdown.

If anybody could provide some guidance or assistance, I would greatly appreciate it.

This is the react code snippet:

import React, { useState } from "react";
import "./styles.css";
import SelectDropdown from "./EditableDropdown";

export default function App() {
  const [description, setDesc] = useState("");

  const options = [
    {
      label: "a11 b33 c88 o99 t66 j44 z99",
      value: "a11 b33 c88 o99 t66 j44 z99"
    },
    {
      label: "Switches",
      value: "Switches"
    }
  ];

  return (
    <div style={{ width: "25%" }}>
      <SelectDropdown
        label="Description"
        value={description}
        onChange={setDesc}
        options={options}
      />
    </div>
  );
}

This is the code for the Editable component:

/* Code goes here */

For a more detailed view and interaction with the code, you can check out this sandbox link: https://codesandbox.io/s/editable-dropdown-ckf1r

Answer №1

If you're considering between using material-ui directly or EditableDropdown, I would recommend opting for material-ui as it offers more flexibility and fewer limitations.

Furthermore, utilizing a newer version of Material-UI is advisable for improved features and performance.

Below is a code snippet in Material-UI (V4.9.5) that achieves the desired functionality. You can apply CSS for styling if needed:

import React from 'react';
import TextField from '@material-ui/core/TextField';
import Autocomplete, { createFilterOptions } from '@material-ui/lab/Autocomplete';

const filter = createFilterOptions();

export default function FreeSoloCreateOption() {
  const [value, setValue] = React.useState(null);

  return (
    <Autocomplete
      value={value}
      onChange={(event, newValue) => {
        if (newValue && newValue.inputValue) {
          setValue({
            title: newValue.inputValue,
          });

          return;
        }

        setValue(newValue);
      }}
      filterOptions={(options, params) => {
        const filtered = filter(options, params);

        if (params.inputValue !== '') {
          filtered.push({
            inputValue: params.inputValue,
            title: `Add "${params.inputValue}"`,
          });
        }

        return filtered;
      }}
      id="free-solo-with-text-demo"
      options={top100Films}
      getOptionLabel={option => {
        // e.g value selected with enter, right from the input
        if (typeof option === 'string') {
          return option;
        }
        if (option.inputValue) {
          return option.inputValue;
        }
        return option.title;
      }}
      renderOption={option => option.title}
      style={{ width: 300 }}
      freeSolo
      renderInput={params => (
        <TextField {...params} label="Free solo with text demo" variant="outlined" />
      )}
    />
  );
}

// Top 100 films as rated by IMDb users. http://www.imdb.com/chart/top
const top100Films = [
  { title: 'Raiders of the Lost Ark', year: 1981 },
  { title: 'Rear Window', year: 1954 },
  { title: 'The Pianist', year: 2002 },
  { title: 'The Departed', year: 2006 },
  { title: 'Terminator 2: Judgment Day', year: 1991 },
  { title: 'Back to the Future', year: 1985 },
  { title: 'Whiplash', year: 2014 },
  { title: 'Gladiator', year: 2000 },
  { title: 'Memento', year: 2000 },
  { title: 'The Prestige', year: 2006 },
  { title: 'The Lion King', year: 1994 },
  { title: 'Apocalypse Now', year: 1979 },
  { title: 'Alien', year: 1979 },
  { title: 'Sunset Boulevard', year: 1950 },
  {
    title: 'Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb',
    year: 1964,
  },
];

For more information, visit: https://material-ui.com/components/autocomplete/ You can access the code here: https://codesandbox.io/s/gbljf

Please let me know if this solution serves 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

Attempting to extract the text within a table row cell by clicking on the cell directly following it

I am trying to extract the data from a table row when I click on a specific div within that row HTML: <td class="ms-cellstyle ms-vb2">10</td> <td class="ms-cellstyle ms-vb2"> <div class="ms-chkmark-container"> <div ...

Personalized text hues for your WordPress product page

As someone who is new to all of this, please keep that in mind :/ I decided to remove the "add to cart" button from my theme (blocksy) so I could insert my own buttons within the product page under the "short description" text. I needed two "download" but ...

tips for fixing npm bug in next js application

I am a project built on Next.js/React.js. During local development, everything functions perfectly and all updates reflect on the site as expected. I have deployed this project using Azure, with my repository hosted on Github Actions. Furthermore, I have s ...

Retrieving the latest state from the Redux storage in React-Native using the useSelector hook fails to provide the

I recently made the switch from the older version of redux (pre-2019) which utilized case and switch statements. The redux store updates correctly, as seen in the TextInput component. However, when I try to use the selected value from the updated redux sto ...

Unable to load the first tab in Material-ui V3 after fetching data or when the page loads

After using Material UI version 3 scrollable-tab and fetching data to load tabs and tab container, I encountered an issue where the first tab does not automatically load on page load. It requires a click in order to see the information. I have searched on ...

Assurance of access granted through token

Currently, I am working with jwt authentication that involves access and refresh tokens. However, a problem arises when the access token expires and a new access token is generated on the frontend (react). This process returns a promise. In the backend/ro ...

Immersive pop-up interface displaying a variety of embedded videos simultaneously

I am a beginner in JavaScript and I came across a CodePen that does exactly what I need, but it currently only works for one embedded video. What I aim to achieve is similar functionality, but with 6 videos. (function ($) { 'use strict'; ...

React Images: Carousel display issue with images not centered

Is there a way to center the selected image instead of it appearing on the left-hand side? Here is the current behavior: https://i.stack.imgur.com/SUWOK.jpg I am using the following packages in a sandbox environment with Next.js 11 and TailwindCSS 2.2.4: ...

Dynamic content in NextJS: First, statically render a page and then customize it with user-specific data

I need advice on how to handle a specific data fetching scenario with NextJS static page rendering. We have a page that showcases articles, similar to this example. The content is the same for all users (perfect for static rendering), but lock icons should ...

CSS: elements that are only visible when positioned above specific elements

Can we create an element that is only visible above specific other elements? For instance, in the following code snippet, I want the .reflection element to be visible only above the .reflective elements (located at the top and bottom) and not visible on t ...

What could be causing next/image to fail in resizing images post-release only on a local server?

We've encountered a strange issue with image optimization and we're curious if anyone else has experienced something similar. Within our code base, we have implemented the following code for rendering images: imageElements: screenshotImageUrls?. ...

What steps do I need to take to create npm packages specifically for react-native development?

Which programming languages are essential for creating npm packages that work on both android and ios platforms in react-native development? Can you suggest any helpful documentation or blogs for developing npm packages that support ...

Evaluating the conditional rendering of a React child component using Jest and Enzyme

I am currently working on expanding the test coverage for this particular file: import React, { useContext } from 'react'; import UserContext from '../../contexts/user'; import styles from './index-styles.scss'; const UserLog ...

"Modifying the state of the layout in React triggers a re-render of child routes displayed in

In my current project, I am developing a React application that utilizes a layout to display routes passed to it. The layout consists of a header and a sidebar that can be toggled open or closed. However, every time the sidebar is opened or closed, it trig ...

Issue encountered while compiling Next Js in Expo

Encountering an error while attempting to utilize Expo components in my Next.js project. I am using Expo with Next.js for web development and aiming to have both platforms share the same components. However, I'm facing this specific error: Module pa ...

What could be causing Jest to struggle with locating data-testid within the map function in React?

Having trouble testing the code below. When data-testid = 'w_1' is added to a separate deletable div, it works fine. What could be causing this issue? export default class App extends Component { clickTest(){ alert('hi'); } re ...

Issue with dragging and styling windows in Safari on iOS

When checking my website on Safari using an iPad or iPhone, I noticed that I can touch and drag left to right, causing the entire window to move and reveal the grey background behind it. Here is a link to my page. However, when visiting other websites, no ...

Uploading Boolean Values from Switch Input (React/Typescript)

I'm facing an issue while trying to post the state value of a switch input toggle control. Whenever I use the submitRecommendation() function through a button click, I encounter a JSON parse error: Cannot deserialize instance of `boolean` out of START ...

The Passport session function is successful when tested with Postman, however, it encounters issues when used with a browser

Currently, I am attempting to implement a login feature using React and Node. My approach involves utilizing axios to send requests from the front end and Express with Passport on the back end. The issue I am facing is that while this code functions smoot ...

The error message "Property 'value' is not present on type 'EventTarget & HTMLSelectElement'" indicates that the 'value' property is not recognized on the Event

Here is the code snippet that I am working with: interface IHandleSelection { (value: string): any | void; } interface IPipeChangeEventValueToFunction { (handler: IHandleSelection): (event: React.ChangeEvent<HTMLSelectElement>) => void; ...