Tips for customizing the appearance of material-ui SelectField

Currently, I am utilizing material-ui alongside react with the version "material-ui": "^0.19.2". I am facing an issue while attempting to embed a SelectField inside a table. Although the functionality is working smoothly, there are two unexpected behaviors due to the margin and/or padding applied to the select component. Firstly, the table rows now adjust their height based on the select field, causing the entire row to appear taller than needed. Secondly, the alignment of other elements within the row is thrown off.

Here is a snippet of my code:

<SelectField
    value={ props.value }
    hintText="Select location.."
    style={ {
        width: 150,
        padding: 0,
        margin: 0
    } }
    onChange={ (event, key, payload) => this.updateLocation(event, payload, props.index, props.original.something) }>
        { ::this.createMenu() }
</SelectField>

createMenu = () => {
    const { locations } = this.props.list;
    return locations.map((location, i) => {
        return <MenuItem key={ i } value={ location } primaryText={ location } />
    });
}

If only I could manage the styling around the rendered component (TextField?), I would attempt to make it fit seamlessly. However, the style prop on the SelectField seems to affect only the dropdown list.

Alternatively, I could explore using a popover for the field and implementing a custom component to attach it to - although my attempts in this direction have not been very successful so far.

Answer №1

By utilizing the specified properties on the SelectField, I am able to achieve the desired outcome:

   <SelectField
          value={props.value}
          hintText="Select location.."
          style={{
            width: 150,
            height: 15,
            lineHeight: 15,
            position: 'relative',
            textAlign: 'center',
            fontSize: '0.9em'
          }}
          menuStyle={{
            position: 'absolute',
            top: -12.5,
          }}
          underlineStyle={{
            position: 'relative',
            top: 20,
          }}
          onChange={(event, key, payload)=>this.updateLocation(event,payload,props.index,props.original.something)}
        >
          {
            ::this.createMenu()
          }
        </SelectField>

If there is a more optimal approach, please feel free to share it in an answer. For now, this solution adequately addresses my question.

Answer №2

<b>To limit the maximum height to 200px, insert maxHeight={200} within the SelectField component.</b>

<SelectField
multiple
fullWidth={true}
value={this.state.candidate_profile_arr}
onChange={this.handleChange}
maxHeight={200}
>
{this.state.profile.map((profile, i) =>
<MenuItem value={profile.id} key={i} primaryText={profile.name} />)
}
</SelectField>

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

Click the button to access the provided link

I need to add a link for redirection to some buttons. Here is an example of the button code: <Tooltip title="Open New Ticket"> <IconButton aria-label="filter list"> <AddTwoToneIcon /> </IconButton> </T ...

Tips for retrieving react-cookies when CORS is restricting access

Using react-cookies, I am trying to transfer data from the client side to the server side. However, when examining the request in NodeJS, I cannot locate any cookies in the headers or elsewhere. It seems that the cookies may not have been sent. After some ...

What can I do to resolve the problem with td border

Check out my website over at browsethewebclean.com I've come across a peculiar issue with the borders and background color of some nested tables on my page. It seems that the border is not aligning properly and the background color goes beyond the im ...

What steps can I take to make sure that a sub component's props are refreshed properly?

I'm encountering an issue with RTK queries in my project. I have a parent component that contains a table component. When a refresh event occurs, such as deleting data, the parent component receives updated data and passes it down to the child compone ...

What is the proper way to add comments within CSS code inline?

Can anyone provide instructions on how to comment an inline css property, such as height, in the following code snippet? <div style="width:100%; height:30%;"> Any help is appreciated. Thank you! ...

Unable to apply border attributes to AntTable row depending on the record value

I am trying to apply conditional border attributes to certain rows in my AntTable component using React. While I have successfully changed other attributes like background-color, width, and height using rowClassName, I am encountering issues with the bor ...

The content in the footer is not displaying correctly (Vuejs)

I recently developed a component with a title and a background color meant to cover the entire page, but it seems to have a top margin that I can't seem to remove. Additionally, I created a footer component that should always stay at the bottom of the ...

Increase the dropdown size without altering the dimensions of the container

I have a dropdown menu enclosed in a div with a vibrant yellow background. Take a look at the code on Plunker here. Upon clicking the dropdown button, the list expands and the container's height increases as well. The background color of the dropdown ...

Tips for integrating hls.js into your React application

Can someone provide guidance on how to integrate hls.js with React? I'm facing an issue where I can successfully fetch the m3u8 from an API and make it work in a basic HTML setup using the <script> tag, but when trying to implement it in React, ...

Mastering the art of combining images and text harmoniously

I am having trouble aligning my lion image and h1 tag side by side. There seems to be an issue but I can't figure out what it is. h2 { width:50%; float:right; padding:30px 0px 0px 0px; margin:0 auto; } .lion { width:10%; float: left; paddin ...

What is the best way to animate my logo using JavaScript so that it scales smoothly just like an image logo

I dedicated a significant amount of time to create a unique and eye-catching logo animation for my website! The logo animation I designed perfectly matches the size of the logo image and can be seamlessly integrated into the site. The issue arises when th ...

The Docker build encountered an error due to confusion with MERN dependencies

Utilizing the MERN stack, this application is built with ReactJS, Node, and MongoDB. I have successfully created a docker container that runs the frontend, but unfortunately, an error keeps arising which I can't seem to pinpoint. The error message I ...

Using regular expressions to enable scientific notation in a numeric text field

I'm looking to create a validation system for numbers with scientific notation (using 'e', '+', '-', '.') using regex. I've tried some expressions but they are not working as expected. For Regular Numbers: ...

CSS Interactive Design Breakpoints

Do my Break points at 768, 480, and 225 provide enough support for a responsive design, or should I consider adding more? 768 + | Computer 480 - 768 | Tablet 225 - 480 | Smartphone 225 < | Phone / Mini Browser ...

Iterating through styles in a selector's attribute

I am creating a site map layout. Looking for a solution similar to this: ul.site-map li[data-level="1"] { margin-left: 50px; } ul.site-map li[data-level="2"] { margin-left: 100px; } ul.site-map li[data-level="3"] { margin-left: 150px; } This code ...

The chart refreshes whenever there is a change in the component's state

Whenever I click the button to use the changeState method, the state changes and the MoreInfo component appears. However, the chart is being drawn again as shown in this GIF: Below is the code snippet: import React from 'react' import './Ho ...

What is the best way to align a button to the right in Material-UI?

I've been experimenting with Material UI, but I'm having trouble aligning buttons to the right :( import * as React from "react"; import SvgIcon from "@mui/material/SvgIcon"; import Button from "@mui/material/Button" ...

The perplexity surrounding the concept of immutability in Redux

While studying Redux, I encountered some confusion regarding how the reducer updates the state. Consider this code snippet: const initialState = { counter: 0 }; const counterReducer = (state = initialState, action) => { if(action.type==="INCREASE" ...

Issue with combining overflow-x, Firefox, and JavaScript

In Firefox, an issue arises that does not occur in other browsers. To see the problem in action, please visit this example page: -removed- Try selecting a page other than the home page. The window will scroll to your selection. You can then scroll down u ...

Creating a form with a questionnaire style design using Ant Design: Step-by-step guide

Ant Design offers a feature called Dynamic Form Item which allows users to add and remove multiple fields. However, I am now looking to implement nesting in this functionality to create a form resembling a questionnaire where I can add multiple questions a ...