Styling approaches for RTL and LTR writing directions #420
Replies: 8 comments 10 replies
-
Thanks for putting this together @jamieomaguire! Fixed! Overall I'm definitely in favour of learning to use CSS logical properties wherever possible for a number of reasons, on top of the ones you gave:
We would need to make sure we have a way of making sure that direction-specific CSS properties like There is also the |
Beta Was this translation helpful? Give feedback.
-
@jamieomaguire thanks a lot for putting this together. I agree with the approaches here. Just a couple bits:
|
Beta Was this translation helpful? Give feedback.
-
Awesome! Thanks for sharing. |
Beta Was this translation helpful? Give feedback.
-
@jamieomaguire thanks for this ❤️ Looks good to me and I'm keen to learn more about CSS logical properties! My main thoughts were it's interesting that JET doesn't have a process for this already! But you covered this by talking to other engineers in that space 😄 My second thought is I suppose we need to be extra clear with making sure people add the |
Beta Was this translation helpful? Give feedback.
-
Another thought I've had:
An example of this can be seen here |
Beta Was this translation helpful? Give feedback.
-
Thanks @jamieomaguire! This looks awesome! I think from a visual testing perspective, it shouldn't be difficult to cover. Couple of points that may be me looking a little more down the road and maybe not a discussion for here. |
Beta Was this translation helpful? Give feedback.
-
Great proposal Jamie! I agree with using CSS Logical Properties with minimal overrides when building new components but for snacks and fozzie components it will mean a lot of manual updates. Do we have a deadline for this? Maybe we can use some tools like https://rtlcss.com/ to automatically mirror directional CSS properties and generate a separate stylesheet for RTL? |
Beta Was this translation helpful? Give feedback.
-
Looks like a very good approach to handling RTL. Great work! One thing I would see us doing going forward is paying close attention to our CSS Logical Properties. Hopefully a linting tool will solve this, but rather than encourage, I'd propose we enforce it, so we can be sure all of our future web components have RTL support. We should also consider documenting this, once signed off, in any styleguides we may have, to ensure the information is available to all new-joiners, as it will be a different way of styling for most. We may also want to backlog a spike to test out RTLCSS on snacks or fozzie, to understand any limitations if we need to go down that route |
Beta Was this translation helpful? Give feedback.
-
Terminology
Overview
When we style components, we want to ensure that they look correct for both RTL and LTR writing directions. This is usually a case of various elements being mirrored (which can mostly be handled by the browser when specifying a
dir
attribute on thehtml
element).There are some additional considerations, however. Browsers will not correct any directional styling applied by CSS. This means that if we use CSS such as
float: left
,padding-right: 24px
ortop: 1em
, this can result in elements looking incorrect in an RTL context. Consider these visual examples below of a typical UI element—a media object.Visual examples
In this first example, the text is flipped. However, the image is floated left and so it looks incorrect in RTL:
In this next example, the layout of the image correctly changes when the writing direction is RTL:
Images borrowed from rtlstyling.com
Another thing to factor in is keyboard navigation and general accessibility requirements. We should ensure that when a component supports RTL, the keyboard navigation and screenreader narration makes sense and follows an order that makes sense to the person interacting with the component.
Approaches
There are a number of ways in which RTL support can be achieved, each with its own pros and cons.
We could look into 3rd party libraries such as RTL CSS which automatically creates a new stylesheet for RTL languages.
We could write our CSS supporting LTR first, then manually apply RTL overrides where appropriate.
An example of this could be:
dir
attribute is correctly set on thehtml
tag.An example of this could be:
Proposal
Having spoken with some engineers at JET who have worked in this space previously, we believe that the most effective approach would be a hybrid of the following:
dir
attribute on theirhtml
element with a RTL or LTR value like so:dir="rtl"
transform: translate()
We believe that a combination of the above will cater to most if not all of our needs when building and styling components that support RTL.
The benefits will be:
Actions to take if the proposal is accepted
padding-left
Summary
We would love to hear people's thoughts on the above proposal. We are still in the early stages and can adjust our proposal based on these discussions, so please leave us feedback!
Useful resources
Beta Was this translation helpful? Give feedback.
All reactions