Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to select values with up-down arrow keys #3682

Closed
uzlov opened this issue Aug 18, 2015 · 3 comments
Closed

Allow to select values with up-down arrow keys #3682

uzlov opened this issue Aug 18, 2015 · 3 comments

Comments

@uzlov
Copy link

uzlov commented Aug 18, 2015

The same with native select - when select don't open.

@uzlov
Copy link
Author

uzlov commented Aug 18, 2015

this.on('keypress', function (evt) {
var key = evt.which;

  if (self.isOpen()) {
    if (key === KEYS.ENTER) {
      self.trigger('results:select');

      evt.preventDefault();
    } else if ((key === KEYS.SPACE && evt.ctrlKey)) {
      self.trigger('results:toggle');

      evt.preventDefault();
    } else if (key === KEYS.UP) {
      self.trigger('results:previous');

      evt.preventDefault();
    } else if (key === KEYS.DOWN) {
      self.trigger('results:next');

      evt.preventDefault();
    } else if (key === KEYS.ESC || key === KEYS.TAB) {
      self.close();

      evt.preventDefault();
    }
  } else {
    if (key === KEYS.ENTER || key === KEYS.SPACE ||
        ((key === KEYS.DOWN || key === KEYS.UP) && evt.altKey)) {
      self.open();

      evt.preventDefault();
    }
    if (key === KEYS.DOWN) {
      if (undefined != this.$element.find('option:selected').next().val()) {
        this.$element.val(this.$element.find('option:selected').next().val());
        this.$element.trigger('change');
      }
      evt.preventDefault();
    }
    if (key === KEYS.UP) {
      if (undefined != this.$element.find('option:selected').prev().val()) {
        this.$element.val(this.$element.find('option:selected').prev().val());
        this.$element.trigger('change');
      }
      evt.preventDefault();
    }
  }
});

@kevin-brown
Copy link
Member

This is a duplicate of #3472.

@akinhwan
Copy link

akinhwan commented Mar 4, 2019

so we just need to update the core.js file with the above function? is there a reason it is not part of the core.js ? just wondering

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants