-
-
Notifications
You must be signed in to change notification settings - Fork 225
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: RTL support #791
Slider: RTL support #791
Conversation
🦋 Changeset detectedLatest commit: 65b4cde The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Hey @abdel-17 thanks for taking the time to tackle this! I think a better approach in terms of DX would be to add a Alternatively, we could make the prop The reasoning for this is that the orientation doesn't actually change with RTL, but rather the behavior of that orientation, so it doesn't make much sense to couple them like that! This would clean things up and enable devs to implement things like a "toggle rtl" much easier since we could add that same prop to all other components as we add RTL support and it will be a matter of changing a single prop! |
Hey @huntabyte, |
I know for a fact we should have either a My thinking behind the whole I noticed on Discord you sent the following:
With this being the case, then we only really need |
src/docs/content/builders/slider.md
Outdated
You can set the `orientation` prop to `horizontal-rl` for right-to-left orientation. Here's an | ||
example: |
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.
You can set the `orientation` prop to `horizontal-rl` for right-to-left orientation. Here's an | |
example: | |
To enable Right-to-Left (RTL) support, you can set the `rtl` prop to `true. | |
Here's an example of a horizontal slider with RTL enabled: |
src/docs/content/builders/slider.md
Outdated
Top-to-bottom orientation is also supported by setting `orientation` to `vertical-tb`. Here's an | ||
example: |
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.
Top-to-bottom orientation is also supported by setting `orientation` to `vertical-tb`. Here's an | |
example: | |
In a Right-to-Left (RTL) context, vertical sliders function from top to bottom instead of bottom to top. Here's an example of a vertical slider with RTL enabled: |
elements: { root, range, thumb }, | ||
states: { value }, | ||
} = createSlider({ | ||
orientation: 'horizontal-rl', |
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.
orientation: 'horizontal-rl', | |
rtl: true, | |
orientation: "horizontal" |
elements: { root, range, thumb }, | ||
states: { value }, | ||
} = createSlider({ | ||
orientation: 'vertical-tb', |
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.
orientation: 'vertical-tb', | |
rtl: true | |
orientation: 'vertical', |
src/lib/builders/slider/types.ts
Outdated
@@ -4,7 +4,7 @@ import type { Writable } from 'svelte/store'; | |||
import type { createSlider } from './create.js'; | |||
export type { SliderComponentEvents } from './events.js'; | |||
|
|||
export type SliderOrientation = 'horizontal' | 'vertical'; | |||
export type SliderOrientation = 'horizontal' | 'horizontal-rl' | 'vertical' | 'vertical-tb'; |
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.
export type SliderOrientation = 'horizontal' | 'horizontal-rl' | 'vertical' | 'vertical-tb'; | |
export type SliderOrientation = 'horizontal' | 'vertical'; |
This reverts commit 1ffe7cc.
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.
Thank you so much! I left some comments 🙂
src/lib/builders/slider/create.ts
Outdated
disabled: disabledAttr($disabled), | ||
'aria-disabled': ariaDisabledAttr($disabled), | ||
'aria-disabled': disabledAttr($disabled), | ||
// TODO: Is aria-orientation missing 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.
It is!
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.
So, about that. I did some research and apparently the aria-disabled
and aria-orientation
attributes should be on the thumb, not the root. That's a breaking change.
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.
No worries, we can change these. We can keep the data-attributes on the root as well though
src/lib/builders/slider/create.ts
Outdated
style.translate = horizontal ? '-100% 0' : '0 100%'; | ||
} else if (index !== 0) { | ||
style.translate = horizontal ? '-50% 0' : '0 50%'; | ||
if ($orientation === 'horizontal' && $dir === 'rtl') { |
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.
These ifs can be a bit complex too, something similar to what i've shown before would be useful 😄
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.
These ifs can be a bit complex too, something similar to what i've shown before would be useful 😄
I'm not the biggest fan of ternaries, personally, but I'll fix the ifs. I wish JS had native pattern matching or switch statements with multiple values.
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.
Hey! So I just pushed the changes. I chose a different approach from ternary statements. If you still prefer ternaries, I have no problem refactoring the code, but I think the new changes are much more readable than both the ternaries and the if statements.
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 do prefer the ternaries, but the direction derived with the switch case is pretty nice too 😄 You can keep it!
// TODO: Consider removing `aria-disabled` from here. | ||
// `aria-disabled` doesn't make sense on the root | ||
// because the slider `role` is on the thumb. |
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.
Let's do it, we can keep the data attribute
Co-authored-by: Thomas G. Lopes <26071571+TGlide@users.noreply.github.com>
Really excited about this pr! 👀
Added two more orientations for sliders,
horizontal-rl
andvertical-tb
, effectively adding RTL support for sliders with an added bonus of top-to-bottom orientation for vertical sliders. I also documented the two orientations.I manually tested all 4 orientations with and without ticks. Everything seems to be placed correctly and keyboard shortcuts work. I haven't added any automated tests, though.