Achieving proper layout in Material-UI Autocomplete by splitting long words

Exploring the Material-UI autocomplete feature for the first time has brought some challenges my way. I am working with usernames, which have a specific length limit but could exceed the space available in the autocomplete view.

https://i.sstatic.net/O8t1I.png

Upon examining the sandbox and image provided, it is evident that longer words get cut off due to size constraints.

Hence, I am seeking a solution to either dynamically expand the dropdown's width based on option string length when clicked or implement a word-break for overly long words.

While experimenting with various methods in the sandbox, I have been unable to successfully handle text overflow or break lengthy words into new lines.

Check out the Sandbox Example

If anyone could offer guidance on resolving this issue, I would greatly appreciate it.

Answer №2

Solved the issue by including componentProps in the list of attributes passed to Autocomplete.

This adjustment ensures that the dropdown containing usernames is wider than the input field, with a width that corresponds to the maximum username length or a predetermined fixed length outlined in my code.

<Autocomplete
        id="select_user_history"
        options={users}
        value={selectedUser}
        // --------
        // this section rectifies the problem
        componentsProps={{
            paper: {
                sx: {
                    width: 160
                }
            }
        }}
        // --------
        getOptionLabel={e => e.name}
        .....
        )}
    />

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 to modify the color scheme of my webpage while utilizing Bootstrap?

As I delve into programming with Bootstrap, I encountered an issue while attempting to change the background color of my body. Even though I used the following CSS code: body { background-color: #eba; width: 100%; height: 100%; } The color change ...

The functionality of SpawnSync is hindered when attempting to integrate electron-builder

I've run into a problem with my react-electron application. When using electron-builder to build the binary, it gets stuck while calling "spawn." However, when I use "yarn start," the application runs without any issues. Can anyone offer some assistan ...

Struggling to implement CSS for second div onto selected item in the first div

As a beginner in Angular, I am seeking some guidance and examples. In my code, there are two divs. One is created using ng-repeat with an ng-click function to detect the clicked item. The other div below has CSS properties like style="width:100px; float ...

What is the best way to utilize a single Google Map component instance across multiple children?

Seeking a method to maintain the same Google Map instance throughout my entire app, as each map load incurs charges... Currently utilizing google-map-react. An instance of a new Map is created in ComponentDidMount, suggesting that it's important to k ...

Bizarre Drop-down Peculiarities

Having a perplexing issue where the 'search' list item is oddly shifted below the dropdown box only when it is displayed. The other list items remain in their correct positions. Any advice on how to resolve this? The appearance and functionality ...

The container holding the inner elements is slightly oversized by a couple of pixels

Check out this Plunker example. Hello everyone, I am currently working on fitting two inner divs (a title bar and a canvas) inside an outer div. These inner divs are generated dynamically and have specific fixed dimensions. Below is a sample code snippet ...

Tips for customizing bootstrap's fixed navbar-default to ensure that the list items align downwards:

Is it possible to customize the bootstrap fixed navbar-default so that the li elements align downward instead of at the top? If you have any corrections or custom solutions, I'd love to see them! Feel free to share your code on platforms like CodePen, ...

Providing a front-end developed using create-react-app through Flask

I have a Flask backend with API routes that are being accessed by a React single page application created using create-react-app. Everything runs smoothly when I use the create-react-app development server. Now, I want to host the built React app (using ` ...

Having trouble accessing the `style` property of undefined in React Material UI?

I am attempting to create a collapsible row within another row. Essentially, I display multiple rows containing pharmaceutical drugs and want users to click on a specific row to reveal the description of that drug. Although it seemed simple at first, my c ...

Switch up the color of the following-mouse-div in real-time to perfectly complement the color that lies underneath it

I am trying to create a div that changes color based on the complementary color of whatever is underneath the mouse pointer. I want it to follow the mouse and dynamically adjust its color. This functionality is similar to what Gpick does: https://www.you ...

Execute a simulated click on the Material-UI Tabbar using a programmatic approach or keyboard shortcut

In my electron/react application, I am implementing Material UI tabs in the following manner: <Tabs> <Tab label="View1" > <View1 /> </Tab> <Tab label="View2"> ...

Styling and Passing Props to Material UI Version 1 Autocomplete Component: A Guide

Seeking guidance on how to customize the new Material UI V1 Autocomplete component or how to pass props to it. Here's a link to a working example on CodeSandbox: https://codesandbox.io/s/xrzq940854 In my case, I'm interested in styling the lab ...

The function element.innerHTML is invalid when trying to assign an object value as an option

Hey there! I'm currently working on a JavaScript project where I have an input that retrieves text from an array. Each option in the array needs to be linked to an object so I can utilize its attributes. const data = [ { name: "SIMPLES NACION ...

Currently trapped within the confines of a Next.js 13 application directory, grappling with the implementation of a

I need to figure out how to export a variable from one component to layout.tsx in such a way that it is not exported as a function, which is currently causing the conditional check in the class name to always be true. Below is the code snippet: // File w ...

What is the best way to integrate ContextualMenu with Persona in Office Fabric UI React?

Currently, I am utilizing Office Fabric UI React to work on a project. My goal is to implement a ContextualMenu in conjunction with the Persona object. In this particular example, I am demonstrating how ContextualMenu can be applied directly to differ ...

How can I create a circular Datepicker in JavaFX?

Struggling with customizing my JavaFX application using CSS. Everything was going smoothly until I encountered the Datepicker. Despite trying various approaches, none seem to be working. Is there a way to round the Datepicker just like my TextFields? Here ...

Double dragenter events triggered before dragleave in HTML5 drag and drop functionality

Currently, I'm researching HTML5 Drag and Drop functionality by using this resource. However, I've encountered an issue with the dragenter event that seems to fire twice for child elements before the dragleave event. Because of this, the dashed b ...

Embedded tweets may occasionally lose their borders when viewed on various web browsers

My goal is to showcase a collection of responsive embedded tweets in rows of 2. Here are the key elements of the code that have enabled me to achieve this: HTML <div id="tweets"></div> <script src="https://platform.twitter.com/widgets.js" ...

MUI DataGrid Identifying Duplicate Rows

I'm encountering an issue with my Data Grid component from MUI when fetching data using axios. The console shows the correct data, but on the page, it only displays one result or duplicates. I suspect there might be a frontend problem, but I'm s ...

Error encountered while updating in the midst of an ongoing state transition, e.g. within the `render` method

class MyComponent extends React.PureComponent { constructor(props) { super(props); this.state = { obj: [], externalObj: [], }; } fetchData = (external) => { ... arr = arr.filter(a => a.toLowerCase().includes(&ap ...