Skip to content

RTL implementation #30918

@ffoodd

Description

@ffoodd

There have been quite a few dicussions around this in Bootstrap, and it's probably been asked more often than any other feature.

Pre-requisites

  1. Should work in all supported browsers, meaning Edge Legacy and Safari 10 for the oldest.
  2. Should work seamlessly with all our components and utilities.
  3. Should be tested, probably with new examples templates.
  4. Should be maintainable, thus not lay on hacky things.

Am I missing any pre-requisite, @twbs/team?

FWIW, one of the best resource I ever read about RTL is very recent: RTL Styling 101 by Ahmad Shadeed.

Solutions

Let me try to sum up the various ways to tackle this in v5.

Another dist file

This is what we used in Boosted v4, using rtlcss.

Pros

  • another file, not a single bloated one
  • easy to setup

Cons

Logical properties

They're meant to be the standard way to do. However Edge Legacy doesn't support them, so we're kinda stuck with this.

PostCSS-logical is meant to handle this in two ways:

  1. each logical property results in two new declarations, suffixed with :dir()
  2. each logical property only gets a LTR fallback: text-align: left; text-align: start;

Both of them will result in a bloated filesize, and the second—despite being the ordinary fallback—won't allow Edge Legacy to handle RTL.

Pros

  • future-proof
  • standardized and CSS-y

Cons

  • Lack of support
  • Filesize (directly due to the lack of support)

Resources

Sassy way

As suggested in the most recent issue about RTL— #28797— a sassy way is possible.

I'd be in favor of a simpler way to handle things:

  • using a mixin, like we do for media queries: @include rtl()
  • checking for a boolean before going ahead, like we do for shadows or rounded: @if $enable-rtl {}
  • then wrapping mixin content in :dir(rtl) using @content
  • and then, just use CSS.

Pros

  • Sass only
  • Consistent with our current way to do things
  • Can be false by default

Cons

  • Requires that we write the RTL styles by ourselves
  • Source code bloat
  • A single bloated output when enabled

So…

My CSS geekery would like to go with Logical properties; rtlcss seems simpler to me since I'm already used to it and it's a robust and proven solution; the sassy way looks a bit naive…

I'd like to hear opinions and suggestions before trying something.

Related issues

Thanks @zaidbarghouthi for listing this!

#28797 #28238 #24807 #27123 #27122 #26879 #26818 #19545 #26299 #25422 #24662 #23703 #24332 #23117 #22708 #22137 #21619 #21180 #20293 #19555 #20075 #19787 #19703 #19668 #19643 #19545 #19379 #18184 #17595 #16455 #16419 #15717 #15700 #15509 #15479 #15433 #14717 #14510 #13564

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions