Last active
May 17, 2021 10:24
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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