I think is better to make isRtl a function that accepts an element parameter, you can get the computed style of that particular element instead of assuming that the root element is always the relevant one but if the element is omitted we can use document.documentElement as a fallback.
Here's an example implementation of isRtl() as a function that accepts an element parameter and returns true if the element's computed direction style is "rtl" (right-to-left), and false otherwise
function isRtl(element = document.documentElement) {
const computedStyle = window.getComputedStyle(element);
const direction = computedStyle.getPropertyValue('direction');
return direction === 'rtl';
}
https://github.com/argyleink/roving-ux/blob/bbeb45407c1ead893b2611a42dbed2709ea4b160/index.js#L2
I think is better to make isRtl a function that accepts an element parameter, you can get the computed style of that particular element instead of assuming that the root element is always the relevant one but if the element is omitted we can use document.documentElement as a fallback.
Here's an example implementation of isRtl() as a function that accepts an element parameter and returns true if the element's computed direction style is "rtl" (right-to-left), and false otherwise