JSFiddle - React, Tailwind, and code Playground
by karimkhan
HTML
<script src="http://twitter.github.io/typeahead.js/releases/latest/typeahead.js"></script>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<script src="netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<br />
<br />
<div class="container">
<div class="col-lg-6">
<div class="input-group">
<input type="text" class="typeahead form-control" placeholder="Select category ..." />
</div>
<ul class="dropdown-menu">
<li id="one"><a href="#">Sports</a></li>
<li id="two"><a href="#">Entertainment</a></li>
<li id="three"><a href="#">Politics</a></li>
<li id="four"><a href="#">Technolohy</a></li>
<li><a href="#"></a></li>
</ul>
</div>
<!-- /.col-lg-6 -->
</div>
<!-- /.row -->
CSS
.container {
width:90%;
margin:10% auto;
}
.dropdown-menu{
width:360px;
left:auto;
margin:0 auto;
}
.twitter-typeahead .tt-query, .twitter-typeahead .tt-hint {
margin-bottom: 0;
width: 360px; !important;
}
.twitter-typeahead .tt-hint {
display: block;
height: 34px;
padding: 6px 12px;
font-size: 14px;
line-height: 1.428571429;
border: 1px solid transparent;
border-radius:4px;
}
.twitter-typeahead .hint-small {
height: 30px;
padding: 5px 10px;
font-size: 12px;
border-radius: 3px;
line-height: 1.5;
}
.twitter-typeahead .hint-large {
height: 45px;
padding: 10px 16px;
font-size: 18px;
border-radius: 6px;
line-height: 1.33;
}
.tt-dropdown-menu {
min-width: 260px;
margin-top: 2px;
padding: 5px 0;
background-color: #fff;
border: 1px solid #ccc;
border: 1px solid rgba(0, 0, 0, .2);
*border-right-width: 2px;
*border-bottom-width: 2px;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
-webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, .2);
-moz-box-shadow: 0 5px 10px rgba(0, 0, 0, .2);
box-shadow: 0 5px 10px rgba(0, 0, 0, .2);
-webkit-background-clip: padding-box;
-moz-background-clip: padding;
background-clip: padding-box;
}
.tt-suggestion {
display: block;
padding: 3px 20px;
}
.tt-suggestion.tt-is-under-cursor {
color: #fff;
background-color: #0081c2;
background-image: -moz-linear-gradient(top, #0088cc, #0077b3);
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0077b3));
background-image: -webkit-linear-gradient(top, #0088cc, #0077b3);
background-image: -o-linear-gradient(top, #0088cc, #0077b3);
background-image: linear-gradient(to bottom, #0088cc, #0077b3);
background-repeat: repeat-x;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0088cc', endColorstr='#ff0077b3',...
JavaScript
$('.typeahead').typeahead({
name: 'Some name',
local: ['Sports', 'Entertainment', 'Politics', 'Technolohy', 'Technolohy Again']
})
$('.typeahead.input-sm').siblings('input.tt-hint').addClass('hint-small');
$('.typeahead.input-lg').siblings('input.tt-hint').addClass('hint-large');
$(".typeahead").click(function () {
var defaultval = $(".typeahead").val();
$('.dropdown-menu').show(1200);
});
$(".typeahead").on('blur', function () {
$('.dropdown-menu').hide(1200);
});
$('ul.dropdown-menu >li').on('click', function(){
var idd = $(this).attr('id');
var val = ($("#"+idd).text());
alert(val);
$(".typeahead").val(val);
$('ul.dropdown-menu').hide(600);
});