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.

Textbox size stays fixed with Bootstrap 3.2

See original GitHub issue

Bootstrap ver: 3.2 Typeahead ver: 0.10.5

Issue: When using typeahead 0.10.5 with Bootstrap 3.2, the textbox is automatically resizes to a fixed 120px width and does not allow for auto-resizing.

For instance, notice that the 2nd textbox will resize and stretches to the full width of it’s DIV, where as the one wrapped in DIV ID=“the-states” stays at a fixed width. Thus breaking the fluid / adjustable form.

Please address this issue

Workaround: None

Reproduce Sample:


{# Note i'm using the standard typeahead.css v0.10.5, unmodified #}
<head>
  <link rel="stylesheet" href="libs/bootstrap/css/bootstrap.min.css" />
  <link rel="stylesheet" href="libs/bootstrap/css/bootstrap-theme.min.css" />
  <script src="libs/jquery/jquery-1.11.1.min.js"></script>
  <script src="libs/bootstrap/js/bootstrap.min.js"></script>
  <script type="text/javascript" src="typeahead.bundle.min.js" ></script>
  <link rel="stylesheet" href="typeahead.css" />
</head>
<body>
<script type="text/javascript">
  $(document).ready(function() {

    var substringMatcher = function(strs) {
      return function findMatches(q, cb) {
        var matches, substrRegex;
        matches = [];
        substrRegex = new RegExp(q, 'i');
        $.each(strs, function(i, str) {
          if (substrRegex.test(str)) {
            matches.push({ value: str });
          }
        });
        cb(matches);
      };
    };
    var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California'];
    $('#the-states .typeahead').typeahead({
      hint: true,
      highlight: true,
      minLength: 1
    },
    {
      name: 'states',
      displayKey: 'value',
      source: substringMatcher(states)
    });
  });
</script>

<div class="container-fluid">
  <form class="form-horizontal" role="form">
    <div class="panel">
      <div class="panel-body">

        <div class="row">

          <!-- This input stays at a FIXED WIDTH -->
          <div class="col-sm-6 col-lg-4">
            <div class="form-group">
              <label for="inputEmail" class="col-md-4 control-label">Email:</label>
              <div class="col-md-8" id="the-states" >
                <input type="text" id="txtInput1"
                  class="typeahead input-sm form-control"
                  autocomplete="off"
                  spellcheck="false"
                  placeholder="Sales Rep"
                />
              </div>
            </div><!-- form-group -->
          </div><!-- col-sm-6 col-lg-4 -->

          <!-- This box shows correctly and resizes correctly -->
          <div class="col-sm-6 col-lg-4">
            <div class="form-group">
              <label for="inputPassword" class="col-md-4 control-label">Password:</label>
              <div class="col-md-8">
                <input type="password" class="form-control" id="inputPassword" placeholder="Password">
              </div>
            </div><!-- form-group -->
          </div><!-- col-sm-6 col-lg-4 -->
        </div><!-- row -->

      </div><!-- panel-body -->
    </div><!-- panel -->
  </form>
</div>
</body>

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

5reactions
DevChivecommented, Aug 22, 2014

Found the fix, PLEASE INCLUDE THIS IN YOUR DOCUMENTATION!

  1. Add the following to typeahead.css
.twitter-typeahead {
  width: 100%;
}
  1. Add the following to your javascrpit after $(“…”).typeahead({…});
$(".tt-hint").addClass("form-control");
1reaction
wattrycommented, Oct 5, 2018

@DevChive

If you add the width: 100% to the drop down it will extend the entire input too:

.scrollable-dropdown-menu .tt-menu {
  width: 100%;
  max-height: 150px;
  overflow-y: auto;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS · Bootstrap 3.3.2 Documentation
Here's how the Bootstrap grid system works: Rows must be placed within a .container (fixed-width) or .container-fluid (full-width) for proper alignment and ...
Read more >
Input widths on Bootstrap 3 - css
Inputs, selects, and textareas are 100% wide by default in Bootstrap. To use the inline form, you'll have to set a width on...
Read more >
Position · Bootstrap
Fixed bottom. Position an element at the bottom of the viewport, from edge to edge. Be sure you understand the ramifications of fixed...
Read more >
Position · Bootstrap v5.0
Be sure you understand the ramifications of fixed position in your project; you may need to add additional CSS. Copy. <div class="fixed-top"> ...
Read more >
Components
Justified button groups. Make a group of buttons stretch at equal sizes to span the entire width of its parent. Also works with...
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