Vue-slider-component: On focus make dot active

Created on 20 Feb 2019  路  7Comments  路  Source: NightCatSama/vue-slider-component

Hi!

My challenge is:
When the dot has focus via keyboard tab - make the dot active so the user can start navigating the slider without having a mouse.

I guess my question becomes: is it possible to through my focus event listener make the dot active? I've tried simulate a click in my event listener without success.

This is how the code looks:

<div @focus="myClickEvent" tabindex="3" slot="dot" slot-scope="{ value }" class="vue-slider-dot-handle dot-outer">
         <span class="dot-inner" ref="myBtn">
                {{ value }}
            </span>
</div>

myClickEvent($event) {
  console.log('Dot is now in focus');
  const elem = this.$refs.myBtn
  elem.click() // Does not work. Can we call some other function to make the dot active?
}

Most helpful comment

Try this

this.$refs.slider.focusSlider = 0
this.$refs.slider.focusFlag = true

All 7 comments

Try this

this.$refs.slider.focusSlider = 0
this.$refs.slider.focusFlag = true

Works like a charm, thank you!!

@NightCatSama @creativejeff Where does this code go? There's absolutely no context.

Hey @3zzy , it goes to the function you've binded to the element. In my case it goes to my focus event conveniently called myClickEvent()

myClickEvent($event) {
  this.$refs.slider.focusSlider = 0
  this.$refs.slider.focusFlag = true
}

@3zzy If you are using the v3.x version, you can use the focus method.

https://nightcatsama.github.io/vue-slider-component/#/api/methods?hash=focusindex

@creativejeff @NightCatSama Great, thanks, that helped! Just wondering how to make it work for a range slider (two handles)?

@3zzy The first parameter of focus is the index of the slider.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

senner007 picture senner007  路  5Comments

advancedlogic picture advancedlogic  路  7Comments

ericdrobinson picture ericdrobinson  路  4Comments

rvasoya picture rvasoya  路  9Comments

yusupprog picture yusupprog  路  5Comments