I am making my own combobox for better design than a <select> tag.
By the way, I wish to know, how to make possible the navigation with the arrow keys of a keyboard between <span> (or other <p>…), and display the proposals with the “tab” key. Like the <option> of a <select> tag.
This is where I would like to make it work :
HTML
<input type="text" id="myInput" value=""/>
<div id="myDiv">
<span>Value 1</span>
<span>Value 2</span>
<span>Value 3</span>
</div>
CSS
#myDiv {display:none;border:1px solid #000;}
span {display:block;background:#EDEDED;cursor:pointer;}
span:hover {background:#555;color:#FFF;}
JS
$(document).ready(function(){
$('#myInput').focus(function(){
$('#myDiv').slideDown();
});
$('span').click(function(){
$('#myInput').val($(this).html());
$('#myDiv').slideUp();
});
});
You can test it here : http://jsfiddle.net/eHpKX/2/
Edit example : for example, click or tab in the input and then use the arrow keys to navigate… It doesn’t works.
Any help will be appreciated.
I wrote a keydown handler for
uparrowanddownarrowto act like select drop down. Howevertabkey has a specific role in tabbing out to next field, So I didn’t want toprevtDefaultbrowser behavior. See below code and you can build it more from there,DEMO
CSS:
JS: