diff --git a/react-responsive-modal/__tests__/index.test.tsx b/react-responsive-modal/__tests__/index.test.tsx index 4f6014fb..a8695f30 100644 --- a/react-responsive-modal/__tests__/index.test.tsx +++ b/react-responsive-modal/__tests__/index.test.tsx @@ -792,6 +792,28 @@ describe('modal', () => { }); }); + describe('prop: dir', () => { + it('should render the modal with the dir attribute', async () => { + const { getByTestId } = render( + null} dir="rtl"> +
modal content
+
, + ); + + expect(getByTestId('root').getAttribute('dir')).toBe('rtl'); + }); + + it('should not render the dir attribute by default', async () => { + const { getByTestId } = render( + null}> +
modal content
+
, + ); + + expect(getByTestId('root').hasAttribute('dir')).toBe(false); + }); + }); + describe('prop: ref', () => { it('should set the modal element to a ref object', () => { const ref = React.createRef(); diff --git a/react-responsive-modal/src/index.tsx b/react-responsive-modal/src/index.tsx index 7725b781..78465784 100644 --- a/react-responsive-modal/src/index.tsx +++ b/react-responsive-modal/src/index.tsx @@ -131,6 +131,10 @@ export interface ModalProps { * ARIA description for modal */ ariaDescribedby?: string; + /** + * Text direction of the modal content. + */ + dir?: 'ltr' | 'rtl' | 'auto'; /** * Avoid unpleasant flickering effect when body overflow is hidden. For more information see https://www.npmjs.com/package/body-scroll-lock */ @@ -193,6 +197,7 @@ export const Modal = React.forwardRef( onAnimationEnd, children, reserveScrollBarGap, + dir, }: ModalProps, ref: React.ForwardedRef, ) => { @@ -332,6 +337,7 @@ export const Modal = React.forwardRef( className={cx(classes.root, classNames?.root)} style={styles?.root} data-testid="root" + dir={dir} >
void` | | Callback fired when the Modal is requested to be closed by a click on the overlay or when user press esc key. |