question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bootstrap input-group CSS alignment

See original GitHub issue

v.0.27.0 React v.15.0.1


I’m including the styles as noted in the docs:

require('react-datepicker/dist/react-datepicker.css');

There is a considerable disparity between the addon and the input style/alignment:

screen shot 2016-05-12 at 3 42 50 pm

markup:

<div className="input-group">
    <span className="input-group-addon">
        <i className="fa fa-calendar"></i>
    </span>
    <DatePicker
        selected={this.state.startDate}
        onChange={this.handleDateChange.bind(null, 'startDate')}
        placeholderText="Start Date &hellip;"
        className="form-control"/>
</div>

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
ryanzeccommented, May 17, 2016

I have the same problem with this.

A temporary hacky workaround I have found is to add this scss:

//NOTE: this is needed in order to make react-datepicker work with bootstrap's input group / input group addon functionatily
.react-datepicker__input-container {
  width: 100%;

  //NOTE: using table instead of block as it is needed in order to make this element set the height since the input is floating
  display: table;

  input {
    border-radius: $input-border-radius;
  }
}

.form-inline {
  .react-datepicker__input-container {
    width: auto;
    display: inline;
  }
}

This works fine for regular form elements however when you use inline form elements, that is where the hacky part come into play. When using inline form elements, the height of the react-datepicker__input-container becomes messed up and does not reflect the height of the elements within. In order to work around that, you can use the popoverTargetOffset property of react-datepicker to align the date picker itself properly.

@martijnrusschen I would be in favor of removing the clear functionality because as @rafeememon said, that is not very difficult functionality to implement manually and it would make this component more flexible to work with. While my hacky solution works, I would not want it to be a long term solution as it would be very prone to breaking as styles are tweaked.

4reactions
jochenbergercommented, Dec 2, 2016

I use a customInput that uses http://react-bootstrap.github.io/ for this use case:

const InputWithButton = (props)=>{
  return(
    <InputGroup>
      <FormControl onClick={props.onClick} value={props.value} onChange={props.onChange} disabled={props.disabled} />
      <InputGroup.Button>
        <Button onClick={props.onClick} disabled={props.disabled}><Glyphicon glyph="calendar" /></Button>
      </InputGroup.Button>
    </InputGroup>
  );
};

and then

<DatePicker customInput={<InputWithButton />} ... />

Maybe some custom input implementations could be provided with react-datepicker, this one would need a dependency on react-bootstrap though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to align inputs in bootstrap form with input-group-addons?
I find that I needed to include: float: left as well. So, the css is: .input-group[class*="col-"] { float: left; padding-right: 15px; ...
Read more >
Input group - Bootstrap
Easily extend form controls by adding text, buttons, or button groups on either side of textual inputs, custom selects, and custom file inputs....
Read more >
Bootstrap CSS class: input-group - Shuffle
Bootstrap CSS class input-group with source code and live preview. You can copy the example and paste it into your project or use...
Read more >
Alignment issue with input-group-btn #24 - GitHub
... to use an input-group-btn with Typeahead, the button does not align ... using the latest version of Bootstrap, Typeahead, and this CSS....
Read more >
Center Bootstrap 4 Input Group - 2 ways on Codeply
Use flexbox or mx-auto to center an input group in Bootstrap 4 Codeply example. ... <div class="form-row justify-content-center">. <div class="form-group ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found