What is the best way to align an InputAdornment IconButton with an OutlinedInput in Material-UI?

Struggling to replicate a text input from a mockup using Material-UI components. Initially tried rendering a button next to the input, but it didn't match. Moving on to InputAdornments, getting closer but can't get the button flush with the input like the mockup.

Check out the code below. Any ideas would be greatly appreciated!


<OutlinedInput
            id="outlined-add-region"
            type="text"
            value="Ajouter une région"
            onChange={handleChange("password")}
            endAdornment={
              <InputAdornment position="end">
                <button
                  aria-label="toggle password visibility"
                  onClick={handleClickShowPassword}
                  onMouseDown={handleMouseDownPassword}
                  edge="end"
                >
                  <Add />
                </button>
              </InputAdornment>
            }
          />

Answer №1

After some experimentation on code sandbox, I was able to achieve a design similar to your mockup.
Feel free to use this code snippet as a starting point:

<OutlinedInput
  style={{height: "40px", width: "250px"}}
  id="outlined-add-region"
  type="text"
  value="Add a region"
  onChange={() => {}}
  endAdornment={
    <Button 
      style={{
        position: "absolute",
        right: 0,
        height: "100%",
        backgroundColor: "#f0f8ff",
        color: "#5072a7",
      }}
    >
      <Add style={{fontSize: "25px"}} />
    </Button>
  }
/>

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

Send the output of an asynchronous ajax request to the designated function within the jQuery Validation plugin

Utilizing the jQuery Validation plugin (JVP) for server-side validations via ajax has been seamless, except for one hitch: JVP struggles with performing remote validation on blank fields. While it's easy to use its default required: true rule for sim ...

What is the process for creating a clickable file upload in Angular?

Currently, I am utilizing the instructions found in this guide to implement a file upload feature in my project. The code provided works perfectly: <input type="file" class="file-input (change)="onFileSelected($event)" #fileUplo ...

ERRSOLVE : Dependency resolution failed due to unresolved dependencies

npm ERROR! code ERESOLVE npm ERROR! ERESOLVE unable to resolve dependency tree npm ERROR! npm ERROR! While resolving: [email protected] npm ERROR! Found: [email protected] npm ERROR! node_modules/react npm ERROR! react@"^18.2.0" from ...

Is it always the case that modifying the props of a child component will trigger a re-render of the parent component, even

I am currently exploring ways to prevent a modal element from re-rendering when it is supposed to be hidden. The tutorial I am following suggests converting the component to a class-based one and using shouldComponentUpdate(). However, I wanted to test if ...

Preventing background style from taking precedence over backgroundColor style in React's inline styling

What causes background to take precedence over backgroundColor in React inline-style? In this scenario, the lack of a specified green background-color results in the background gradient with transparency transitioning into white rather than green within t ...

Having difficulties accessing the /playlists route with express and app.get in my code

I am encountering a 404 status code error when trying to access app.get('/playlists'). The browser displays "cannot GET /playlists" and I can't seem to figure out why. Here is the code I am using: var express = require('express&apos ...

Customizing React component properties within a Styled Component

I have been experimenting with styled components to customize the appearance of basic material-ui React components. My goal is to pass props into the MUI component and then use styled components to apply CSS styling. One interesting aspect is being able t ...

Is it possible for JavaScript/React to observe the movement of elements on the webpage?

I'm searching for a solution to detect if an element moves on the screen. Currently, I have an absolute positioned div (acting as a download overlay) that appears when a document is clicked on my website. However, I want it to disappear whenever the d ...

When the class changes, V-for re-renders every component

Currently, I am in the process of changing classes for images based on their index using the moveIndex method and key events. While this works smoothly on computers, it seems to take significantly longer when implemented on TVs. The process runs smoothly w ...

Manage the lineup of tasks in the bull queue by organizing them into groups

I am currently working on a nodejs application that handles queues using the bull library. The application is required to make multiple asynchronous HTTP requests and then process the results of these calls. I'm curious about whether bull would be an ...

"Ensuring Your SVG Icon is Perfectly Centered: A Step

My SVG icon is currently aligned to the left, but I want to center it. I tried using the following code, but it doesn't seem to be working: .parent{ display: flex; align-items: center; font-size: 13px; } span{ margin-right:10px } When I look at the S ...

What do you want to know about Angular JS $http request?

My goal is to send a request using $http with angular js in order to retrieve a json object from google maps. $http.get('http://maps.googleapis.com/maps/api/geocode/json?address=' + data[ 'street' ] + ',' + data[ 'city&a ...

How to set custom column width for each element using react-masonry

To create a unique grid layout using react-masonry, refer to the documentation provided at https://mui.com/material-ui/react-masonry/ By default, the column widths are equal when generating the grid. For instance, with 3 columns, each column will occupy 3 ...

What is the best way to utilize the GET Method with a hashtag incorporated into the URL?

For instance: www.sample.com#?id=10 Currently, I am not able to retrieve any value from $_GET['id']. Despite my attempt to eliminate the hashtag from the URL using JavaScript, no change occurs: $(document).ready(function(){ $(window.location ...

I recently added Tailwindcss to my project and set up the configuration after initialization. However, I am facing issues as my styles are not being applied to the page

This is my current tailwind configuration file. I have attempted different suggestions found on Stack Overflow, but none seem to be resolving the issue. Does anyone have any insights or catch any mistakes that may not be related to the content? Thank you ...

What could be causing babel-preset-react to not parse my JSX properly?

Encountering the error below while running webpack: Error in ./src/index.jsx Module parse failed: .../src/index.jsx Unexpected token (10:18) You may need an appropriate loader to handle this file type. All necessary loaders are thought to be properly set ...

Using React Higher Order Components with several different components

Is it possible to create a React HOC that can accept two components instead of just one wrapped component and toggle between them? For instance, in the code snippet below, rather than having <h3>component one</h3> and <h3>component two< ...

Unable to access Form element in Firefox browser

I'm struggling with debugging unfamiliar problems. For instance, in my HTML there's a form: <form name="myForm" > <table> <tr> <td> <input type="radio" name="myType" value="val" onclick="someF ...

Change occurring within a cell of a table that has a width of 1 pixel

In the code snippet below, there is a transition inside a table cell with a width of 1px to allow it to wrap its content. However, the table layout changes only at the end or beginning of the transition: var animator = document.getElementById("animator" ...

HTML: Dealing with issues in resizing and resolution with floating elements on the left and right using

Encountering some issues with the HTML code below when resizing the window: 1: The right bar suddenly drops down if the width is made too small. 2: The spacing between the content and the right bar expands as the window width increases. <style ty ...