jquery-nice-select icon indicating copy to clipboard operation
jquery-nice-select copied to clipboard

Would be nice to have a typed key jump to word beginning with that letter

Open geigel opened this issue 6 years ago • 2 comments

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.

geigel avatar Jun 28 '18 09:06 geigel

Any update on this how can we achieve to select the option using the keyboard? Thanks.

jatindersin avatar Oct 11 '18 00:10 jatindersin

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;
            }  
          }
        });
      }
    });

Kane-R-G avatar Mar 18 '19 01:03 Kane-R-G