-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[material-ui][Slider] Set CSS writing-mode
and update vertical slider docs
#44537
base: master
Are you sure you want to change the base?
Conversation
writing-mode
and update vertical slider docs
4b5574e
to
5c830c3
Compare
Netlify deploy preview@material-ui/core: parsed: +0.12% , gzip: +0.14% Bundle size reportDetails of bundle changes (Toolpad) |
e3164ed
to
0c864c7
Compare
7803c4b
to
64ba470
Compare
Fixed the rest of the comments ~ |
64ba470
to
9fa734e
Compare
9fa734e
to
9dc7bf7
Compare
@mj12albert arrow keys are still reversed. Is that expected? e.g. in https://deploy-preview-44537--material-ui.netlify.app/material-ui/react-slider/#vertical-sliders |
🥲 nope – let me fix this |
Fix for reversed arrow keys is still pending
ecd4102
to
c865329
Compare
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.
Behavior wise, it looks good. I left some inline comments.
Do you think any of the introduced changes could be considered breaking? I think this PR has grown to be more than what the PR description states. I'm tagging @DiegoAndai for an additional review.
**WARNING**: Chrome, Safari and newer Edge versions that is any browser based on WebKit exposes `<Slider orientation="vertical" />` as horizontal ([chromium issue #40736841](https://issues.chromium.org/issues/40736841)). | ||
By applying `-webkit-appearance: slider-vertical;` the slider is exposed as vertical. | ||
:::warning | ||
Chrome versions below 124 implement `aria-orientation` incorrectly for vertical sliders and exposes them as `'horizontal'` in the accessibility tree. ([Chromium issue #40736841](https://issues.chromium.org/issues/40736841)) |
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.
Chrome versions below 124 implement `aria-orientation` incorrectly for vertical sliders and exposes them as `'horizontal'` in the accessibility tree. ([Chromium issue #40736841](https://issues.chromium.org/issues/40736841)) | |
Chrome versions below 124 implement `aria-orientation` incorrectly for vertical sliders and expose them as `'horizontal'` in the accessibility tree. ([Chromium issue #40736841](https://issues.chromium.org/issues/40736841)) |
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.
Ping
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.
9f9587c
Fixed ~ @aarongarciah
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 we really need these constants? The values of the constants could be considered constants themselves.
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.
The values of the constants could be considered constants themselves.
@aarongarciah, what do you mean?
I think handling the key constants like this is something we should've done in Material UI long ago to avoid typos. How is Base UI handling this?
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 mean I don't see an improvements when reading
event.key === ARROW_UP
vs
event.key === 'ArrowUp'
The latter is one less file. I also don't see the point on defining these constants at the component level. The downside is potential typos. If we have a convention for this we should just follow the convention and forget my comment. I'm just wary of creating unnecessary abstractions, but that's a personal preference.
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.
Yes, I would say the only upside of the constants is avoiding typos, and there should be a convention but that's out of scope for this PR. I also agree these shouldn't be defined at the component level.
I would revert this change in this PR, and create an issue to eventually implement the convention throughout the components.
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.
We made them all constants, exactly to avoid typos ~ https://github.com/mui/base-ui/blob/master/packages/react/src/composite/composite.ts#L12-L24
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 believe there's also a performance gain from this, although I don't know how much: https://www.notion.so/mui-org/Performance-guide-memory-allocations-134cbfe7b66080cba325db614278fc20?pvs=4#134cbfe7b6608042afb5f000dca0ab4f
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 would revert this change in this PR, and create an issue to eventually implement the convention throughout the components.
OK then ~
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.
Looks like some of the tests are being repeated in different blocks. Do you think we need that repetition?
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 agree. For example, if the "Home" and "End" keys have the same behavior on LTR and RTL, we can rely on the LTR tests and not repeat them for RTL.
Do you see some value in the repetition @mj12albert?
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.
To make it easier to read and at least appear less repetitive, let's just have one single describe('keyboard interactions'...
and organize everything in there instead of spreading it out (this file is very long already): 93083a8
Do you see some value in the repetition
Yes! Better safe than sorry, the combination of direction/orientation/various keys gets confusing 😅
In particular, I think it's important to repeat a bunch of combinations for the when step is null and restricted by marks
version of the slider, as it almost becomes a different component
Regarding:
From the description:
I think this will be considered a breaking change for people using RTL 🤔 It might not, but we have had people complain in the past about changing an element's @aarongarciah @mj12albert can you think of other changes that could be considered breaking? What do you think about adding it as an opt-in API and making it the default in the next major?
Would it be possible to split this into two PRs? One with the |
This rendering thing only affects the native The only (breaking) user-facing change, is that previously if you had a
So to opt-in to the "unreversed" arrow keys, you would be un-doing It only be breaking if you were actually using the "reversed" left/right arrow keys before (that our docs were recommending you suppress!) which I would guess most users would not be doing Does that makes sense? It's confusing, as there are actually 3 different factors to consider (orientation, text direction, "polarity") @DiegoAndai @aarongarciah
That is OK too, let's do this then ~ the only quirk is that the writing-mode only PR would still have to (temporarily) explain why the left/right arrow keys appear reversed as the reason is now differen – with |
Thanks for the quick response @mj12albert 😊 Let me know if I understand correctly:
So, the Material UI Slider will still be rendered bottom-to-top for both LRT and RTL?
The changes would be:
Is that right?
Ok, so splitting them is not a great idea either. I was thinking the refactor was completely separate from the fix. With this explanation I would keep both changes in the same PR. I would revert the constants and open a separate issue to do the same Base UI does, though. |
7d37ac7
to
0304fad
Compare
0304fad
to
cc32deb
Compare
Yes ~ sandbox here just to be sure: https://codesandbox.io/p/sandbox/material-ui-slider-writing-mode-jkw4kn?file=%2Fsrc%2FApp.js%3A1%2C1
Yes ~ thats correct, I've also removed the constants now @DiegoAndai |
Clarification: I may not have been specific enough here (though this is just to document the fact and doesn't affect the PR now) - with |
@mj12albert I'm confused, you shared two demos:
In the first one, both sliders increase with the Up Arrow But both have |
This first one is with the fixes in this PR!
This second one is just a fork of the |
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.
This first one is with the fixes in this PR!
This second one is just a fork of the VerticalAccessibleSlider demo on master
I see, it makes sense now 😅.
From the description:
Handle all keypresses in the keydown handler instead of splitting them across the keydown and change handlers
I see that in this PR we're handling all keys in the keydown handler, but I don't see the removal from the change handlers. Am I missing something?
@aarongarciah If we released this in a minor version, we would have to add an explanation to the changelog. The breaking change would be that for the users who didn't follow our recommendation of preventing default. For them, the left/right arrow keys would be swapped when updating.
I consider it a 'softer' breaking change as it will only affect people who didn't follow the recommendation. But, there will probably be some users that notice the change and are not happy with it, so if we wanted to play it extra safe, we could hold until v7. Your call.
|
||
{{"demo": "VerticalAccessibleSlider.js"}} | ||
For Chrome 124 and newer, the slider includes the CSS [`writing-mode`](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_writing_modes/Vertical_controls#range_sliders_meters_and_progress_bars) property that fixes this bug. |
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.
Users don't have to add this themselves, right? I would remove/rewrite this, otherwise I think people might think they need to provide it themselves.
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.
Updated!
I think we can ship this in a minor. |
f463c0f |
I didn't explain my question well enough 😅 here it goes again:
|
@DiegoAndai In the keydown handler, material-ui/packages/mui-material/src/Slider/useSlider.ts Lines 357 to 371 in c279aea
So it wouldn't get handled twice (I think lots of tests would have broke if it did) |
writing-mode
property in the<input type="range">
element's styles to ensureorientation
is exposed correctly in the accessibility treefireEvent.keyDown
, most of the existing tests usefireEvent.change
which did not catch some incorrect behaviorskeydown
handler instead of splitting them across thekeydown
andchange
handlers. This takes care of a side effect of using CSSwriting-mode
to fix the a11y issue – it causes native range inputs to render top-to-bottom in LTR (reference), and bottom-to-top in RTL, which is counter-intuitive 😆 (but its the spec).Closes #44237