-
Notifications
You must be signed in to change notification settings - Fork 12
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
Slider keyboard "step" options don't work if their value is smaller than constrainValue step. #698
Comments
What a fun problem. We, in the past, have had good success using these two options in combination, like using constainValue to appropriately round all step sizes. Is there a patch/commit for a component that I could play around with before recommending a path forward? |
The example code in #698 (comment) is a simplified version of fourier-making-waves AmplitudeSlider.js, where you'll find this TODO: //TODO https://github.com/phetsims/sun/issues/698 constrainValue is overriding shiftKeyboardStep |
The "high" priority label is for me to get to it anytime in the next 2 weeks. Feel free to remove if @jessegreenberg is able to answer your questions. |
I'm going to re-title this issue, because the problem is not specific to |
@arouinfar and I were trying to figure out why this doesn't seem to be a problem in GFL. I found this in NumberControl.js, added by @zepumph in phetsims/scenery-phet@17e8ac3: // By default, constrain to multiples of delta, see #384
const defaultConstrainValue = value => {
const newValue = Utils.roundToInterval( value, options.delta );
return getCurrentRange().constrainValue( newValue );
};
...
// Support shift key stepping based on the arrow key delta, but that may be more minute than constrainValue allows
// for the slider.
if ( options.sliderOptions.constrainValue ) {
const oldConstrainValue = options.sliderOptions.constrainValue;
options.sliderOptions.constrainValue = value => {
if ( this.slider.getShiftKeyDown() ) {
return defaultConstrainValue( value );
}
return oldConstrainValue( value );
};
} It's circumventing A workaround would be to move this to Slider. A more longterm solution is to revisit the "step size" options and make them work for all input modes. |
I asked:
Looking at commit messages... This identical issue was discussed and addressed by @zepumph and @jessegreenberg in phetsims/scenery-phet#528. But for some reason, all of the work was done in NumberControl, and the identical problem was not addressed in Slider. Do either of you recall why the Slider-specific stuff (like the code shown above) was not done in Slider? |
@jessegreenberg and I discused this today via Zoom. In the longterm, it makes sense to take a look at all of the "step size" related options to Slider, as is suggested in #703. But that's likely to be a bigger project than can be completed in the timeframe needed for Fourier 1.0. So for the short-term, @jessegreenberg is going to investigate moving the NumberControl workaround into Slider. @jessegreenberg I'll be happy to review this work, and test-drive in Fourier. |
This much was done in the above two commits, moving the check for @pixelzoom could you please review? |
Looks great, thanks @jessegreenberg. I tweaked one comment in the above commit when something non-optional was still documented as "optional". Tested in Fourier and GLF, and everything is working as expected/desired. Closing. |
Reopening. Because This: // @private {function(number):number} - called before valueProperty is set
this._constrainValue = options.constrainValue;
// @private {function(number,number):number} - called before constrainValue called and valueProperty is set
this._a11yMapValue = options.a11yMapValue; and: // {function(number):number} - It should return the constrained value, called before valueProperty is set
constrainValue: _.identity, and: /**
* Called before constraining and setting the Property. This is useful in rare cases where the value being set
* by AccessibleValueHandler may change based on outside logic. This is for mapping value changes from input listeners
* assigned in this type (keyboard/alt-input) to a new value before the value is set.
* @type {Function}
* @param {number} newValue - the new value, unformatted
* @param {number} previousValue - just the "oldValue" like the Property listener
* @returns {number} - the mapped value, ready to be constrained
*/
a11yMapValue: _.identity, I'll make a pass at revising, then assign to @jessegreenberg for review. |
Oh wait. And regardless of whether the doc gets changed, this issue should be left open. There's a workaround for shiftKeyboardStep, but the other 2 options could still be a problem (though unlikely). |
Thanks, I updated the documentation for the option to make it clear there. I am seeing a couple of CT errors related to this change.
Because |
Oops, this workaround was also in the wrong spot. Just checking for whether the shift key was down means that we aren't using |
CT is stable now, @pixelzoom can you please review these latest changes? If OK then the "high" priority label can be removed and a better solution for |
Thanks for the doc updates, looks good. You added this to ComponentSpacingSlider in phetsims/fourier-making-waves@8d482bc: keyboardStep: 1,
+ shiftKeyboardStep: 1,
+ pageKeyboardStep: 1 Rather than requiring clients to redundantly specify |
Oh boy... There's more to this issue than I orginally reported. I originally described this problem as:
But there's another relationship that must exist between the step options and For example, suppose I have a slider with these options -- you can try these values in AmplitudeSlider.js: constrainValue: value => Utils.roundToInterval( amplitude, 0.5 ),
keyboardStep: 0.6,
shiftKeyboardStep: 0.1,
pageKeyboardStep: 1.25
I don't know how likely this is to occur in a sim, but it's definitely not obvious/robust, and could lead to confusion/bugs. Should these be addressed now, or as part of the larger issue #703? @jessegreenberg thoughts? |
Most likely a subset of phetsims/scenery#1298. |
#698 (comment) is EXACTLY what @jessegreenberg and @samreid and I just ran into for My Solar System in phetsims/my-solar-system#105. We do not like the "cleverness" of how it can behave, and that, coupled with the possibility for a noop depending on your step (see #350), we are going to delete the constrainValue option from the keyboard side of things. Please see #837. Closing |
In Fourier, I have amplitude sliders that I want to configure like this:
The designers want dragging constrained to STEP - no intermediate values. This was working great until I added the PDOM options, and discovered that
options.constrainValue
is also passed to AccessibleValueHandler. For Slider.js:So
shiftKeyboardStep
is not working, because it's value is smaller than STEP.Why does AccessibleValueHandler need to use
constrainValue
when it has specific step sizes? If it has specific step sizes, should it ignoreconstrainValue
?@jessegreenberg @zepumph suggestions on how to proceed? And again, dragging must be constrained to STEP, with no intermediate values.
The text was updated successfully, but these errors were encountered: