+ {leftArrowEnabled && (
+ // making a conscious decision to use
over
)
}
diff --git a/packages/components/src/__utilities__/isRTL/index.ts b/packages/components/src/__utilities__/isRTL/index.ts
new file mode 100644
index 00000000000..692938f1210
--- /dev/null
+++ b/packages/components/src/__utilities__/isRTL/index.ts
@@ -0,0 +1 @@
+export * from './isRTL'
diff --git a/packages/components/src/__utilities__/isRTL/isRTL.spec.tsx b/packages/components/src/__utilities__/isRTL/isRTL.spec.tsx
new file mode 100644
index 00000000000..84dcc9fc086
--- /dev/null
+++ b/packages/components/src/__utilities__/isRTL/isRTL.spec.tsx
@@ -0,0 +1,38 @@
+import React from 'react'
+import { render, screen } from '@testing-library/react'
+import { isRTL } from './isRTL'
+
+describe('isRTL', () => {
+ it('returns false when no element with dir found', () => {
+ const Example = (): JSX.Element => Test
+ render()
+ const button = screen.getByRole('button')
+ expect(isRTL(button)).toBe(false)
+ })
+
+ it('returns false when greater parent is dir=rtl, but closer parent is dir=ltr', () => {
+ const Example = (): JSX.Element => (
+
+
+ Test
+
+
+ )
+ render()
+ const button = screen.getByRole('button')
+ expect(isRTL(button)).toBe(false)
+ })
+
+ it('returns true when greater parent is dir=ltr, but closer parent is dir=rtl', () => {
+ const Example = (): JSX.Element => (
+
+
+ Test
+
+
+ )
+ render()
+ const button = screen.getByRole('button')
+ expect(isRTL(button)).toBe(true)
+ })
+})
diff --git a/packages/components/src/__utilities__/isRTL/isRTL.ts b/packages/components/src/__utilities__/isRTL/isRTL.ts
new file mode 100644
index 00000000000..47ac4ca8188
--- /dev/null
+++ b/packages/components/src/__utilities__/isRTL/isRTL.ts
@@ -0,0 +1,6 @@
+/**
+ * Finds the first ancestor with a `dir` property on it
+ * Returning true is that is `dir=rtl` and returning false in all other cases
+ */
+export const isRTL = (element: Element): boolean =>
+ !!element.closest('[dir]')?.matches('[dir="rtl"]')