Skip to content

Nested Dir #19

@HamzaAmar

Description

@HamzaAmar

const isRtl = window.getComputedStyle(document.documentElement).direction === 'rtl'

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';
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions