leongersen / noUiSlider

noUiSlider is a lightweight, ARIA-accessible JavaScript range slider with multi-touch and keyboard support. It is fully GPU animated: no reflows, so it is fast; even on older devices. It also fits wonderfully in responsive designs and has no dependencies.
https://refreshless.com/nouislider/
MIT License
5.64k stars 658 forks source link

BEst way to detect if a handle was clicked without moving #1209

Closed frumbert closed 2 years ago

frumbert commented 2 years ago

I want to handle an action when clicking (pressing and releasing) a handle that hasn't changed position.

But not when a handle is pressed then moved then released, or if a handle was moved using keyboard or set using script.

Seems like I have to do something like

        noUISider.create(node, { 
           behaviour: 'unconstrained-smooth-steps-hover'
           range: { 'min': 0, 'max': 100},
           start: [10]
        });
        noUi.noUiSlider.on('set', set);
        noUi.noUiSlider.on('start', start);

        let lastvalue = [];

        function start(a,b,c,d,e,inst) {
            lastvalue = inst.get(); // might be array or single value
        }

        function set(a,b,c,d,e,inst) {
            let value = inst.get();
            if (JSON.stringify(value) === JSON.stringify(lastvalue)) {
                handleClick(inst);
            }
        }

which works but feels janky. Is there a better way to handle this?

leongersen commented 2 years ago

That's how I would do it. Note that where you are using lastvalue = inst.get();, the slider values are available in b[a].

github-actions[bot] commented 1 year ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.