scroll-into-view / compute-scroll-into-view

Utility for calculating what should be scrolled, how it's scrolled is up to you
https://scroll-into-view.dev#scroll-alignment
MIT License
308 stars 27 forks source link

Add support for RTL #907

Open bakura10 opened 11 months ago

bakura10 commented 11 months ago

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.

bakura10 commented 11 months ago

Hi @stipsan , any info on whether this could be merged or not? :)