Skip to content
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

Convert all UI code to CSS logical properties #8051

Merged
merged 3 commits into from
Mar 15, 2022

Conversation

thibaudcolas
Copy link
Member

@thibaudcolas thibaudcolas commented Feb 28, 2022

A large step towards RTL support (#7793) – this changes all of our existing styles to use CSS logical properties and values, and sets up linting to prevent future usage of left and right in properties as set up our Stylelint configuration.

The stylesheet changes were largely mechanical – this was more complex than expected for a few reasons:

  • For inset positioning, our browser support targets don’t allow us to fully drop left/right positions.
  • For per-corner border radius, same story
  • float support for flow-relative values is much poorer than I thought – we should likely stop using float for layout altogether.

The linting changes were made more complex by the same issues!

@thibaudcolas thibaudcolas added Accessibility component:i18n i18n for content created in Wagtail, not the admin UI itself status:Needs Review type:Cleanup/Optimisation labels Feb 28, 2022
@thibaudcolas thibaudcolas self-assigned this Feb 28, 2022
@thibaudcolas thibaudcolas added this to the 2.17 milestone Feb 28, 2022
@thibaudcolas thibaudcolas changed the title WIP: Logical properties CSS WIP: Convert all UI code to CSS logical properties Feb 28, 2022

&:before {
font-size: 1rem;
position: absolute;
// Remove once we drop support for Safari 13.
// stylelint-disable-next-line property-disallowed-list
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an idea - should we create a mixin? @include safari { left: 0; }
Something like that might help to be explicit and also allows us to use a media / supports selector to house the enclosed styles.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We’ve discussed this together at the last UI team meeting – I chose to keep this like this because I’d like it to go away in the next + 1 release (August 2022, so we’ll be able to remove this code after the May 2022 release’s code freeze – late April). Hard-coding the styles like this is the pattern that will be the simplest to remove mechanically in 1 month’s time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

// 'float': ['inline-start', 'inline-end', 'none', 'unset'],
'text-align': ['start', 'end', 'center'],
},
// Disable declaration-strict-value until we are in a position to enforce it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the plan to use a newer version of the Wagtail stylelint LIbrary? - let me know if you need me to do a new release of that library to help.

Ignore this if you were just adding this temporarily.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose to fully disable this because the needed refactorings would be distracting to what this PR is trying to achieve (and the PR is already big as-is). Once this gets merged, we can create a follow-up task to gradually enforce this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Thanks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Thanks

@kaedroho
Copy link
Contributor

kaedroho commented Mar 1, 2022

Thanks for this @thibaudcolas!

I'm wondering what the advantage of using CSS logical properties is for Wagtail over width/height/left/right/etc?

The existing physical properties are quite easy for most developers to understand. I'm concerned that unless developers use local properties often, these properties might add a lot of extra cognitive load when writing new CSS.

@lb-
Copy link
Member

lb- commented Mar 3, 2022

@thibaudcolas as per discussion today

  • We agree that all the Safari comments are not ideal but it is better than digging to deep into the rabbit hole of a postcss / autoprefixer approach and the caveats with that solution
  • What we should address, outside of this PR, is the overuse of floats and absolute positioning, I have gone about half way through (can try to update tomorrow) and anecdotally it appears that Icons are the most common case of this kind of CSS. Maybe we can split out these things into groups and create some future clean up Issues to remove these cases.
  • For things like tooltips, modal backdrops, dropdowns - we may not really be able to find a better way.
File Usage Type Selector
client/scss/components/_button.scss Icon position .bicolor:before, span.icon-spinner:after, .controls
client/scss/components/_button.scss Other border-radius .bicolor ..icon-wrapper
client/scss/components/_comments-controls.scss Icon position &__icon
client/scss/components/_comments-notification-dropdown.scss Dropdown position ::before
client/scss/components/_dropdown.legacy.scss Dropdown position .dropdown
client/scss/components/_dropdown.legacy Dropdown position .c-dropdown__button
client/scss/overrides/_utilities.dropdowns.scss Dropdown position .u-arrow--tl:before`
client/scss/components/_footer.scss Other position .avatar
client/scss/components/_forms.scss Controls position select ~ span:after
client/scss/components/_forms.scss Icon position ...fields :before/:after
client/scss/components/_forms.scss Controls position .field-comment-control
client/scss/components/_help-block.scss Icon position .help... &:before
client/scss/components/_listing.scss Icon position th.icon, .privacy-indicator
client/scss/components/_loading-mask.scss Other position .loading-mask
client/scss/components/_main-nav.scss Icon position .menu-item a:after, icon--submenu-trigger
client/scss/components/_main-nav.scss Other position .nav-wrapper + lots more
client/scss/components/_modals.scss Other position .modal, .modal-backdrop
client/scss/components/_skiplink.scss Other position .skiplink
client/scss/components/_tabs.scss Controls position .a.errors
client/scss/components/_tooltips.scss Controls position all
client/scss/elements/_elements.scss Unsure position .body:after
client/scss/elements/_forms.scss Icon position input[type='radio']:before
client/scss/objects/_avatar.scss Other position .avatar img

I think this kind of thing is a good reason why we want to try to keep more CSS a lintable format (or restricted by what tailwind classes provide) across the application. And also, not provided too much by external libraries. It is hard enough to get our own core styles written in a way that makes it easy to provide RTL, let alone externally supplied CSS.

It is easy to reach for position: absolute / float but it will keep causing problems if we want to really support RTL and multiple languages well.

@lb-
Copy link
Member

lb- commented Mar 3, 2022

@thibaudcolas
Copy link
Member Author

@kaedroho as LB mentions, the goal is RTL support. In particular supporting RTL languages with as little "RTL overrides" as possible – the styles should just be written with direction-agnostic CSS techniques. Logical properties and values are the simplest way to do this, and are becoming a solid option now that our browser support targets allow us to use them.

We’re only using logical properties/values for RTL mirroring, so there are only 10 or so properties in frequent use, which should be straightforward to get used to (basically left -> inline-start, right -> inline-end).

@thibaudcolas thibaudcolas changed the title WIP: Convert all UI code to CSS logical properties Convert all UI code to CSS logical properties Mar 14, 2022
@thibaudcolas thibaudcolas marked this pull request as ready for review March 14, 2022 15:06
@thibaudcolas
Copy link
Member Author

@fabienheureux @lb- would either of you be ok to review this? So far I have tested this successfully with:

  • My WIP visual regression testing setup – no visual changes in RTL (English) across the tested scenarios in Chrome
  • Manual testing in Safari 13.1

I did basic testing in Arabic as well, which shows promising results, but there is much more to do (too much float usage, lots of directional icons).

Before:

localhost_8000_admin_pages_60_edit_ (2)

After:

localhost_8000_admin_pages_60_edit_ (4)

@lb- lb- self-requested a review March 14, 2022 20:52
Copy link
Member

@lb- lb- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me @thibaudcolas

@squash-labs
Copy link

squash-labs bot commented Mar 15, 2022

Manage this branch in Squash

Test this branch here: https://thibaudcolasfeaturertl-logical-njxbd.squash.io

@thibaudcolas thibaudcolas merged commit 14280ad into wagtail:main Mar 15, 2022
@thibaudcolas thibaudcolas deleted the feature/rtl-logical-css branch March 15, 2022 13:21
@thibaudcolas thibaudcolas removed the request for review from fabienheureux March 15, 2022 13:22
@thibaudcolas thibaudcolas mentioned this pull request Mar 15, 2022
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accessibility component:i18n i18n for content created in Wagtail, not the admin UI itself type:Cleanup/Optimisation
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants