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

update event fires for all handles when one is changed with a key press #960

Closed
eoghanmurray opened this issue Mar 14, 2019 · 6 comments
Closed
Labels
Bug Confirmed bugs

Comments

@eoghanmurray
Copy link

eoghanmurray commented Mar 14, 2019

With multiple handles, moving one of them using the keyboard causes an update event to fire on all 3 handles.

noUiSlider.create(slider_el, {
    start: [30, 60, 90],
    behaviour: 'drag',
    connect: true,
    tooltips: [true, true, true],
    range: {
	'min': 0,
	'max': 100
    }
});
slider_el.noUiSlider.on('update', 
    function(v, h, u, t, p) { if (!t) { console.log('update:', h); }});
slider_el.noUiSlider.on('set', 
    function(v, h, u, t, p) { if (!t) { console.log('set:', h); }}

Expected output upon moving handle number 2 with keyboard:

update: 1
set: 1

Actual output:

update: 0
update: 1
set: 1
update: 2

This causes a bug with my solution in #957 when trying to move handle number 2 back past the margin of handle number 1; the event handler for handle number 1 gets executed first and modifies the position of handle number 2 such that when the update event for handle number 2 subsequently fires, there's nothing to do.

@eoghanmurray
Copy link
Author

Looks like the rationale for the multiple updates was already questioned here:
#579 (comment)
I know there's gonna be a good reason but I can't figure it out.
Could a solution be to check whether a given handles' value has actually changed before firing that event?

@leongersen
Copy link
Owner

This is a mistake on my end, update should only fire for the handle being, you know, updated.

@leongersen leongersen added the Bug Confirmed bugs label Mar 15, 2019
@leongersen
Copy link
Owner

leongersen commented Mar 15, 2019

As per the rationale behind firing update events:

The idea is that calling set allows handles to "push" each other forward. Say you have a slider with range 0 - 10, step 3, start 0 - 6. Calling set([9, null]) causes handle 0 to move to 9, forcing handle 1 to move to 9 as well, even though no update of handle 1 was requested. If there would be no update event for handle 1, possible listeners would be out of sync.

Thanks for pointing this out, because I'm now realizing that keyboard interaction allows for this same effect: handle 0 can push handle 1 forward, but it shouldn't!

@leongersen
Copy link
Owner

This is fixed in noUiSlider 13.1.3. Many thanks for contributing, @eoghanmurray! Much appreciated.

@eoghanmurray
Copy link
Author

Chuffed to have turned out to be useful!

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Confirmed bugs
Projects
None yet
Development

No branches or pull requests

2 participants