Select component experiencing misalignment of MaterialUI labels

My modal component is displaying a form with text inputs and select components, but the Select Labels are appearing at the top left corner of the form. I tried a solution from here, but it didn't work for me. Another issue is that when I click on one Select component, the other one seems to be linked and shows as focused. As someone new to Material UI (only using it for a few days), I find this challenging. Additionally, the Select on the left is not aligned with the Text input.

Below is the Dialog/Form code. Please ignore the Select onChange event functions.

            {/* Modal Dialog to add the Form*/} 
        
            <Dialog maxWidth="100" open={createOpportunity} onClose={handleDialogClose}>
                <DialogTitle align='center' id="form-dialog-title">Add New Opportunity</DialogTitle>
                <FormControl className={classes.formMainClass}>
                    <div className='formDivs'> 
                        <TextField autoFocus margin="dense" id="name" label="Opportunity Name" type="text" fullWidth/>
                        <TextField margin="dense" id="address" label="Address" type="text" fullWidth/>
                        <TextField margin="dense" id="city" label="City" type="text" fullWidth/>
                        <div className='state-zip'>
                            <InputLabel htmlFor="state">State</InputLabel>
                            <Select fullWidth inputProps={{id: "state"}} value={value} onChange={event => setValue(event.target.value)}>
                               <MenuItem value="">Empty Value for First Option</MenuItem>
                               <MenuItem value="Hey">Hey</MenuItem>
                            </Select>
                            <span> </span>
                            <TextField margin="dense" id="zip" label="Zip" type="text" fullWidth/>
                        </div>
                        <TextField margin="dense" id="architect" label="Architect" type="text" fullWidth/>
                        <TextField margin="dense" id="consultant" label="Consultant" type="text" fullWidth/>
                        <TextField margin="dense" id="duedate" label="Due date" type="date" fullWidth InputLabelProps={{shrink: true}}/>
                    </div>
                    <div className='formDivs'>
                        <InputLabel htmlFor="manager">Manager</InputLabel>
                        <Select fullWidth inputProps={{id: "manager"}} value={value} onChange={event => setValue(event.target.value)}>

                        </Select>
                        <div className='state-zip'>
                            <InputLabel htmlFor="status">Status</InputLabel>
                            <Select fullWidth inputProps={{id: "status"}} value={value} onChange={event => setValue(event.target.value)}>

                            </Select>
                            <span> </span>
                            <InputLabel htmlFor="source">Source</InputLabel>
                            <Select fullWidth inputProps={{id: "source"}} value={value} onChange={event => setValue(event.target.value)}>

                            </Select>
                        </div>
                        <TextField multiline rows={4} rowsMax={Infinity} margin="dense" id="description" label="Description" type="text" fullWidth/>
                        <TextField multiline rows={4} rowsMax={Infinity} margin="dense" id="notes" label="Notes" type="text" fullWidth/>
                    </div>
                </FormControl>
                <DialogContent>
                <DialogContentText>Opportunities text.</DialogContentText>
                    
                    </DialogContent>
                    <DialogActions>
                        <Button onClick={handleDialogClose} color="primary">Cancel</Button>
                        <Button onClick={handleDialogClose} color="primary">Save</Button>
                    </DialogActions>
            </Dialog>

Code for the Styling

.opportunities {
    display: flex;
    align-content: center;
    justify-content: flex-start;
    align-items: center;
    width: auto;
}

.top-buttons {
    margin-top: 15px;
    margin-bottom: 0;
    width: 90%;
}

.formDivs {
    width: 50%;
    margin: 1% 3%;
}

.state-zip, .manager {
    display: flex;
    flex-direction: row;
}

https://i.stack.imgur.com/sNaBO.png

I would greatly appreciate any advice, comments, or suggestions.

Answer №1

the problem you're experiencing may be due to incorrect usage of the FormControl element. This element is specifically designed to provide additional control or functionality for individual form inputs.
To resolve this issue, make sure to wrap your input elements with FormControl separately if you intend to utilize its functionalities. It's recommended to use div or form as a wrapping element instead of FormControl in your current code (preferably form).

Here is a relevant answer

You can also check out a functioning demo using the form tag here:
https://codesandbox.io/s/crazy-shape-0gzzd?fontsize=14&hidenavigation=1&theme=dark

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

Broken Mui Input - Full width with attributes for minimum and maximum values

I've created a sandbox to demonstrate an issue I came across that seems unbelievable, but it's happening. Here's the link: https://codesandbox.io/s/nifty-swanson-yxj4n2?file=/NumberField.js:1075-1097 The problem is simple - when both the ht ...

What is the appropriate event type to pass to the onKeyPressed function in a React application utilizing MaterialUI and written with Typescript?

I am currently working on a React application using Typescript and MaterialUI, where I have implemented a TextField component. My goal is to capture the value of the input HTML element when the user presses the enter key. To achieve this, I have created ...

Tips on hiding bottom tabs when navigating to a route that is two levels deep

When a specific screen is active, I want the bottom tab bar to disappear. Using react navigation for this purpose. For example, when the "Insight Detail Adjustment" screen is displayed, I need the bottom tabs to be hidden. Currently, none of the solutions ...

Utilizing FlowRouter with React: Implementing conditional component rendering based on route

I am currently working on a Meteor application using React and navigating with FlowRouter. Within my main AppContainer, I have multiple components including a footer. class AppContainer extends Component { render() { return( <di ...

React JS component experiencing issues with Material UI modal functionality

Attempting to reproduce the material ui modal example has proven to be a challenge for me. Initially, I encountered an error stating "Cannot read property 'setState' of undefined" which I managed to resolve. However, even after resolving this iss ...

What are some ways I can improve the readability of this if-else function in Javascript ES6?

As a newcomer to React development, I am currently in the process of tidying up my code. One issue that I am facing is how to deal with a particular function while minimizing the use of if-else statements. const calculatePerPage = () => { if ...

Is there a way to align the Material UI mobile menu to the left edge of the screen?

Need help with this UI issue: Currently working on designing a mobile web app using React and Material UI. I'm struggling to get the sidebar menu to start from the left edge of the screen, as it seems to have an unwanted margin preventing it. Any sug ...

Encountering a problem in React.js and Typescript involving the spread operator that is causing an error

Could someone assist me with my current predicament? I attempted to work with TypeScript and utilize the useReducer hook. const initialState = { a: "a" }; const [state, dispatch] = useReducer(reducer, {...initialState}); I keep encountering an error ...

Creating an array with conditional elements in React involves utilizing the map method along with a conditional

My array, named tableFilterFields, looks something like this: const tableFilterFields = [ { label: "Start Date", name: "StartDate", type: FilterControls.DatePicker, defaultValue: new Date(new Date().setDate( ...

Tips for saving/downloading generated QR codes in React Native

Using this code allows me to generate QR Codes, but I am struggling with saving the generated QR Code in PNG or JPEG format. I have tried a few examples without success and I am continuing to try different methods. import React, { Component } from 'r ...

Issue with React Redux: Store dispatch not causing component update

I have recently implemented React Redux in my project, but I seem to be encountering some issues. Despite changing the state, the value remains the same. I attempted to use useStore(), but it does not take any parameters. Can anyone provide insight into wh ...

Multi-object retrieval feature in Material Dialog

I am encountering an issue with Material Dialog when confirming the action to "remove row" in a table. Initially, removing from the dialog works fine and deletes a row. However, after closing the dialog and re-calling it for the second time, the removal ac ...

Expo: A guide on integrating expo code into an existing Android project

I'm looking to enhance my Android app (which is built in standard Java) by allowing users to create their own 3D models. To achieve this, I want to incorporate a 3D viewer within the app so that users can view and interact with their creations. My pl ...

JavaScript PIP video feature

Currently, I am utilizing the requestPictureInPicture function to display the HTML video element in a popup window. However, I have encountered an issue where the size is restricted to approximately 920 x 540 when in Picture-in-Picture mode. I am wonderin ...

The issue of MUI components overlapping arises during window resizing

I am currently working on a chat component that includes both the chat display and message input fields. function Chat() { const chatBoxStyles = { bgcolor: "red", height: "70vh", mt: "1rem" }; const messageIn ...

Adding Material-UI icons dynamically in a React TypeScript project requires understanding the integration of imported icons

I have a collection of menu buttons with icons, stored in an array of objects. The icon names are saved as strings that correspond to Material UI icons: interface MenuButton { text: string, onClickFunction: Function icon: string } export defau ...

Having trouble rendering the React app; encountered an error: JSX contents are unterminated

I am currently facing an issue while trying to fetch data from an API in React using Axios. How can I ensure that useEffect functions properly? My objective is to create a page by fetching data from an API in React through Axios. I have designed a compon ...

State of redux form not reflecting changes in initialValues

I am struggling to set the values in my Redux-form correctly, as the input field does not display the assigned value. Can anyone offer assistance with this issue? Below is a snippet of my code: import React from "react"; import { Field, reduxForm } from ...

Whenever a socket event occurs, the state of Nextjs is automatically reset

I attempted to implement chat functionality into my Nextjs app. Despite following the documentation, the chat log gets reset every time a socket event occurs. Below is the code snippet: import { useState, useEffect } from 'react' import io from & ...

Using the `minDate` prop in Material-ui Datepicker will take precedence over the default null state

I am facing an issue with a component where the minDate in the material-ui Datepicker is taking precedence over the null value and setting the minDate as the selected value. Furthermore, it also triggers the onChange function automatically. Here is my comp ...