-
Notifications
You must be signed in to change notification settings - Fork 0
getLTRStyles
β οΈ Version Recommendation: Always install and use the latest version ofrtl-text-tools(npm install rtl-text-tools@latest). While this specific feature was introduced in an earlier version, the latest release includes crucial bug fixes, better edge-case handling, and improved legacy browser compatibility. Avoid pinning your project to an old version just to use this function.
Returns a ready-to-use CSS style object to trigger proper LTR (Left-to-Right) rendering on any container element. This is incredibly useful when you need to isolate LTR content such as URLs, code snippets, or English text inside a larger RTL layout, ensuring that punctuation and text flow don't visually break.
getLTRStyles(): { direction: string; unicodeBidi: string }None.
-
object: An object containing the CSS properties required for LTR layout:{ direction: 'ltr', unicodeBidi: 'embed' }
Apply it directly to a React component's style prop to force LTR rendering for specific elements inside an RTL page:
import { getLTRStyles } from 'rtl-text-tools';
function TrackingNumber({ code }) {
return (
<span style={getLTRStyles()}>
{code} {/* e.g., "TRK-12345-XYZ" */}
</span>
);
}You can easily apply these styles to any DOM element using Object.assign or by setting properties individually:
import { getLTRStyles } from 'rtl-text-tools';
const urlElement = document.getElementById('website-link');
// Using Object.assign
Object.assign(urlElement.style, getLTRStyles());
// Or setting manually
const styles = getLTRStyles();
urlElement.style.direction = styles.direction;
urlElement.style.unicodeBidi = styles.unicodeBidi;- Pure Function: This function has no side effects and takes no arguments. It simply returns a static object, making it extremely fast and predictable.
-
Legacy Compatibility: The CSS properties
directionandunicode-bidihave been supported in Internet Explorer since IE6. This means the returned styles will work flawlessly across all browsers, from legacy IE to modern Chrome, Firefox, and Safari. -
Why
unicodeBidi: 'embed'? Theembedvalue creates a new embedding level, ensuring that the content inside the container is treated as strictly LTR. This isolates the element from the surrounding RTL context, preventing the browser's bidirectional algorithm from flipping punctuation or reordering the text.
-
v1.0.0: Added
getLTRStyles(alongsidegetRTLStyles) to provide ready-to-use CSS style objects for React and vanilla JS.
π Home β’ π Getting Started β’ π API Reference β’ π Report Issue
Made with β€οΈ by Homayoun Mohammadi
If you find this project useful, please consider β starring the repo to show your support!
- π Home
- π Getting Started
- π§© API Overview
- π οΈ Framework Guides
- π‘ Use Cases
- π₯οΈ Browser Compatibility
- β FAQ & Troubleshooting
Homayoun Mohammadi
π GitHub β’ βοΈ Email
β Love this project? Star it on GitHub to show your support!