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
Allow text input on slider widgets #6106
Conversation
ping @ellisonbg, @jdfreder for review |
Haven't looked at the implementation yet. Is this something we want to support? It adds complexity and textual editing of the slider's value can already be done by linking it to a second text input widget. It also impacts the visual size of the slider - I think it is important to keep it compact. I am probably 50/50 myself. |
The layout of the slider is not actually changed. If the slider is created with If readout is disabled, no label is displayed and this does nothing. The use case is wanting to normally be able to try a range of values, in typical data-exploration style, but occasionally wanting to be able to cherry-pick a specific (probably round) value which mouse resolution makes difficult to select with the slider (eg, when you can only manage to select 99 or 101). This I would assert is something that people might want to do relatively often without wanting to go back and alter the slider parameters or set up a bound text entry widget. The change consists only of setting the |
|
I think this implementation is overly complicated- it seems like you are just reimplementing the IntTextView and FloatTextView here. Did you look at replacing the readout with them instead? |
Using It is true that the |
@jdfreder https://gist.github.com/chronitis/5bb76f913aa91eebc177 shows a possible re-working (the common validate and update logic is removed from both widgets to a separate function). I'm not sure if this actually makes it more readable though - let me know if this seems a reasonable direction and I'll commit this to the PR. |
Not using content editable makes it work better for numeric input on mobile, I think. For example, see http://sagecell.sagemath.org/?q=dxgrse |
http://caniuse.com/#feat=contenteditable claims very wide support (everything minus android 2.3 and opera mini) for |
but the input also pulls up a numeric keyboard on mobile, IIRC. Would contenteditable? I think mobile in general has a hard time with knowing when to pull up a keyboard on content editable, and definitely wouldn't know to bring up a numeric keyboard. |
@jdfreder @jasongrout @SylvainCorlay can you folks make a decision on this widget related PR and push it through review. In our call today, we decided that in principle we are OK with it - but you 3 should make the final decision. |
I have not read the code yet. I imagine that one may not want to enable |
I can add a trait to the widget that disables this behaviour easily (and will, if there is consensus to do so) - but I wonder if doing it on a per-widget basis makes sense? It is not obvious to me that a user is likely to care enough to selectively disable this on certain sliders (or other widgets) but not others. A global option to enable or disable use of |
If that's the case, then it would make more sense to have a subclass the user can use that has the current behavior, rather than a global option. |
I think we ought to just enable it always, and wait for usecases to come up where you don't want enabled before adding an option to turn it off. |
TODO: I'm going to review the gist you published. Sorry for the delay, I've been away a couple of weeks. |
@@ -9,6 +9,10 @@ define([ | |||
var IntTextView = int_widgets.IntTextView; | |||
|
|||
var FloatSliderView = IntSliderView.extend({ | |||
_parse_text_input: parseFloat, | |||
|
|||
_range_regex: /^\s*([+-]?\d*\.?\d+)\s*[-:]\s*([+-]?\d*\.?\d+)/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be ^\s*([+-]?\d*\.?\d?)\s*[-:]\s*([+-]?\d*\.?\d?)
which allows the python shorthand float declaration, i.e. 1.-2.
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As written this matches a lone decimal point, and does not match numbers with >1 decimal place - but I agree with the point. I'll fix it so it matches 1.
.
Edit: I think ([+-]?(?:\d*\.?\d+|\d+\.)(?:[eE][+-]?\d+)?)
(x2) matches all appropriate patterns, including exponents (which are probably wanted for scientific use).
Hey @chronitis , thanks for trying this. This isn't actually what I was envisioning, I was talking about scrapping the use of content-editable all together and just re-using the numeric text widgets as readouts (of course with some styling changes). I don't think this makes sense anymore, now that the slider widgets support value ranges. I added a couple of comments inline, otherwise the code looks good. |
} else { | ||
// clamp to range | ||
values = [Math.max(Math.min(values[0], vmax), vmin), | ||
Math.max(Math.min(values[1], vmax), vmin)]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first glance I thought this would cause trouble, since you do not check if min and max are undefined, but the widget won't exist in the front-end until it's been opened from the back-end, and the second it's opened from the back-end, a full state is pushed. When a widget like this is opened from the front-end, it will be important to remember that some values have to be defined on the model before it will work properly (this is probably not the only place) @jasongrout @SylvainCorlay .
Leaving on need review (cause we need to finish reviewing), but will need a rebase at some point also. |
fec3566
to
e4c2069
Compare
Rebased to current master. |
}, | ||
|
||
handleKeyDown: function(e) { | ||
if (e.keyCode == 13) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to require static/base/js/keyboard
and user keycode.enter
here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for this suggestion
Looks good. I had a quick overview, but I'm not conforable on widgets. One potential minor comment to use explicit keymap with enter instead of hardcoded 13. |
Thanks @chronitis this looks good. I'm marking it as ready to merge and I'll let someone else click the button! |
Agreed looks good. I'll push the green button. |
Allow text input on slider widgets
Allow text input on slider widgets
This adds "click-to-edit" to the text readout to the right of a slider, allowing precise values to be set.
Changes are entirely on the javascript. Editing is handled using the HTML5
contentEditable
attribute rather than explicitly creating any input widget. The modified value is committed by either clicking outside the text, or pressing enter. Works for bothInt
andFloatSliderView
.The new value is validated for float/int and min/max, but the step size (if set) is not enforced.
This will need updating if #6050 is merged.