const maxLength = 12
const onKeyDwn = (e: any) => {
const currentTextLength = e.target.outerText.length;
if (currentTextLength === maxLength && e.keyCode != 8) {
e.preventDefault();
}
}
<div onKeyDown={onKeyDwn} contentEditable={true} ></div>