NightCatSama / vue-slider-component

🌡 A highly customized slider component
https://nightcatsama.github.io/vue-slider-component
MIT License
2.41k stars 346 forks source link

Disable key up down events #377

Closed carlosjpr-collab closed 5 years ago

carlosjpr-collab commented 5 years ago

Hi, I am using the option useKeyboard: true that allow me to change the slider tooltip right and left by using key up down or key right left.

Now, I want to disable the key event up and down and make vue slider change only when i press key right or left.

I think the code that must be changed is:

switch (e.keyCode) {
    case KEY_CODE.UP:
      return i => (params.direction === 'ttb' ? i - 1 : i + 1)
    case KEY_CODE.RIGHT:
      return i => (params.direction === 'rtl' ? i - 1 : i + 1)
    case KEY_CODE.DOWN:
      return i => (params.direction === 'ttb' ? i + 1 : i - 1)
    case KEY_CODE.LEFT:
      return i => (params.direction === 'rtl' ? i + 1 : i - 1)
}

Thanks,

NightCatSama commented 5 years ago

Added keydownHook parameter in version 3.0.33

You can use it like this

<vue-slider
  :use-keyboard="true"
  :keydown-hook="e => e.keyCode !== 38 && e.keyCode !== 40"
/>
carlosjpr-collab commented 5 years ago

cool !