-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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] Add support for Arrow Down/Up + Shift and Page Up/Down keys #40676
Conversation
@@ -296,6 +297,89 @@ export function useSlider(parameters: UseSliderParameters): UseSliderReturnValue | |||
otherHandlers?.onBlur?.(event); | |||
}; | |||
|
|||
const changeValue = (event: React.KeyboardEvent | React.ChangeEvent, valueInput: number) => { |
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've extracted the previous createHandleHiddenInputChange
logic in a new method that can be re-used in two places now. The only difference is how we read the value (from the input target, or calculating it in case the PageUp/PageDown arrows are used.
Netlify deploy preview
@material-ui/core: parsed: +0.09% , gzip: +0.12% Bundle size reportDetails of bundle changes (Toolpad) |
@@ -9,6 +9,7 @@ export default function DiscreteSlider() { | |||
aria-label="Temperature" | |||
defaultValue={30} | |||
getAriaValueText={valuetext} | |||
pageStep={3} |
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.
Using a smaller pageStep
on the discrete sliders looks better.
It seems that shift+right is incrementing the slider value by To avoid this, I think I'd be in favour of changing how that works to one of these options:
|
Thanks for checking this Colm!
It should be incremented by 10, pageStep = step * pageStep - this should end up being 10 still. Do you have an example of this? I haven't caught this with the tests.
On 2. - this is what I initially thought the API should look like. The reason why I ended up multiplying these two values was because it made more sense in the cases when cc @DiegoAndai @michaldudak what are your thoughts? Considering this will affect both Base UI and Material UI? |
lol you're right, math is hard 😄 Video attached of the first docs example in the deploy preview. The value is initially set to '0'. Then I press Shift+Right, and it increments by '11'. Screen.Recording.2024-01-18.at.16.32.48.mp4
I'm not sure this is necessarily an issue, especially since the user configures the values themselves. I think having the two step increments dependent on each other is more of an issue, because it makes certain configurations more complicated. Let's say I want So I think the issue with the dependency between the two props is that it's not inherent or explicitly communicated. It's kind of just magic, which I think will probably be confusing. I think if both props are independent, we just let the user set their own values and it's up to them how the slider works. |
Yeah, ok fair enough. I will update the PR and check the issue from the video. Maybe the input type="range" increments on each Arrow Right by one too. |
Regarding the
So for example:
|
I am not 100% sure about this. It works for the examples you provided, but for e.g. if we have values from 1 to 100, with step of 10, it will fail again. It would be simpler to just say, by default the page step is 10, and for any other value, override it. |
I misread this part of @DiegoAndai's comment when I put my thumbs up. This is an example of the magic I was referring to above. Nothing tells me about the dependency between the two props, one prop just updates the other without me telling it to work like that. Imagine you set
It also causes problems/confusion like in this example from @mnajdova.
imo this is the simplest and best API. |
Cool, the API is updated based on the conclusion (I've also updated the PR description). We can move into reviewing the logic next. |
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.
Tested it in the docs and LGTM 👍
Fixes #40611
Some design decisions:
pageStep
value with a value dividable with the step prop.Preview: