UNPKG

@gravityforms/utils

Version:
26 lines (25 loc) 597 B
/** * @module isRtl * @description Tests if the document is in RTL mode. * * @since 1.0.0 * * @return {boolean} Whether the document is in RTL mode. * * @example * import { isRtl } from "@gravityforms/utils"; * * function Example() { * if ( isRtl() ) { * // do something * } * } * */ export default function isRtl() { const rtlTest = document.createElement( 'div' ); document.body.appendChild( rtlTest ); const isRtlMode = window.getComputedStyle( rtlTest, null ).getPropertyValue( 'direction' ) === 'rtl'; document.body.removeChild( rtlTest ); return isRtlMode; }