How to eliminate borders from a specific textfield in Material UI

I'm in the process of creating an input field with an icon on the left side, similar to the design shown here:

https://i.sstatic.net/OK7wN.png

The input element has been successfully created. My intention is to place both the input and the icon within a grid layout, remove the border of the input, and include them in the grid container.

Unfortunately, I'm facing difficulties in removing the border. I attempted to utilize the spread operator but encountered errors in the process.

It's worth mentioning that there are other input fields within the same styles that require the border to remain intact.

Is there a way to eliminate the border specifically for this input field?

const useStylesCustom = makeStyles((theme) => ({
  root: {
    border: '1px solid #e2e2e1',
    overflow: 'hidden',
    borderRadius: 2,
    backgroundColor: '#fff',
    transition: theme.transitions.create(['border-color', 'box-shadow']),
    '&:hover': {
      backgroundColor: '#fff',
    },
    '&$focused': {
      backgroundColor: '#fff',
      borderColor: '#DFDFDF',
    },
    '&$error': {
      borderColor: theme.palette.error.main,
    },
  },
  focused: {},
  error: {},
}));

<Grid container>
  <Grid xs={2} style={{ alignSelf: 'center', textAlign: 'center' }} item>
    <img src="/img/usa_flag.svg" height="25" />
  </Grid>
  <Grid item xs={10}>
    <TextField
      fullWidth
      label='Phone number'
      variant='filled'
      value={lastName}
      style={{ border: '0' }}
      InputProps={{ classes, disableUnderline: true }}
      onChange={(e) => setLastName(e.target.value)}
    />
  </Grid>
</Grid>

Answer №1

To remove the variant and hide the border:

    <Grid container style={{border: "none"}}>
  <Grid xs={2} style={{ alignSelf: 'center', textAlign: 'center' }} item>
    <img src="/img/usa_flag.svg" height="25" />
  </Grid>
  <Grid item xs={10}>
    <TextField
      fullWidth
      label='Phone number'
      value={"lastName"}
      style={{ border: '0' }}
      InputProps={{ classes, disableUnderline: true }}
      
    />
  </Grid>
</Grid>

Check out this sandbox example.

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

The conventional method for including React import statements

I'm curious if there is a standard convention for writing import statements in React. For instance, I currently have the following: import React, { useState, FormEvent } from 'react'; import Avatar from '@material-ui/core/Avatar'; ...

Looking for a React library that offers both direct reading and mutating capabilities for state management?

My personal project could greatly benefit from using Valtio as the state management library for React. https://github.com/pmndrs/valtio Here are some advantages that I see: I can utilize the state object without worrying about unnecessary re-renders. Thi ...

Issue with useEffect() not receiving prop

Currently diving into the world of React and still in the learning process. I recently integrated a useEffect() hook in my code: import { fetchDetails } from "../../ApiServices/Details"; export interface RemoveModalProps { id: number; i ...

How do I position an element at the center of a div using CSS?

Here is some HTML code that I need help with: <div id='nav'><a href ='./?page=1'>1</a> 2 <a href ='./?page=3'>3</a> <a href ='./?page=4'>4</a> <a href ='./?page=5&ap ...

Customizing ArrowDownwardIcon within MuiTableCell in Mui v5

I am attempting to modify the default color of the ArrowDownIcon within a TableCell using global theming in the following manner: MuiTableSortLabel: { styleOverrides: { root: { '&&.MuiTableSortLabel-icon': { ...

Encountered an error with an unexpected token while attempting to upgrade React in a Next

I am looking to update my React 18 in a Next.js application. I followed the guidance provided in the official documentation here. npm install next@latest react@latest react-dom@latest However, when attempting to run npm run build, I encountered the follo ...

react-router-config - using various route paths to render a single component

I am currently utilizing the react-router-config package for my project, which can be found here: https://www.npmjs.com/package/react-router-config. In order to configure my routes, I have created a Routes.js file where I define my route configurations. He ...

Adjust webpage display with JavaScript

Utilizing the mobile-first approach of Zurb Foundation, I successfully created a responsive design. However, my client now requires a direct link labeled "View desktop version" in the footer for when the website is accessed on mobile devices or tablets. T ...

Is there a way to retrieve the setState function from React Context and establish it as the initial value within createContext?

I am currently working with a very basic react context that looks like this: import { FC, createContext, useState, Dispatch, SetStateAction, PropsWithChildren } from "react" export const UserContext = createContext<UserContextType ...

PHP submitting form saves zeros

I have encountered an issue with submitting a form entry provided by the user. Instead of storing the actual values entered by the user, the database is recording 0 as the input. I require assistance to rectify this problem. Below is my code snippet: & ...

Creating a nested or indented text list with MUI Typography is a breeze!

In my current setup, the data structure looks like this: const bullets = [ "Top Sports are:", "hockey", "soccer", "football", "Top Names are:", "liam", "noah", "jordan" ] Usin ...

Troubles with double borders in HTML's opaque border feature

I'm encountering an issue where opaque borders are overlapping each other, causing the alpha value to be twice as high as intended. This problem seems to only affect the first n-1 elements — the last child is rendering correctly. Check out the Cod ...

Discover the pixel width of a Bootstrap grid row or container using JavaScript

How can I calculate the width of a Bootstrap grid row or container in pixels using JavaScript? I am working with Aurelia for my JavaScript project, but I'm open to solutions in standard JS (no jQuery, please). Looking at the Bootstrap documentation, ...

What is the best way to transfer data from one function to another file in React without directly calling the component or using props?

filename - Header.jsx import { useEffect, useState } from 'react' import { getValue } from './Input' import TextField from '@mui/material/TextField'; export const Header = () => { const [search, setSearch] = useState( ...

What causes my React app menu to unexpectedly open while simply updating the state without any CSS modifications?

In the Header component, there is a button that triggers the toggleNav function in context.js when clicked. This function changes the state of isNavOpen from false to true, resulting in the opening of the navigation. Surprisingly, there doesn't appear ...

Image staying in place when browser page is resized

Half page browser Full page browser Hello everyone, I could really use some assistance with my program. I'm trying to figure out how to keep my robot in the same position when switching from a half-page browser to a full-screen browser. Currently, w ...

Is it possible to stack divs horizontally in a liquid layout while allowing one of the widths to be dynamic?

This is the code snippet and fiddle I am working with: http://jsfiddle.net/hehUt/2/ <div class="one"></div> <div class="two">text here text here text here text here text here text here text here text here text here text here text here te ...

Creating buttons with onClick property in React, calling a function

I am currently working on developing a calculator and need to include buttons for numbers 1 through 9. To simplify the process, I am approaching it from a more efficient perspective by creating a function that will generate all the buttons concurrently, ra ...

Error occurred when attempting to retrieve data from a REST API to a React application, resulting in an unhandled rejection and a TypeError

I'm in the process of creating an application where the Flask REST API takes two strings and generates a floating value as a prediction. My current objective is to establish a connection with the React app in order to display these predictions on a we ...

Utilize a react component with modified features

Currently, I am working on developing a shared npm package that contains React components for use in multiple projects. Within this package, I have created default snackbar components and a wrapper component that will display a specific snackbar based on t ...