This is an attempt to add support for RTL. I have not tested all possibilities but it seems to work well on the few cases I tried. While I ported everything to logical properties, I only tried the RTL (I am not aware of any language reversing the block order).
Here are the main changes that have been done:
Using logical property instead of non-logical properties when applicable (eg. scrollMarginLeft => scrollMarginBlockStart)
Normalize properties that do not have logical equivalent:
getBoundingClientRect are reversed (left becomes right and vice versa) and normalize with the viewport width
scrollLeft is normalized as it returns negative values in RTL context
Finally, at the final step, the left scroll is negated as in RTL scrolling requires negative value
I decided to keep "left" and "top" at the final step (what is returned to calculations) because the native scrollIntoView, scrollTo, scrollBy... do not support logical property so it would be confusing for the library consumer.
I am not 100% confident of all the changes, and I have no guarantee that all situations work properly, but this should be a good start to provide RTL feature.
EDIT: for the implementation I decided to rely on "document.dir" instead of having an extra option in the library. I know some librairies explicitly require a direction option, but a lot of thing break in RTL context if the document does not have the dir="rtl" attribute set, so I think we should do this to encourage people to add the correct attribute on the document.
Hi !
This is an attempt to add support for RTL. I have not tested all possibilities but it seems to work well on the few cases I tried. While I ported everything to logical properties, I only tried the RTL (I am not aware of any language reversing the block order).
Here are the main changes that have been done:
I decided to keep "left" and "top" at the final step (what is returned to calculations) because the native scrollIntoView, scrollTo, scrollBy... do not support logical property so it would be confusing for the library consumer.
I am not 100% confident of all the changes, and I have no guarantee that all situations work properly, but this should be a good start to provide RTL feature.
EDIT: for the implementation I decided to rely on "document.dir" instead of having an extra option in the library. I know some librairies explicitly require a direction option, but a lot of thing break in RTL context if the document does not have the
dir="rtl"
attribute set, so I think we should do this to encourage people to add the correct attribute on the document.