What is the default margin for Autocomplete in Material UI?

Having just started with material-ui, I'm having trouble figuring out the margins of the Autocomplete. My form includes both Autocomplete and TextInput elements, but their positioning seems off to me. Is there some predefined margin box around Autocomplete that TextInput lacks? I had to adjust margin on the TextInput to align them, but now I have extra marginLeft on the Autocomplete that I don't want. I could add specific styling for it, but that messes up the sizing when zooming in.

The image clearly shows how the Autocomplete margin doesn't match the TextInput: https://i.sstatic.net/25A5U.png

Any guidance on this matter would be greatly appreciated.

Below is the code snippet:

import React, { useState, useEffect } from 'react';
import Autocomplete from '@material-ui/lab/Autocomplete';
import TextField from '@material-ui/core/TextField';
import Grid from '@material-ui/core/Grid';


export default function AddPurchase() {

    const [coinList, setCoinList] = useState([]);
    const [name, setName] = useState('');
    const [symbol, setSymbol] = useState('');
    const [date, setDate] = useState('');
    const [price, setPrice] = useState('');
    const [amount, setAmount] = useState('');


    const data = {
        name: name,
        symbol: symbol,
        date: date,
        price: price,
        amount: amount
    }

    const handleName = (e, value) => {
        if (value !== null) {
            setName(value.substring(0, value.lastIndexOf('-') - 1));
        }
        else {
            setName('')
        }

    }
    const handleSymbol = (e, value) => {
        if (value !== null) {
            setSymbol(value.substring(value.lastIndexOf('-') + 2));
        }
        else {
            setSymbol('');
        }
        console.log(value);
    }

    const handleDate = (e) => {
        setDate(e.target.value);
    }

    const handlePrice = (e) => {
        setPrice(e.target.value);
    }

    const handleAmount = (e) => {
        setAmount(e.target.value);
    }

    const getCoins = useEffect(() => {
        let mounted = true;
        fetch('http://127.0.0.1:5000/api/v1/coins/list')

            .then(res => res.json())
            .then(items => {
                if (mounted) {
                    setCoinList(items)
                }
            })
        return () => mounted = false;
    }, [])

    console.log(data)

    return (

        <form>
            <Grid container >
                <Grid item xs={12} md={3}>
                    <Autocomplete
                        id="get-coin"
                        noOptionsText={'Coin not found...'}
                        options={coinList.map(item => (`${item.name} - ${item.symbol.toUpperCase()}`))}
                        onChange={(e, value) => { handleName(e, value); handleSymbol(e, value) }}
                        renderInput={(params) => (
                            <TextField {...params} label="Add coin" margin="normal" variant="outlined" />
                        )}
                    />
                </Grid>
                <Grid item xs={12} md={3}>
                    <TextField
                        onChange={handleDate}
                        label="Date"
                        variant="outlined"
                        style={{ width: 250 }}
                        margin="normal"
                    >
                    </TextField>

                </Grid>
                <Grid item xs={12} md={3}>
                    <TextField
                        onChange={handlePrice}
                        label="Price"
                        variant="outlined"
                        style={{ width: 250 }}
                        margin="normal"
                    >
                    </TextField>
                </Grid>
                <Grid item xs={12} md={3}>
                    <TextField
                        onChange={handleAmount}
                        label="Amount"
                        variant="outlined"
                        style={{ width: 250 }}
                        margin="normal"
                    >
                    </TextField>
                </Grid>
            </Grid>
        </form>
    );
}

Answer №1

After discovering an unexpected styling within the App.css, resolving the issue by modifying or removing the conflicting styles corrected the misalignment.

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

Failure to append an object to the array occurs when submitting an HTML form

I am facing an issue with a form that is supposed to add input values to an array as objects when submitted. However, every time I submit the form, the console briefly shows that there is an array with one object, only for it to disappear. Below is the f ...

Transferring information among React Native screens (From Screen A to Screen B to Screen C)

Imagine this particular situation. Essentially, a MaterialTopTabNavigator is nested within a StackNavigator. The challenge at hand is how to effectively pass data from a function all the way to the MaterialTopTabNavigator. Keep in mind that the data has t ...

Checking if children have certain text using jQuery

My task involves filtering an HTML table. In order to accomplish this, I have created an 'each' callback for all 'tr' elements and check if any of their children contain a specific pattern. $("#filter").keypress(function() { var fi ...

popular standard HTTP header parameters used in ReactJS

When working with React, I want to add a custom header (user-id and auth) to the HTTP request so that it is included in all methods. How can I achieve this similar to how it is done in Angular? Appreciate any help, Raja K ...

Iterating through every image displayed on a webpage

Two inquiries: What is the best way to efficiently loop through every image on a specific webpage and open each one in a new browser tab? Similar concept, but instead of opening in a new tab, I am interested in substituting different images for the ...

Passing state from child to parent in React using the useContext hook

I'm currently working with a MetaTable Component that includes a LeftSidePanel wrapped with the UseContext. My goal is to open the panel when a button is clicked on the MetaTable (to display detailed information about a particular record). While my co ...

At times, an InvalidArgumentError occurs stating: "The 'handle' parameter must be a string."

I have incorporated 'React-google-login' into my React project and now I am working on an automated test to make sure it functions correctly. try { await driver.get("http://localhost:3000/"); await driver.wait(until.elementLocated(By.xpath(` ...

What are some strategies for consistently monitoring the visibility of my React application on the webpage?

I am looking for a way to ensure that a specific React application is always present on my website. If the URL is broken or if there is an error in the React app, I want to be notified. How can I continuously monitor a given URL to check if the page contai ...

What is the correct method for aligning to the right or left within the material-ui appbar using material-ui-next version?

Having trouble getting the login/logout buttons to float right using material-ui-next ("material-ui": "^1.0.0-beta.22"). It looks like they removed iconElementRight= from the api. Is the new solution to use <Grid> in the appbar? Seems a bit clunky. W ...

executing a function repeatedly upon being invoked in a child React component using useEffect

I have a situation where I need to handle API calls in my React components. Each ChildComponent should make a specific API call when clicked, and currently, the API call seems to repeat itself when a modal is opened or closed. I came across a discussion o ...

When implementing `useRouter().push()` in Next.js, it has the ability to refresh

I have recently started using a custom node server in my Next.js app. Previously, useRouter().push() was working fine without a custom server and providing a seamless single-page app experience. However, with the custom server, it now refreshes my applicat ...

"The TextInput component in ReactNative is preventing me from inputting any text

Experiencing issues with the iOS and Android simulators. Upon typing, the text disappears or flickers. I attempted initializing the state of the texts with preset values instead of leaving them empty. However, this caused the TextInput to stick to the ini ...

Stop Bootstrap IE menu from closing when scrollbar is clicked

When using IE, the dropdown menu closes when clicking on the scrollbar. However, it functions properly when scrolling with the mouse wheel. To see the issue in action and potentially offer a solution, you can visit this Codeply link: I'm seeking sug ...

Having a tough time navigating the Bootstrap upgrade from 2.x to 3.x - now my design is all out of whack

Upgrading my site to the newest version of Bootstrap has been quite the challenge. I'm noticing that despite the window size being the same, version 1 and version 2 of my site are displaying different @media sizes. What's going on? On the left i ...

Making a CSS table fit perfectly inside a container

After reading numerous recommendations on the subject, none of them seem to be effective in my particular situation. The issue lies with a table that is nested within a container ('div' element) as shown below: <div class="container"> ...

Is there a way for me to determine if I am accurately interpreting the content on websites?

I created this function to check for any changes on a website. However, I have noticed that it produces incorrect results when tested on unchanged websites. Can you help me identify the issue and determine if there is indeed a problem? Here's the code ...

What is the method to show text on hover in angularjs?

I'm a beginner in AngularJS and I'm looking to show {{Project.inrtcvalue}} when the mouse hovers over values. Can anyone guide me on how to achieve this using AngularJS? <table ng-table="tableParams" show-filter="true" class="table" > ...

Why am I receiving the message "Error: /api/products/undefined" instead of /api/products/1?

I am facing an issue where I am trying to retrieve data of a single product from "api/products/id" using Django Rest Framework and store it in the Redux state. However, when I refresh the product's page in my React application by going to "localhost:3 ...

Encountering a problem with the Material UI Autocomplete component when trying to implement

I am trying to integrate a Material UI autocomplete component with a checkbox component. Is there a way to have the checkbox get checked only when a user selects an option from the autocomplete? You can check out my component through the following links: ...

Trouble with displaying my three.js 3D model

I've tried multiple solutions I found, but none have fixed the issue of not being able to display 3D models. Many have suggested that it could be a problem with the camera, but so far I haven't been able to resolve it. Any assistance would be gre ...