mirror of
https://github.com/material-components/material-web.git
synced 2026-03-09 00:09:23 +08:00
21 lines
623 B
TypeScript
21 lines
623 B
TypeScript
/**
|
|
* @license
|
|
* Copyright 2022 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/**
|
|
* Returns `true` if the given element is in a right-to-left direction.
|
|
*
|
|
* @param el Element to determine direction from
|
|
* @param shouldCheck Optional. If `false`, return `false` without checking
|
|
* direction. Determining the direction of `el` is somewhat expensive, so
|
|
* this parameter can be used as a conditional guard. Defaults to `true`.
|
|
*/
|
|
export function isRtl(el: HTMLElement, shouldCheck = true) {
|
|
return (
|
|
shouldCheck &&
|
|
getComputedStyle(el).getPropertyValue('direction').trim() === 'rtl'
|
|
);
|
|
}
|