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:

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

Setting up WebPack for TypeScript with import functionality

A tutorial on webpack configuration for typescript typically demonstrates the following: const path = require('path'); module.exports = { ... } Is it more advantageous to utilize ES modules and configure it with import statements instead? Or is ...

What is the best way to add a -webkit-transform to a div without affecting its enclosed elements?

Is there a way to apply a webkit transformation to a div without affecting the text inside? I need help with achieving this. Below is my current code: .main_div { width:200px; height:100px; background:red; margin-left:55p ...

Searching using ReactJS when the user changes the input

I'm facing an issue with the search functionality in my ReactJS application. Every time a user types a letter in the textfield, the "searchHandler" function is triggered, making multiple calls to the API for a single term like "Lorem". This results in ...

In a Twitter Bootstrap environment, the button cursor transforms into an I-beam when activated

After utilizing twitter bootstrap to construct a small blog site and integrating a third-party file upload application into the project, I encountered an issue. The CSS files in the file uploader style the "upload button," but when my cursor hovers over it ...

Unfortunately, I am unable to utilize WebStorm in combination with React

Struggling to set up a React project in WebStorm, it's not running and ESLint isn't recognizing it. Started a new React project with Node.js v16: Successfully created the React project: Encountering issues as ESLint is not recognizing the ...

How can I refresh the connections in socket.io using react/node without including the current one?

I am currently working on implementing socket.io for a basic chat messaging system. My goal is to update clients in real-time using socket connections, following this example: Client one - logged in as x, client two - logged in as y. So, client one should ...

A guide on how to efficiently retrieve all images stored in a specific directory

I attempted to showcase all the images from a single directory using jQuery, but unfortunately it is not functioning as expected. My folder setup includes an 'images' folder and a 'js' folder. I followed this question on Stack Overflow ...

Creating a simulated dropdown menu using only CSS

I was able to create a select menu using only CSS, following some code I found. However, I am now facing an issue with overlaying divs. Whenever I hover or click on the "select menu", all the divs below it move down. I've attempted to adjust the z-i ...

Bootstrap 3.2.0 Grid Column Creation Problem Identified

On my webpage using Bootstrap 3.2.0, I have a layout that includes dynamic column generation and content within those columns. However, I am facing an issue with this setup. Can anyone advise me on how to resolve it? Your help is greatly appreciated. ...

Select element from Material UI displaying horizontally

I'm brand new to Material Ui and currently tackling the implementation of their SELECT component. However, I am running into an issue where it is displaying in a row instead of a column. Am I overlooking something important here? const SelectDropDownC ...

Implementing a Search Icon in Input Field using Material-UI in React

Hello, I am currently utilizing material ui for my project. My goal is to display a search icon within an input field, similar to the image shown here: To achieve this functionality, I am referring to this API documentation. If you would like to take a l ...

Identify and correct improper or invalid HTML closing tags in Visual Studio Code

As part of my transition to Visual Studio Code from Adobe Brackets, I am looking to replicate the feature that highlights incorrect close markup in my code. This feature is particularly helpful in identifying duplicated </div> tags like shown in the ...

Creating borders around Material UI grid items can be achieved by applying a border style to the

import React from 'react'; import { makeStyles } from '@material-ui/core/styles'; import Paper from '@material-ui/core/Paper'; import Grid from '@material-ui/core/Grid'; const useStyles = makeStyles((theme) => ({ ...

Position the final list item in the column on the left side

Currently, I am facing an issue with creating spacing between li elements in a column layout. The problem arises when the last li in the column does not align to the far left edge of the column width. Take a look at the screenshot below for reference: Bel ...

Do not incorporate a div in the overlay

I have an image inside a container. When hovering over the image/container, overlay information is displayed (which is currently working correctly). The overlay should cover the entire container (the grey part) where the image is located. The product-tit ...

Dividing the z-index by half of the shape

I am trying to achieve the following shape: https://i.stack.imgur.com/Lr9gv.png So far, I have attempted the following code. How can I combine these elements together? .clal-loader{ display:flex; } .clal-loader div{ border: 10px solid #38477e; b ...

Exploring LZMA compression in conjunction with next.js

Is anyone familiar with using the lzma algorithm to compress video, photo, text, etc. in the Next.js framework? I have searched everywhere but couldn't find a solution. I haven't found a proper demonstration or answer anywhere. I would greatly a ...

Passing a state object in a POST request body, only to find it arriving empty at the Express server

I'm having an issue with my React form component when making a POST request. The body of the request is showing up as {} even though I'm trying to send my State object. Within my form Component, I am passing the state information to another Reac ...

The styles order definition in the Material-UI production build may vary from that in development

When using material-ui, an issue arises in the production build where the generated styles differ from those in development. The order of the material-ui styles in production does not match the order in development. In DEV, the material-ui styles are defi ...

Facing compatibility problems with JavaScript and Cascading Style Sheets in Google Chrome?

Welcome to the site . Let's address a couple of issues with JavaScript and CSS: Firstly, the JS code seems to be malfunctioning only in Chrome, throwing an error that reads: 'Uncaught TypeError: Object [object Object] has no method 'on prij ...