コンテンツにスキップ

useTextDirection

カテゴリ
エクスポートサイズ
821 B
最終更新日
先週

要素のテキストのリアクティブな dir

デモ

この段落は英語で、正しく左から右に進みます。


クリックして方向を変更

使用法

ts
import { useTextDirection } from '@vueuse/core'

const dir = useTextDirection() // Ref<'ltr' | 'rtl' | 'auto'>

デフォルトでは、例えば、dir `rtl` が `html` タグに適用されている場合、`rtl` 方向を返します。

html
<!--ltr-->
<html>
  ...
</html>

<!--rtl-->
<html dir="rtl">
  ...
</html>

オプション

ts
import { useTextDirection } from '@vueuse/core'

const mode = useTextDirection({
  selector: 'body'
}) // Ref<'ltr' | 'rtl' | 'auto'>

型宣言

typescript
export type UseTextDirectionValue = "ltr" | "rtl" | "auto"
export interface UseTextDirectionOptions extends ConfigurableDocument {
  /**
   * CSS Selector for the target element applying to
   *
   * @default 'html'
   */
  selector?: string
  /**
   * Observe `document.querySelector(selector)` changes using MutationObserve
   *
   * @default false
   */
  observe?: boolean
  /**
   * Initial value
   *
   * @default 'ltr'
   */
  initialValue?: UseTextDirectionValue
}
/**
 * Reactive dir of the element's text.
 *
 * @see https://vueuse.dokyumento.jp/useTextDirection
 */
export declare function useTextDirection(
  options?: UseTextDirectionOptions,
): WritableComputedRef<UseTextDirectionValue, UseTextDirectionValue>

ソース

ソースデモドキュメント

貢献者

Anthony Fu
iChengbo
Anthony Fu
Eyal Peleg
Nestor Vera

変更履歴

v12.0.0-beta.1 on 2024/11/21
0a9ed - feat!: Vue 2 のサポートを廃止、バンドルの最適化、クリーンアップ (#4349)

MITライセンスの下でリリースされています。