When the flexDirection is set to row, Material-UI input labels will appear outside of

Currently, I am facing an unusual situation. In my code, I have incorporated 2 div elements within a FormControl, and everything appears to be working correctly with the input label for the Select. However, when I apply styling with flexDirection: 'row', the label gets misaligned as shown in the image below.

Update: I observed that commenting out the justifyContent property resolves the issue.

Here's the code snippet:

const useStyles = makeStyles((theme) => ({
    submitForm: {
        display: 'flex',
        flexDirection: 'row',
        margin: theme.spacing(1),
        justifyContent: 'space-evenly'
    },
    bacsInputs: {
        minWidth: '200px'
    }
}))

const DemoInventory = () => {

    const bacsInfoInputs = () => {
        return(
            <>
            <p><b>Enter BACS information below and click SAVE</b></p>
            <FormControl variant="outlined" className={classes.submitForm}>
            <div>
                <InputLabel clasName={classes.submitForm} id="demo-simple-select-outlined-label">Select BACS Unit</InputLabel>
                <Select
                    labelId="demo-simple-select-outlined-label"
                    id="demo-simple-select-outlined"
                    value={bacsUnit}
                    onChange={onChangeInput}
                    label="BACS Unit"
                    className={classes.bacsInputs}
                    >
                    <MenuItem value={'Product-1'}>Product-1</MenuItem>
                    <MenuItem value={'Product-2'}>Product-2</MenuItem>
                    <MenuItem value={'Product-3'}>Product-3</MenuItem>
                    <MenuItem value={'Product-4'}>Product-4</MenuItem>
                    <MenuItem value={'Product-5'}>Product-5</MenuItem>
                    <MenuItem value={'Product-6'}>Product-6</MenuItem>
                    <MenuItem value={'Product-7'}>Product-7</MenuItem>
                </Select>
                <p>Serial number input</p>
                <p>Part number input</p>
                <p>Location input</p>
                <p>Description input</p>
            </div>
            <div>
                <p>Deployment input</p>
                <p>Ship Date input</p>
                <p>Expected return date input</p>
            </div>
                <p>Save Button</p>
            </FormControl>
            </>
        )
    }
}

return (
     <Fragment>
       {bacsInfoInputs()}
     </Fragment>
)

Answer №1

Due to the inclusion of the classes.submitForm class in the FormControl element, the default style is being altered, resulting in a unique style for the selectbox.
It is important to note that FormControl elements are specifically designed for encapsulating input elements for added control and functionality. Therefore, it is recommended to only include Select and InputLabel elements within this element for optimal results.

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

A guide on effectively passing color props through Nivo ResponsiveBar

I'm using Nivo's responsive bar for my project. Currently, I can achieve the desired bar like shown in the image by directly setting the colors as follows. However, I would like to know how to set the colors either by passing props or through a f ...

Why is my component not triggering a rerender when the context gets updated?

I need to display a table after retrieving data from an API. I have implemented the Context API and a custom hook to update the context. The second useEffect function logs the retrieved data, confirming that the hook is functioning correctly. Although Re ...

Managing Flicker Effect by Implementing Theme Switching and Using Local Storage in Next.js with Ant Design

I've been working on a new feature to switch themes (light/dark) dynamically in a Next.js application using Ant Design. Successfully integrating the theme switch with a toggle switch and useState hook, I'm faced with the challenge of storing the ...

How can I make my modal box appear after someone clicks on selecting a college?

Can someone help me figure out how to display my modal box after clicking into the selecting list? I've already coded it, but I'm struggling with getting it to show up after the click event. Any assistance is appreciated! In the image provided, ...

Acquiring the selected value when the dropdown is modified in a React application

Upon selecting the year 2022, I faced an issue where the logged value did not appear in the console. Strangely, when choosing 2021 instead, '2022' was the value that got printed to the console. To remedy this, I attempted setting the initial stat ...

Having trouble with the Tooltip feature in Bootstrap versions 5.2 and 5.3 on my end

I've been working on building an HTML website using Bootstrap 5.2, and I followed the instructions in the Bootstrap documentation to add tooltips. However, I encountered an issue where the tooltips were not functioning as expected. When checking the ...

Using React hooks to manage state, the submit action is triggered on the second attempt from

I am currently working on an orders management system that includes an Order.js page with a Child Component called ProductsForm.js When I fill out the form to add products to the order, I utilize onChange to update the state using useState with the necess ...

Is there a way to declare the different types of var id along with its properties in Typescript?

I recently received a task to convert a JavaScript file to a TypeScript file. One issue I am currently facing is whether or not I should define types for the 'id' with this expression, e.g., id={id}. So far, I have tried: Even though I defined ...

Show real-time notifications for updates and releases on a React Redux application

I'm currently working on a react + redux app and I need to have the ability to dynamically display notifications or messages about new features/updates at the header of our application. These messages will be entered as text input in a component calle ...

Disable automatic focusing for a material-ui popover component

I am struggling to create a search match list that updates as the user types in their query. However, I am facing an issue where the input element loses focus to the pop-up. I have attempted to programmatically set the focus using refs, but I am unable to ...

Submit form only if the field value is valid

I created a form with an input field that captures the user's mobile number and validates it to ensure it begins with '0'. The validation process is functioning correctly, but I am encountering a problem when submitting the form. Even if the ...

The value returned by a component should remain consistent regardless of where it is invoked. Additionally, the main component in React should not re-render when the state of a sub-component is

I am looking to have the same value displayed in the Home function from the Component, without causing a rerender when the useState in Component is updated. import { useState, useEffect } from "react"; function Component() { const [count, setC ...

Converting RGB color values to HSL color values using a unique, randomized Javascript approach

On this site, I have added a random color overlay to the media-boxes. Check it out here Thanks to the helpful folks at stackoverflow, I was able to create this script: var getRandomInRange = function(min, max) { return Math.floor(Math.random() * (ma ...

Error TS2604: Upon importing the 'material-ui' button from one package into another

Our team is in the process of implementing a new front-end for our application by transitioning from standard react to typescript. As someone who is relatively new to development, I have been struggling with a particular issue for several days now. The set ...

Struggling to center a MatIcon within a MatButtonToggle component in an Angular project

I've been struggling to center the MatIcon in the MatButtonToggle, trying multiple methods without success. It may seem like a minor issue, but it's causing quite a bit of trouble for me. Can someone please guide me on how to make this adjustment ...

How to stop font-family and letter spacing from affecting the margin of div and ul elements in CSS

I'm facing a challenge with aligning a rotated div and an unordered list in a container. Adjusting the margin of either element does the trick, but changing font-family or letter-spacing globally affects the spacing between the two. Check out this JS ...

Vanilla JS method for resetting Bootstrap 5 client-side validation when focused

I'm currently exploring Bootstrap 5's client-side validation feature. However, I've encountered a usability issue with the is-invalid class. After clicking the submit button, this class persists until the correct input is entered. I would li ...

The `background-size` property in jQuery is not functioning as expected

I am facing the following issue: When I click on a div with absolute positioning, I want to animate its position, width, and height. In addition, I want to change the background-size using jQuery. However, the problem is that all CSS properties are updat ...

The border on the right side of the accordion does not continue down

After creating an HTML page with an accordion in one div and a menu in another, I added a simple border styling to the right side of the menu using CSS properties like height, border-right-width, border-right-style, and border-right-color. height:100%; b ...

"Endowed with improper dimensions, the BootStrap collapse feature

Yesterday, I posted about an issue with BootStrap and panel collapsables causing graph sizes to become distorted. The post was locked because there was no accompanying code. I have now created a code snippet for you all to see the exact problem I am facing ...