Components: Fix RTL on Flex component#33729
Conversation
sarayourfriend
left a comment
There was a problem hiding this comment.
Thank you for the fix!
There was a problem hiding this comment.
Thank you for working on this, @walbo !
For ease of review, noting that the only significant code changes are in the in the useFlex hook, where the marginLeft and marginRight CSS properties are being wrapped in the rtl() utility function (which is able to switch left and right CSS props when a RTL language is detected at component "mount time").
Every other code change is caused by auto-formatting (and consequently, by spacing updates in the unit test snapshots).
For completeness, it would probably be good to replace instances of the words "left" and "right" in the folder, so that the documentation also doesn't assume LTR languages. A few instances I found:
Finally, should we add a unit test for RTL styles? (maybe we could mock the isRTL function for that specific test, in order to force rtl styles to be applied?)
|
Looks like the I'll take a look at adding an RTL unit test later today (or tomorrow). @ciampo to you know if there is an existing test that has mocked RTL for reference? |
Not that I know — but I'd probably look into mocking the jest.mock( '@wordpress/i18n', () => ( {
...jest.requireActual( '@wordpress/i18n' ),
isRTL: jest.fn( () => true ),
} ) );and then, maybe, later in the single test, change the implementation of ... and either do a snapshot test of a component rendered with RTL locale, or maybe even do a diff snapshot between the LTR and the RTL version of the same snippet? |
|
To be fair we don't do these kinds of tests literally anywhere else in Gutenberg, do we? I'm not sure they bring that much value to something as declarative as styles 🤷 The The best way to test that RTL styles are working properly is probably something like visual regression testing with various locales. 🤔 But that's not something we have the infrastructure for at the moment. |
|
I agree with @sarayourfriend about the test. Adding ex a snapshot test will only confirm that the Added |
Sure, let's drop the unit tests.
Is this |
It work if I run The example added in #33882 fails. |
This is expected. As mentioned in an earlier comment, interpolated functions only work for Since in this case we're using the |
Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com>
Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com>
Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com>
|
Thanks for the clarification @ciampo I belive this is ready then. |
ciampo
left a comment
There was a problem hiding this comment.
Code changes LGTM and test well as per instructions! Thank you @walbo for working on this 🚀
One last thing, before merging — could you add an entry for this bug fix in the "Unreleased" section of packages/components/CHANGELOG.md?
Description
The flex component has some margins to add gaps. These need to be reversed on RTL sites.
How has this been tested?
Tested different location that the component is used with Arabic and English.
Screenshots
Types of changes
Bug fix
Checklist:
*.native.jsfiles for terms that need renaming or removal).