The positioning of Material UI InputAdornment icons is located beyond the boundaries of the TextField input area

I am struggling to understand why my InputAdornment is not positioned correctly.

There doesn't seem to be any style in my code that would affect the location of the icon within the TextField (such as padding or flex properties).

Currently, the calendar icon does not align properly with the text field input line.

https://i.sstatic.net/5Mzbh.png

This is how I want it to look - but with a calendar icon instead of 'kg' :)

https://i.sstatic.net/6KuEd.png

Here are some snippets from my styles object:

const useStyles = makeStyles(theme => ({
    input: {
        '& input, textarea': {
            paddingTop: 8,
            paddingBottom: 12,
            fontSize: 15,
            marginTop: 15,
            '&:focus': {
                borderBottomColor: COLORS.BLACK
            },
            '&::placeholder': {
                fontSize: 15
            }
        },
    },
    ...
    dashboardInput: {
        '& .MuiInputLabel-root': {
            color: theme.palette.text.primary,
            fontSize: 16,
        },
        '& input, textarea': {
            borderBottom: `1px solid ${COLORS.BLACK}`,
            fontSize: 16,
            '&::placeholder': {
                color: theme.palette.grey[400],
            },
            '&:disabled': {
                color: COLORS.BLACK
            }
        },
        '& .MuiFormHelperText-root': {
            color: theme.palette.grey[500],
            fontSize: 10
        },
    },
   ...
    inputLimiter: {
        textAlign: 'right',
        fontSize: 10
    },
    ...
    },
}));

The relevant part of the component is shown below:

    <FormControl
        fullWidth
        className={classNames(classes.input, getInputStyle(appearance), {
            [classes.error]: error
        })}
    >
        <InputLabel shrink htmlFor={name}>
            <div className={classes.divcontrol}><div>{label}</div><div className={classes.redAsterisk}>*</div></div>
        </InputLabel>
        <TextField
            id={name}
            placeholder={placeholder}
            fullWidth
            multiline={multiline}
            rows={multiline ? rows : 0}
            type={type}
            style={style}
            inputProps={{
                maxLength,
            }}
            defaultValue={defaultValue}
            disabled={disabled}
            onChange={e => onChangeWithRightType(e)}
            InputLabelProps={{
                shrink: true,
            }}
            value={value}
            {...props}
            InputProps={{
                disableUnderline: true,
                endAdornment: (
                    <InputAdornment position="end">
                        <DateRange />
                    </InputAdornment>
                ),
            }}
            error
            helperText={helperText}
        />
        {maxLength && (
            <Typography variant="body2" className={classes.inputLimiter}>
                {value ? String(value).length : 0}/{maxLength}
            </Typography>
        )}
    </FormControl>

https://i.sstatic.net/834cO.png

Answer №1

In response to your inquiry, I recommend toggling the disableUnderline setting in InputProps to true.

InputProps={{
              disableUnderline: true,
              ......
           }}

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

Preventing toggling collapse or expand functionality in a material-ui accordion

I am working with a MaterialUI accordion that contains some icons. I have noticed that when clicking on two specific icons, the accordion expands or collapses. However, I do not want this behavior. Instead, I want a different event to occur upon clicking t ...

Align text vertically in the center to fill the entire containing view

When working with React Native, I have set up a Text element nested within a View: import React, { Component } from 'react'; import { Text, View, StyleSheet } from 'react-native'; export default class App extends Component { render( ...

Calculate the occurrences of numbers within a string in an array of objects containing a specific string each time an object is removed

I am facing an issue where I need to re-number strings based on their type, regardless of their previous number. For example, if I delete Oranges 2 from [Oranges 1, Oranges 2, Oranges 3], it should become [Oranges 1, Oranges 2]. This means the numbers shou ...

Displaying Material UI textboxes in multiple columns for dynamically created forms using ReactJs from an array

I am working with an API to retrieve a list of cars, and I have come up with the following code snippet to generate labels and textboxes for editing the car codes. {!carQuery.loading && carDefinitions?.map((car: ICarType, idx: number ...

Navigate to the top of the page using jQuery

Attempting to implement a simple "scroll jump to target" functionality. I've managed to set it up for all parts except the "scroll to top". The jumping works based on the tag's id, so it navigates well everywhere else, but not to the very top. He ...

Launch your React JS website on GitHub Pages

Recently, I successfully developed my first React JS application by utilizing the create-react-app command line tool. Prior to executing npm run build However, upon attempting to access the GitHub page at username.github.io/project-name/public, a 404 err ...

Font size determined by both the width and height of the viewport

I'll be brief and direct, so hear me out: When using VW, the font-size changes based on the viewport width. With VH, the font-size adjusts according to the viewport height. Now, I have a question: Is there a way to scale my font-size based on ...

Striving to implement a dynamic expand and collapse animation feature for a card in ReactJS

I'm attempting to create an expand and collapse animation effect on a card without relying on bootstrap or any external libraries. I have tried adding a transition property but it doesn't seem to work when the button is clicked. Here is the comp ...

Next.js - Anticipated that the server HTML would include a corresponding <div> within <div> tag

For a live demonstration, please click here In my current project, I am experimenting with creating a simple layout that adjusts based on the user's screen size. Specifically, on mobile devices, only the latest posts should be displayed. On desktops, ...

Animating slides with CSS Keyframes and React, incorporating toggle slide fade out and slide fade (back) in

I am seeking a solution for toggling a box (div) with slide-out animation and then sliding back in animation (in reverse) upon button press. My requirement is to have no animations during the initial page render. While I can successfully slide the box to ...

How to eliminate the bottom border in react-native-material-dropdown

I recently integrated react-native-material-dropdown-v2 into my project using React Native. https://i.sstatic.net/aKVfi.png Is there a way to eliminate the bottom border in this material dropdown component? My React Native version is 0.62.2. ...

Learn how to use the Firebase Adapter for Next Auth to easily sign in using your email and password

I am currently using next-auth along with a Firebase adapter for authentication, but I am uncertain about the correct way to sign in users. I do not want to utilize my Google account for signing in; instead, I have user accounts within a Firebase project a ...

Angular Material: Enhanced search input with a universal clear button

After searching for a cross-browser search control with a clear button similar to HTML5, I found the solution rendered by Chrome: <input type="search> The code that gave me the most relevant results can be found here. I used the standard sample w ...

Is it possible to coerce multiple Context Consumers into sharing their state?

Currently, I am utilizing the React Context API to avoid prop drilling in my application. My Context consists of a useState and various state-updating functions encapsulated within an object that is passed as the value prop of ActionsContext.Provider. The ...

Unforeseen issues arise when using material ui's Select component in conjunction with 'redux-form'

I am encountering an issue with a 'redux form' that includes a Select component from the latest material-ui-next. import { TextField } from 'material-ui'; <Field name="name" component={TextField} select > <MenuIte ...

Ways to conceal Bootstrap-designed elements behind a fullscreen overlay

I'm attempting to create a transparent layer to conceal the entire content of my page behind it. It works fine without the Bootstrap columns, but as soon as I add the columns for responsive design, it stops working (or maybe I'm just not understa ...

Show the 'No Records Found' message once a filter has been applied in the MUI DataGrid

NoRowsOverlay is failing to display when a filter is applied and no rows are left to show. Below is the code snippet: function customNoRowsOverlay() { return ( <GridOverlay> <div>No Rows</div> </GridOve ...

What is causing my div exchange using .class to fail?

Struggling to convert this code from working with IDs to Classes. The code reveals one Div while hiding another based on the onClick event. Originally, it was straightforward because the div location was absolute. In the classes version, I need to revea ...

Issue with <BrowserRouter>: TS2769: No suitable overload for this call available

I encountered this error and have been unable to find a solution online. As a beginner in typescript, I am struggling to resolve it. The project was originally in JavaScript and is now being migrated to TypeScript using ts-migrate. I am currently fixing er ...

Exploring the Angular TypeScript Method for Rendering Nested Objects in an Array

Within this array, I have a collection of objects that contain properties for model and color. My goal is to present these objects in a table format, with individual access to the color values. grp = [ {model: "CF650-3C", color: {Orange: 3, Black ...