Dynamic Material UI TextField underline width using JSX in React

I recently encountered an issue while trying to add padding to my TextField component. I applied the padding to the root 'style' property, but it caused the underline to overflow beyond the designated area to the right by the same amount as the padding. The strange thing is that any padding applied to the left or right of the underline seems to be ignored, and it ends up spanning the entire width of the container element.

To remedy this situation, I decided to set a fixed width for the underline using the underlineStyle prop. However, this solution can become messy if the width needs to be adjusted frequently. My question now is how to express 'width: '100% - 5px' ' in JSX? Is there a way to achieve this using proper syntax?

<TextField
  inputStyle={styles.inputStyle}
  value={props.messageValue}
  name={props.name}
  onChange={props.handleFieldChange}
  errorText={props.messageError}
  floatingLabelText={props.floatingLabelText}
  underlineStyle={styles.underlineStyle}
  floatingLabelStyle={styles.floatingLabelStyle}
  floatingLabelFocusStyle={styles.floatingLabelFocusStyle}
  **underlineFocusStyle={styles.underlineFocusStyle}**
  style={styles.fieldStyle}
  >
    {props.children}
  </TextField>

underlineFocusStyle: {
borderBottom: 'solid 1px',
borderColor: grey50,
width: '95%'
},

Answer №1

try using 'calc(100% - 5px)' for the width.

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

Adjusting the spacing between the logo and navbar in HTML code

I am struggling to understand why this issue keeps occurring: I have thoroughly checked for errors, attempted multiple solutions, yet the problem persists. Please assist body { margin: 0; padding: 0; } .logo { margin: 0; padding: 0; } ul { li ...

React application fails to launch using "npm start" due to "out of memory" error in the process

I encountered an issue while trying to launch my React app using the command npm start. Initially, the app was integrated into a Firebase project and utilized Firebase Cloud Functions as its backend. However, it previously relied on a node server for the b ...

The ReactJS form fails to show any updates upon submission

Here is the code snippet I have been working on: const [messages, setMessages] = useState(messagesList); const [addMessage, setAddMessage] = useState({ messageSent: '', }); const addMessageChange = (event) => { event.preventD ...

A method for displaying monthly data in a single row

Hey there! I'm currently dealing with a data list stored in an array. The |arraycontains various objects` each with their own properties such as name, created-at, and more. My goal is to display all users who were created within a specific month in on ...

Is there a way to ensure that the line numbers displayed for JavaScript errors in Chrome are accurate?

I suspect either my webpack configuration or my npm run dev script are causing the issue, but I'm unsure of what exactly is going wrong. While running my application in development mode, I encounter error messages like: Uncaught TypeError: this.props ...

Change the color of an SVG image without CSS or altering the SVG file

Seeking advice on altering the color and properties of an SVG icon without CSS or directly editing the file. Does anyone have any insights? For instance: const style = { somestyle: { random style configurations } } <svgIcon className={somesty ...

Using the power of Selenium's XPath, we can easily navigate through a table to access

Looking for assistance in creating selenium xpath for the various column links within a table. Each row has a unique identifier and contains information about a product, including the name. Based on the product name, I need to locate other links within the ...

When you select one of the autofill suggestions, the background color of the MUI TextField component will switch to white

Alright, here's the issue at hand. The main problem is indicated by the title of this post. I have a component that consists of a standard MUI text field: <TextField onChange={(e) => { handleSetUserData(e); }} ...

Using ES6 to create a callback function that stores values in a Map

I've been trying to find an answer to this question by searching extensively, but haven't had any luck. Currently, I am developing a React app and faced with the task of storing the state, which happens to be a map, in a local variable. Here is ...

Error encountered when accessing color background in the state of Material UI

My eyes are feeling strained, and I'm working on implementing a slider that can adjust both the radius and color of a button. This sandbox successfully updates the radius. Here is the code: (Code content) Currently, my focus is on utilizing ...

Django and its compatibility with modal windows

I have developed a Django website that includes multiple items in a "for" loop. I need to delete a specific item by opening a modal window and passing the post ID (referred to as "get_post_id") to the modal window. However, I want the modal window to exist ...

Is it possible to integrate a personalized theme into react-dates?

Attempting to customize the styling of my react-dates DayPickerRangeController in Typescript using react-with-styles and Aphrodite. I have implemented the following code, mirroring the code found at https://github.com/airbnb/react-dates#interfaces: const ...

Manipulating class properties in AngularJS from a controller

I won't dwell on the reason for this (it's required to override some behavior in Angular Material that is causing issues in Safari), but here is what I am attempting to accomplish: HTML: <style> .changeme{ height: 300px; } </st ...

Tweaking react-lottie and SVG dimensions with CSS media queries: A step-by-step guide

I am currently working on a React project that involves displaying Lottie-react animations and SVG's. My main concern is making sure that these illustrations are responsive on my website. The components are stored in a .js file, which I import into m ...

JQueryUI dialog is falling short in terms of maximum width

I am experiencing an issue with a jqueryui dialog that I have defined with a maxWidth setting. $("#myDialog").dialog({ autoOpen: false, width: 'auto', maxWidth: 1000, height: 'auto', position: [2 ...

Closing an Electron Dialog triggers a refresh on my current page

I currently have an Electron application in place. It utilizes Bootstrap v4, Electron v2, as well as other node modules. One concern I am facing is related to a button that triggers an Electron dialog box where users can select a folder. Upon selecting th ...

Strange CSS/browser storage glitch

UPDATE: JUST REALIZED THIS ISSUE IS ONLY OCCURRING ON FIREFOX, NOT CHROME ANOTHER UPDATE: Oddly enough, this problem only occurs locally. When I push it to GitHub, everything works fine. So strange. I suppose that means it's not a major issue. On my ...

Styling with CSS: How to Adjust Word Wrap in a Container that Resizes Dynam

I'm struggling to ensure that long lines of text break and wrap correctly within a chat feature I am developing. The crucial elements in question are .chat__messages__item and .chat__messages__body (these are all contained within a parent element set ...

Is the navigation dropdown toggle triggered by both mouseout and when hovering off of it?

I'm looking for some assistance in modifying the code so that the dropdown menu not only hides on click, but also hides on mouseout and/or when another top-level menu button is hovered over. View jsfiddle example $(document).ready(function () { ...

Update all data replies in strapi

I'm trying to figure out the best approach for running a function before receiving any data from the API in order to modify the response. Although I could include the function in each controller, it would result in repetitive code. Using policies see ...