allow ten characters, also count glyphs not chars

This commit is contained in:
sawka 2024-07-30 22:22:21 -07:00
parent 827263d2d5
commit f7531b895f

View File

@ -79,7 +79,8 @@ const Tab = React.memo(
}
return;
}
// this counts glyphs, not characters
const curLen = Array.from(editableRef.current.innerText).length;
if (event.key === "Enter") {
event.preventDefault();
if (editableRef.current.innerText.trim() === "") {
@ -89,10 +90,7 @@ const Tab = React.memo(
} else if (event.key === "Escape") {
editableRef.current.innerText = originalName;
editableRef.current.blur();
} else if (
editableRef.current.innerText.length >= 8 &&
!["Backspace", "Delete", "ArrowLeft", "ArrowRight"].includes(event.key)
) {
} else if (curLen >= 10 && !["Backspace", "Delete", "ArrowLeft", "ArrowRight"].includes(event.key)) {
event.preventDefault();
}
};