Stop input-group-append from causing adjacent input-groups to shift right

When I have two input fields next to each other and render a button within an input group, the button pushes the neighboring input field on the right, decreasing its width. This behavior can be observed in this example sandbox: view code sample. To illustrate, typing something in the "Recipient's username" input field causes the button to render and push the "Recipient's password" field on the right. My goal is to prevent this layout shift while still displaying the button without modifying the input fields themselves. For a demonstration without the code, you can check out this link: view example here.

Answer №1

To structure your form inputs, consider utilizing Bootstrap's grid layout. You can nest your inputs within a col inside a row, without altering the individual input fields themselves. Simply apply an additional CSS class to both input-group divs and wrap them in a container div with the class row:

<div className="App">
  <div className="row">
    <div className="input-group col-6">
      <input ... />
      {showAppend === true && (
        <div className="input-group-append">
          <span className="input-group-text" id="basic-addon2">
            @example.com
          </span>
        </div>
      )}
    </div>
    
    <div className="input-group col-6">
      <input... />
      {showAppendPassword === true && (
        <div className="input-group-append">
          <span className="input-group-text" id="basic-addon2">
            @example.com
          </span>
        </div>
      )}
    </div>
  </div>
</div>

This approach leverages the grid system to display both the username and password inputs side by side effectively. By specifying the width of each input-group div with col-6 (indicating they occupy 50% of the total width), you ensure that when the input-group-append is present, it does not disrupt the layout of the adjacent input:

Original input layout: https://i.sstatic.net/8tsvk.png

Updated with input-group-append: https://i.sstatic.net/7tdd0.png

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 functionality of the handleTextShow function in components>DrinkList.js is not working as expected after integrating an API

While working on my react program, I created a DrinkList.js file to display images of drinks. However, when I attempted to make the images clickable by adding an Onclick function to display their names in the console, errors started flooding in. import Rea ...

Is it possible to add an autocomplete feature within the <ChipInput> component in Material UI?

Is it possible to implement an autocomplete field using in material UI? I would like the user to be presented with a dropdown list from which they can make a selection, and then have it displayed as a chip. ...

CSS style takes precedence over inline JavaScript transitions occurring from a negative position

I am puzzled by a JavaScript fiddle I created which contains two small boxes inside a larger box. Upon clicking either of the buttons labeled "Run B" or "Run C", the corresponding box undergoes a CSS transition that is controlled by JavaScript. Below is t ...

Menu: animated opening/closingIs this convenient, or

How can I add animation to opening and closing menu items in my project? I am not sure if it can be done in Angular or CSS. I have provided a reproduction of the project for reference => Stackblitz. HTML file <div class="wrapper"> & ...

Issues encountered when attempting to run a Dockerfile on the backend of a React project

I am attempting to launch a React app with two Node servers - one for the front-end and one for the back-end, which are connected via a MySQL database. I am trying to utilize Docker for containerization. I have successfully started up the database and fro ...

Ways to determine if the popupState component in Material UI is currently opened

I am currently utilizing PopupState and the Popover component to create a specific element. It is functioning properly, but I have a requirement to modify the icon displayed based on whether the popup is open or closed. Here is the code for my component: ...

I have successfully implemented the Context API in my Next.js project and everything is functioning smoothly. However, I encountered an error while using TypeScript

Currently, I am working on a Next.js project that involves using the Context API. The data fetched from the Context API works perfectly fine, but I am encountering errors with TypeScript and I'm not sure how to resolve them. Error: Property openDialo ...

Top method for retrieving step counter information using React Native

Seeking advice on the most efficient method for retrieving pedometer data from a phone, particularly Android. Initially, I attempted to run a background task and use react-native-universal-pedometer npm package to subscribe to the step sensor, but discov ...

The Nivo Slider is stealthily concealing my CSS Menu

Although this question has been previously asked, I am still unable to make it work with the solutions provided; The website in question is I have tried changing the z-index on all menu items to 99999, but they are still appearing below. <div id="sli ...

What is preventing the container slide from reacting solely to the image?

I've been working on an image and a slider, and everything seems to be functioning as intended. However, there is a strange reaction on the left side even before reaching the image. I've tried tweaking it, but I can't seem to figure out the ...

What is the best way to initiate a dialog within the handleSubmit function?

In my project, I have a component called SimpleDialog which is defined in the File.tsx file. export default function SimpleDialog() { const handleSubmit = (event: any) => { <SimpleDialog />; } return( <form> <Button type="submit& ...

unable to insert logo into HTML

I am customizing an HTML template, but the dimensions of the logo in the template are smaller than my logo. Despite adding my logo to the template, it is not showing up. @media (max-width: 673px) { #logo { margin-left: 20px; } } #header #logo ...

Leveraging the same React component in multiple instances and streamlining requests - NextJS vs React

Currently, I'm working on a chat application using NextJS 14. Each time a message is sent or received, there is a small icon next to the chat message that represents the user who sent the message. To achieve this, I have a ChatMessageUI component tha ...

Leveraging @font-face for various styles and designs

Google web fonts presents the Droid Serif font in these styles: DroidSerif.ttf DroidSerif-Bold.ttf DroidSerif-BoldItalic.ttf DroidSerif-Italic.ttf I am interested in using the @font-face CSS rule to import all of these variations with the "Droid Serif" f ...

Empty canvas post-launch - React application utilizing Node

While my React app and server-side (Node.js) work perfectly on localhost, I encountered an issue when deploying them on Heroku as it displayed a blank page. During deployment, I created a Procfile where I referenced the server file: web: node ./server/ind ...

Handling errors when importing images from a URL in React

Currently, I am iterating through an API that includes links to images which I want to display visually. My approach looks like this: <img className={styles['picture']} src={props.flyerFront} alt="new" /> The issue arises when s ...

Troubleshooting alignment issues with ReactJS Bootstrap on Internet Explorer - Application not displaying correctly on IE as it does in Chrome

After building a ReactJS app, I noticed that when accessing it in Internet Explorer, all the content gets squished in the middle of the page. It seems like IE is not properly rendering the Bootstrap components, even though Chrome, Firefox, and Edge display ...

Tips for preventing the deletion of cell content using the Delete key in Material-UI XGrid

Is there a way to stop the delete key from clearing cell content in the Material-UI Grid for React? Currently, when you click on a cell and press the Delete key, it removes the contents. I want to find a solution to prevent this action. ...

Playing around with adjusting the size of a div that is positioned absolutely on the right side

Snippet: http://jsfiddle.net/scottbeeson/TU6Zw/ HTML Code: <div id="itemMap" class="shadow"> <div class="mapHeader">List of Items</div> <div class="mapItem">Item 1</div> <div class="mapItem">Item 2</div& ...

``Incorporate images into a slideshow container with proper alignment

I'm currently using a jquery slideshow on my homepage with fading images, but I'm having trouble centering them. The images are all different sizes and they're aligning to the left instead of being centered. Here is the CSS code I've b ...