diff --git a/components/chip/API.md b/components/chip/API.md
index 5a44398971..776bddd298 100644
--- a/components/chip/API.md
+++ b/components/chip/API.md
@@ -22,8 +22,10 @@ import { Chip } from '@dhis2-ui/chip'
|dragging|boolean||||
|icon|element||||
|marginBottom|number|`4`||`margin-bottom` value, applied in `px`|
-|marginLeft|number|`4`||`margin-left` value, applied in `px`|
-|marginRight|number|`4`||`margin-right` value, applied in `px`|
+|marginInlineStart|number|`4`||`margin-inline-start` value, applied in `px`|
+|marginLeft|number|`4`||`margin-inline-start` value if marginInlineStart is not provided, applied in `px`|
+|marginInlineEnd|number|`4`||`margin-inline-end` value, applied in `px`|
+|marginRight|number|`4`||`margin-inline-end` value if marginInlineEnd is not provided, applied in `px`|
|marginTop|number|`4`||`margin-top` value, applied in `px`|
|overflow|boolean||||
|selected|boolean||||
diff --git a/components/divider/src/divider.js b/components/divider/src/divider.js
index d2bdec0d1a..7efd0371b1 100644
--- a/components/divider/src/divider.js
+++ b/components/divider/src/divider.js
@@ -2,18 +2,20 @@ import { colors, spacers } from '@dhis2/ui-constants'
import PropTypes from 'prop-types'
import React from 'react'
-const Divider = ({ className, dataTest, dense, margin }) => {
- let rtlMargin = margin
+const flipMargin = (margin) => {
const splitMargin = margin.split(' ')
if (splitMargin?.length === 4) {
- rtlMargin = [
+ return [
splitMargin[0],
splitMargin[3],
splitMargin[2],
splitMargin[1],
].join(' ')
}
+ return margin
+}
+const Divider = ({ className, dataTest, dense, margin }) => {
return (
diff --git a/components/popper/src/popper.js b/components/popper/src/popper.js
index e046dbcba2..453e3a067f 100644
--- a/components/popper/src/popper.js
+++ b/components/popper/src/popper.js
@@ -5,6 +5,16 @@ import { usePopper } from 'react-popper'
import { getReferenceElement } from './get-reference-element.js'
import { deduplicateModifiers } from './modifiers.js'
+const flipPlacement = (placement) => {
+ if (placement.startsWith('right')) {
+ return placement.replace('right', 'left')
+ }
+ if (placement.startsWith('left')) {
+ return placement.replace('left', 'right')
+ }
+ return placement
+}
+
const Popper = ({
children,
className,
@@ -32,7 +42,10 @@ const Popper = ({
const { styles, attributes } = usePopper(referenceElement, popperElement, {
strategy,
onFirstUpdate,
- placement,
+ placement:
+ document.documentElement.dir === 'rtl'
+ ? flipPlacement(placement)
+ : placement,
modifiers: deduplicatedModifiers,
})
diff --git a/components/popper/src/popper.stories.js b/components/popper/src/popper.stories.js
index f052ce37f5..faba883903 100644
--- a/components/popper/src/popper.stories.js
+++ b/components/popper/src/popper.stories.js
@@ -1,5 +1,5 @@
import { sharedPropTypes } from '@dhis2/ui-constants'
-import React, { useRef } from 'react'
+import React, { useEffect, useRef } from 'react'
import { Popper } from './popper.js'
const description = `
@@ -143,3 +143,20 @@ export const VirtualElementRef = (args) => {
}
VirtualElementRef.args = { placement: 'left-end' }
VirtualElementRef.parameters = { docs: { source: { type: 'code' } } }
+
+export const RTL = (args) => {
+ useEffect(() => {
+ document.documentElement.setAttribute('dir', 'rtl')
+ return () => {
+ document.documentElement.setAttribute('dir', 'ltr')
+ }
+ }, [])
+ return (
+
+ If dir=rtl, `left` and `right` placement are reversed
+
+
+
+
+ )
+}
diff --git a/components/switch/src/switch/switch-icons.js b/components/switch/src/switch/switch-icons.js
index d34d5460fd..cb2b9e8fcd 100644
--- a/components/switch/src/switch/switch-icons.js
+++ b/components/switch/src/switch/switch-icons.js
@@ -116,13 +116,6 @@ export function SwitchRegular({ className }) {
// fill="#FFFFFF"
// fillRule="nonzero"
>
-
', () => {
const left = '200px'
const wrapper = shallow()
- expect(wrapper.html()).toContain(`left: ${left};`)
+ expect(wrapper.html()).toContain(`inset-inline-start: ${left};`)
})
it('accepts a muted prop', () => {
const wrapper = shallow()
diff --git a/components/table/src/data-table/table-elements/__tests__/table-header-cell.test.js b/components/table/src/data-table/table-elements/__tests__/table-header-cell.test.js
index 65968f72a8..4e40ed69c8 100644
--- a/components/table/src/data-table/table-elements/__tests__/table-header-cell.test.js
+++ b/components/table/src/data-table/table-elements/__tests__/table-header-cell.test.js
@@ -77,7 +77,7 @@ describe('', () => {
const left = '200px'
const wrapper = shallow()
- expect(wrapper.html()).toContain(`left: ${left};`)
+ expect(wrapper.html()).toContain(`inset-inline-start: ${left};`)
})
it('accepts an muted prop', () => {
const wrapper = shallow()
diff --git a/components/table/src/data-table/table-elements/table-data-cell/table-data-cell.js b/components/table/src/data-table/table-elements/table-data-cell/table-data-cell.js
index 5dfb7b09d4..ffe7188a46 100644
--- a/components/table/src/data-table/table-elements/table-data-cell/table-data-cell.js
+++ b/components/table/src/data-table/table-elements/table-data-cell/table-data-cell.js
@@ -62,7 +62,7 @@ export const TableDataCell = forwardRef(