Typeahead.js interferes with Bootstrap input groups
Asked Answered
W

5

25

How do I keep Typeahead.js from splitting up my Twitter Bootstrap 3 input groups? Whenever I point the Typeahead javascript at a text area that's part of an input group, the joined text area and submit button stop being joined. Is this something that's just a bug in Typeahead, or is there a workaround for this?

Without loading Typeahead.JS:

enter image description here

With Typeahead.JS:

enter image description here

My original HTML:

    <div class="col-sm-4 hidden-xs">
    <form class="navbar-form" role="search">
        <div class="input-group">
        <input type="text" id="tags" class="form-control" name="q">
            <div class="input-group-btn">
                <button class="btn btn-default" type="submit">Search</button>
            </div>
        </div>
    </form> 
    </div>

This is what Typeahead does to this HTML:

<div class="col-sm-4 hidden-xs">
        <form class="navbar-form" role="search">
            <div class="input-group">
            <span class="twitter-typeahead" style="position: relative; display: inline-block;">
            <input type="text" class="form-control tt-hint" disabled="" autocomplete="off" spellcheck="false" style="position: absolute; top: 0px; left: 0px; border-color: transparent; box-shadow: none; background-attachment: scroll; background-clip: border-box; background-color: rgb(255, 255, 255); background-image: none; background-origin: padding-box; background-size: auto; background-position: 0% 0%; background-repeat: repeat repeat;">
            <input type="text" id="tags" class="form-control tt-input" name="q" autocomplete="off" spellcheck="false" dir="auto" style="position: relative; vertical-align: top; background-color: transparent;">
            <pre aria-hidden="true" style="position: absolute; visibility: hidden; white-space: nowrap; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; word-spacing: 0px; letter-spacing: 0px; text-indent: 0px; text-rendering: auto; text-transform: none;">
            </pre>
            <span class="tt-dropdown-menu" style="position: absolute; top: 100%; left: 0px; z-index: 100; display: none;"><div class="tt-dataset-0"></div>
            </span>
            </span>
                <div class="input-group-btn">
                    <button class="btn btn-default" type="submit">Search</button>
                </div>
            </div>
        </form> 
        </div>
Welty answered 8/3, 2014 at 23:38 Comment(3)
Not sure if this would help, but there's a project which provides Bootstrap style for typeahead.js (both Less and CSS). You might want to try it.Soper
I've got the same issue! Have you made any progress on this?Guadalupe
the project mentioned above partially helped to me.Eudocia
E
14

This project partially solved the issue for me: https://github.com/hyspace/typeahead.js-bootstrap3.less

The only outstanding problem is when I apply shadow effect to both the .btn and .form-control the shadow is drawn also between the input field and the button.

enter image description here

Eudocia answered 18/7, 2014 at 12:39 Comment(4)
My workflow doesn't use less so this doesn't really work for me.Welty
@schnauss Neither does mine, the solution is not dependent on less.Eudocia
Works great, but one thing that is missing is: .twitter-typeahead > .form-control{ width: inherit !important; }. Add that to adjust the width of the input fields.Jueta
Simply incorporated typeahead.css (version 0.2.3) from the cited github page, added the link and typeahead (version 0.11.1) is working just fine.Cami
V
31
.twitter-typeahead{ float:left; width:100%}
Verniavernice answered 26/3, 2014 at 9:23 Comment(1)
This answer is incorrect and should not be upvoted. This squishes them closer together, but it doesn't join them and it doesn't do anything about the left-hand side of the text box being square.Welty
E
14

This project partially solved the issue for me: https://github.com/hyspace/typeahead.js-bootstrap3.less

The only outstanding problem is when I apply shadow effect to both the .btn and .form-control the shadow is drawn also between the input field and the button.

enter image description here

Eudocia answered 18/7, 2014 at 12:39 Comment(4)
My workflow doesn't use less so this doesn't really work for me.Welty
@schnauss Neither does mine, the solution is not dependent on less.Eudocia
Works great, but one thing that is missing is: .twitter-typeahead > .form-control{ width: inherit !important; }. Add that to adjust the width of the input fields.Jueta
Simply incorporated typeahead.css (version 0.2.3) from the cited github page, added the link and typeahead (version 0.11.1) is working just fine.Cami
P
8

Bootstrap v4 solution:

.input-group > .twitter-typeahead {
   flex: 1 1 auto;
   width: auto;
}
Praetor answered 18/12, 2018 at 0:58 Comment(3)
This worked for me, thanks. Though I didn't need the width: auto rule for my version, presumably due to using the css for other BS4 changes for it from here github.com/bassjobsen/typeahead.js-bootstrap4-cssEthiopia
Almost perfect. Add this to remove the input radius at the left: .input-group>.twitter-typeahead > .form-control:not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; }Iberian
This solution helped me solve the exact same problem for a blazored-typeahead component with bootstrap v5.Rahm
L
3

maybe?

.twitter-typeahead > .form-control{
  width: inherit !important;
}
Liegnitz answered 13/11, 2014 at 4:31 Comment(0)
A
2

This fixes the problem when the left-hand side of the text box is square (not rounded):

.input-group .twitter-typeahead .form-control:not(:first-child):not(:last-child) {
  border-radius: 4px 0px 0px 4px;
}
Airdrop answered 23/4, 2014 at 8:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.