Using Material-UI to showcase a TextField with a labelWidth set to zero

I need to showcase a specific field on my website.

https://i.stack.imgur.com/PJUW7.png

However, the issue I'm facing is that even when the field is in focus, the border remains unaffected and does not get cut off by the label.

https://i.stack.imgur.com/uyL44.png

The TextField component from material-UI is what I am currently using for this task.

Answer №1

Your task is to:

  • Conceal the label (I'm currently doing it when a value is entered just for demonstration - feel free to remove it completely)
  • Finalize the border, meaning remove the legend using CSS

Applicable CSS:

legend { border: 1px solid red; display: none; }

Relevant JavaScript:

const styles = theme => ({
  cssLabel: {
    color: "green"
  },

  cssLabelHide: {
    display: "none"
  },
});

<TextField
        id="standard-name"
        label="Name"
        className={classes.textField}
        value={this.state.name}
        onChange={this.handleChange("name")}
        margin="normal"
        variant="outlined"
        InputLabelProps={{
          classes: {
            root:
              this.state.labelVisibility === true
                ? classes.cssLabel
                : classes.cssLabelHide,
            focused: classes.cssFocused
          }
        }}
        InputProps={{
          classes: {
            root: classes.cssOutlinedInput,
            focused: classes.cssFocused,
            notchedOutline: classes.notchedOutline
          },
          inputMode: "numeric"
        }}
      />

Check out a functional example on StackBlitz here

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

Error in React Toaster preventing redirect with useHistory() before reaching another page

When I try to display a message using react toaster and then redirect to another page using history.push('/'), the toaster fails to work properly. Instead, the page immediately redirects to the homepage without displaying the toast message first. ...

Unlocking the Secret to Rotating a GroundOverlay on Google Maps

I am currently working on a map project that involves adding shapes and locations onto the map and saving it. However, I am encountering an issue with groundoverlay rotation. Even though there is no built-in rotation property in the Google Maps documenta ...

I encountered an issue where the error "data.map is not a function" occurs whenever I try to execute a React component

I have implemented the HorizontalScrollbar component and passed data as a prop. When I try to run the HorizontalScrollbar component, I encounter the following error in the console tab of Chrome: Error: Uncaught TypeError: data.map is not a function Horiz ...

The React Component is caught in a loop of continuous re-rendering and reloading

Just starting out with React and tackling my first project. Running into a bit of trouble here, so I'm sharing my code for some insight. When users input their search term and hit 'search,' they are redirected from another page to this one. ...

Ways to ensure the axios call is completed before proceeding with the codeexecution

I need to use axios to send a request and retrieve some data that I want to pass as a prop to a React Component. Here's my render function: render() { boards = this.fetchBoardList(); return ( <div className="app-wrapper"> ...

Encountering errors while trying to integrate a custom npm package into a React project. Compilation

I recently followed a guide on Zell Liew's blog to create my own custom npm package at . The specific package I created can be found on npm at https://www.npmjs.com/package/demo-to-publish. Here is the folder structure of my custom package: src -&g ...

Managing class toggling using React's State Hook

Currently, I am working on creating a sidebar navigation menu using React and the State hook. Despite going through the documentation, I haven't been able to find an example that fits my exact requirement. All I want is to toggle a CSS class on click ...

Navigating the Basics: Understanding the Four Quadrant Selection Grid in a Material UI & React Pop-Up Form

Sorry if these questions seem silly. I'm diving into React & Material-UI without a mentor to guide me, relying on documentation and tutorials. Is there a better place for quick beginner questions? Maybe a chat forum or Slack group? Not sure if Stack i ...

Why is it that the bootstrap text color class isn't applying for my project?

After some experience with bootstrap, I have encountered an issue with the text-white class. Despite trying to change the text color using this class, it doesn't seem to work. Below is the code that I've been working on. Can anyone spot what migh ...

Encountering a Typescript error while attempting to extract state from a History object containing an enum property

My enum structure is as follows: enum values { first, second, } Within my component, I handle the history object like this: const { push, location: { state = {} } } = useHistory(); Additionally, in the same component within a useEffect hook, I have ...

Having trouble loading styles in Vue after publishing to npm

I'm currently using vue-cli3 for the npm publication of a Vue component. Below are my build scripts: "package-build": "eclint fix && vue-cli-service build --target lib --name @xchat-component/chat-component ./src/index.ts & ...

What is the best way to navigate and map through an array of objects, especially when encountering an empty object?

I am currently in the process of developing a bootleg version of Amazon with a focus on creating the Questions & Answers component. The issue I have encountered is that in my dummyData, there are instances where a product may not have any questions, lead ...

Enhance your AngularJS skills by incorporating multiple conditions into the ternary operations of ng-class

I am struggling to apply multiple classes when the condition in the ng-class attribute evaluates to true. Here is the code I have attempted so far, but it doesn't seem to be working: <div class="col-md-4" ng-mouseover="hoverButton=true" id="plai ...

Rotate image in Vue3 using @click

I have a dashboard with a refresh button that I want to rotate 360 degrees every time it is clicked. How can I achieve this rotation effect on the image with each click of the refresh button? Below is the code snippet I have been working on, but it only r ...

Adjust padding dynamically as the screen size changes

In the setup I'm working with, each section is contained within a div that carries a container class. There are intentional sections in between that extend beyond the screen's view. My objective is to have these sections align with the left side ...

Creating interactive and adaptable maps

Currently, I am working on making a Joomla website responsive. However, I have encountered an issue with the SobiPro Map. The problem arises when displaying a map (background img) and points (a link + img) over it with an absolute position. As a result, wh ...

Utilizing the change of state in one useEffect to prompt the execution of another useEffect

While working on a project, I decided to incorporate a wysiwyg style editor. I came across a video on YouTube showcasing a Reddit clone that had the feature integrated using Editor JS. As I delved into the code, I noticed an interesting use of useEffect tr ...

The background image is not appearing on the div as expected

I've been attempting to create a div and set a background image for it using jQuery, but I seem to be facing issues. When I try setting the background color to white, it works fine. Here's the code snippet: function appendToDom(poster) { ...

In TypeScript with React, utilizing ref to access the video element and trigger the .play() method

I have a TypeScript React video component that I want to play when clicked. My approach is to use a click handler that accesses the video through a ref and calls .play(), but I keep encountering this error: TS2339: Property 'play' does not exist ...

Sort through the API's array

Currently, I am working with the OpenWeather API's 5-day 3-hour forecast feature and encountering an issue regarding the response JSON. The array contains 40 items, each with a "dt_txt" value in the format of "2018-11-22 15:00:00". My goal is to displ ...