getTextDirection

Category Browser

Indicates the text writing directionality of the content of an element.

You can set a value to change the dir property on the element.

Demo

This paragraph is in English and correctly goes left to right.


Click to change the direction

Type Definitions

import { type ConfigurableDocument } from '../__internal__/configurable.js';
import type { CleanupFunction, MaybeElement, MaybeGetter } from '../__internal__/types.js';
type GetTextDirectionValue = 'auto' | 'ltr' | 'rtl';
interface GetTextDirectionOptions extends ConfigurableDocument {
    /**
     * Whether to auto-cleanup the observer or not.
     *
     * If set to `true`, it must run in the component initialization lifecycle.
     * @default true
     */
    autoCleanup?: boolean;
    /**
     * The element on which to control the text direction.
     * @default document.documentElement
     */
    element?: MaybeGetter<MaybeElement>;
    /**
     * Whether to observe changes on the element via the `Mutation Observer API`.
     * @default false
     */
    observe?: boolean;
    /**
     * The initial direction of the element.
     * @note This value is discarded if the `dir` property already exists on the element and `override` is set to `false`.
     * @default 'ltr'
     */
    initial?: GetTextDirectionValue | null;
}
type GetTextDirectionReturn = {
    current: GetTextDirectionValue;
    /**
     * Removes the attribute from the element while not changing the `current` property.
     * @note If `observe` is `true`, `current` will be set to `initial`.
     */
    removeAttribute: () => void;
    cleanup: CleanupFunction;
};
/**
 * Indicates the text writing directionality of the content of an element.
 * @param options Additional options to customize the behavior.
 * @see https://svelte-librarian.github.io/sv-use/docs/core/get-text-direction
 */
export declare function getTextDirection(options?: GetTextDirectionOptions): GetTextDirectionReturn;
export {};

Sources