jquery-nice-select
jquery-nice-select copied to clipboard
Would be nice to have a typed key jump to word beginning with that letter
I'm using NS for a state dropdown and noticed today that when the NS control has focus if I type the letter "P"—to jump to "PA - Pennsylvania" for example—it doesn't do that. With a normal select control it would.
Also, if I were to type fast on a normal select control (e.g. assume list of full state names and I typed "N-O-R-T-H" quickly) it would jump to those states start with "North" in the name and skip over, for instance, the state of "New York."
I'd like to request that key taps would jump to the instance in the list associated with that letter's keypress, and quick keytaps jump to that word in the list.
Any update on this how can we achieve to select the option using the keyboard? Thanks.
I got this working by using adding the keyup event:
$(document).on('keyup', '.nice-select', function(event) {
var $dropdown = $( this );
if (event.which !== 0) {
$( this ).find('ul.list li').each(function( index ) {
if( ! $( this ).hasClass('focus') ){
var li_text = $( this ).text().replace(/\s+/g, '');
if( li_text.charAt(0) == String.fromCharCode(event.which) ){
$dropdown.find('.focus').removeClass('focus');
$( this ).addClass('focus');
return false;
}
}
});
}
});