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

Resizing Wordpress images to uniform height within a Bootstrap flex-row with flex-nowrap styling

I have successfully integrated Bootstrap with a Wordpress Underscores Template. My goal is to create a horizontally scrollable container filled with images of equal height. Currently, I am facing an issue where the images within the scrollable container ...

The useContext hook was utilized in conjunction with useReducer, however, a child component is unexpectedly showing an

First and foremost, I want to express my gratitude for your unwavering support. As a newcomer to the realm of ReactJS, I am currently navigating through the development of a concept example for a product store that includes various filters in the form of ...

What is the method for retrieving the state within the fetching action in redux-thunk?

I am just starting out with react. I have a product component in my react app that displays all the product items. The fetch function from the server is managed using redux-thunk. However, I am facing an issue where I cannot access the state in my componen ...

What is a way to activate the onSelectionChange event only when the cursor moves without any changes in the input?

In my React Native app, I have a use case where I want to implement mentions. This requires calling a function on the onSelectionChange event only when the text in the input remains unchanged but the caret position has moved. Currently, the onSelectionCha ...

The specified container is not a valid DOM element

Recently, I decided to implement Redux into my React application. However, as I began setting everything up within my index.js file, I encountered an error message: https://i.sstatic.net/4kL2T.png. After some research, I learned that this error is related ...

What causes the background to shift as I scroll?

Whenever I scroll, the background image text seems to stick around no matter where I move on the page. Is there a way to keep it fixed in one place? .bg-image { background-image: url(../construction/3.jpg); filter: blur(8px); -webkit- ...

Add the onmouseover attribute to dynamically alter the text

I'm trying to add the onmouseover function to the image of Angelina Jolie in order to change the text above, which currently says "Your Daily Dose of Contrabang". What is the best way to achieve this? Thank you for your assistance. You can check out t ...

fade in and out twice (for beginners)

Jquery <script> //Code snippet $(document).ready(function(){ $(".team").click(function(){ $(".panel").fadeToggle("3000"); }); $(".team").click(function(){ $(".teamh").fadeToggle("3000"); }); }); </script> HTM ...

Handling events for components that receive props from various components in a list

In my code, I have a component called PrivateReview which includes event handlers for updating its content. export default function PrivateReview(props) { const classes = useStyles(); const removeReviewAndReload = async () => { await ...

Tips for overlapping children in a column flex direction while maintaining the parents' positioning

Currently, I am working with two parent flex items, arranged with flex-direction: column. Within the first parent, there are two children. However, one of the children is optional and may be removed at times. I aim to have the optional child displayed on ...

Navigate to the appropriate directory specified in the package.json file

Here’s a breakdown of my project structure: Project client server I am currently facing an issue while trying to start both my Node Express Server and React project at the same time. The express server starts successfully, but I am unable to navigat ...

Formatting tabular rows to appear as headers

I am currently developing a mobile website that is specifically designed for older phones with minimal CSS and HTML support. Due to these limitations, I have decided to utilize tables in my design. My goal on a certain page is to create a table row with a ...

Guide to using spyFn for testing components in React Jest

I have a component called Actions that I want to test by passing actions to children. Each source (like Twitter or Facebook) has its own set of actions, and I want to verify if they are being called using spies. Here is the code for my Actions component: ...

Mouse over effect to highlight the crosshair on a table

My code currently enables a crosshair function, but I am looking for a way to limit the highlight effect only within the cursor (hover) area. Instead of highlighting in a "cross" shape, I would like it to show a backward "L" shape. This means that the hig ...

What are the style attributes that can be edited in each ant design component?

My goal is to customize an ant design card by adding a border only on the left and right sides of the card. The bordered attribute in the card component seems to either remove the entire border or display it on all sides. I am looking for a way to specif ...

Ensuring consistent placement and scrollability of two divs across all screen sizes

I am in need of a solution to fix the top and bottom divs in the given image. The scroll should only occur when there is overflow. <!DOCTYPE html> <html> <head> <script src="//code.jquery.com/jquery-1.9.1.min.js"></script> ...

Utilize a personalized container for the slider's thumb within a React application

Is it possible to replace the slider thumb with a custom container/div in React instead of just styling the thumb or using a background image? I have found a codepen example that demonstrates what I am trying to achieve, but unfortunately I am having trou ...

Accessing UPI apps such as Google Pay through deep linking from a web application

I am currently exploring the possibility of deep-linking to individual UPI apps, like Google Pay, that are installed on a user's phone. The goal is for users to be seamlessly redirected to their preferred UPI app when they click on the respective icon ...

"Despite using the setHeader function in express.js to set a cookie, an empty cookie is still being

customer: <a href="http://localhost:3001/user/login">Login</a> server: const token = jwt.sign({ broadcasterId: user.twitchId }, process.env.JWT_SECRET); res.writeHead(301, { "Location": "http://localhost:3000" ...

Can you explain the meanings of <div class="masthead pdng-stn1"> and <div class="phone-box wrap push" id="home"> in more detail?

While working on styling my web pages with CSS and Bootstrap, I came across a few classes like "masthead pdng-stn1" and "phone-box" in the code. Despite searching through the bootstrap.css file and all other CSS files in my folders, I couldn't find a ...