Automatically detect direction with AutoDirectionProvider
masterUse AutoDirectionProvider for content where the direction is unknown or dynamic, such as user-generated text. It wraps a DirectionProvider and automatically sets the direction based on the provided text prop.
- Detection Logic: The direction is determined by the first strong LTR or RTL character found in the string.
- Fallback: If no strong direction is found (e.g., a string of numbers), it inherits the direction from the nearest
DirectionProviderancestor or defaults to LTR. - Language Support: Like
DirectionProvider, it also supports thelangprop.
import AutoDirectionProvider from 'react-with-direction/dist/AutoDirectionProvider';
<AutoDirectionProvider text={userGeneratedContent}>
<ExampleComponent>
{userGeneratedContent}
</ExampleComponent>
</AutoDirectionProvider>