Skip to content

Instantly share code, notes, and snippets.

@pffigueiredo
Last active May 17, 2021 10:24
Show Gist options
  • Save pffigueiredo/8f0b5738eda8bdfb0ed190815952cbb5 to your computer and use it in GitHub Desktop.
Save pffigueiredo/8f0b5738eda8bdfb0ed190815952cbb5 to your computer and use it in GitHub Desktop.
Usage of the Left-to-Right mark to enforce LTR behaviour despite the specified direction.
import React, { useState } from "react";
const LEFT_TO_RIGHT_MARK = "‎\u200e"; // marks the input with LTR despite the specified direction
function InputLTR() {
const [cardNumber, setCardNumber] = useState("");
function onInputChange(event) {
const newCardNumber = event.target.value.replace(LEFT_TO_RIGHT_MARK, "");
setCardNumber(newCardNumber);
}
return (
<input
name="cardNumber"
type="text"
value={LEFT_TO_RIGHT_MARK + cardNumber}
onChange={onInputChange}
/>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment