Direction Provider
Enables RTL behavior for Sveltery Base components.
Anatomy
Import the component and wrap it around your app:
<DirectionProvider> enables child Sveltery Base components to adjust behavior based on RTL text direction, but does not affect HTML and CSS. The dir="rtl" HTML attribute or direction: rtl CSS style must be set additionally by your own application code.
API reference
DirectionProvider
direction TextDirection 'ltr'
- Name
- Description
The reading direction of the text.
- Type
TextDirection- Default
'ltr'
useDirection
Use this function to read the current text direction. This is useful for wrapping portaled components that may be rendered outside your application root and are unaffected by the dir attribute set within.
Call it while the component initializes. It returns an object instead of a string, so that the direction property stays current when the provider's direction changes. Read the property in the template, in $derived, or in an event handler.
useDirection return value:
Outside a provider, direction is 'ltr'.