Open
Description
Small issue with the progress bar not filling all the way on repeated text input.
To reproduce:
- Focus the textarea demo.
- Type until the progress bar is 3/4 full.
- Stop, and note that the progress bar does fill up correctly.
- Now switch to a new line, and hold down any key. Characters will be inserted as long as the key is held down, and extra characters will be erased on keyup. However, the progress bar will not update correctly to 100% in this scenario.
On a related note, it might be prudent not to allow characters to be inserted at all if the character limit is exceeded -- binding to the 'keypress' event and disallowing any keypress except the backspace key would work. Something like:
var maxChars = 200;
var keyCodeBackspace = 8;
var keyCodeDelete = 46;
// Prevent input when textarea character limit exceeded. Allow deleting characters.
textarea.addEventListener('keypress', function(event) {
if (textarea.value.length >= maxChars
&& event.keyCode !== keyCodeBackspace
&& event.keyCode !== keyCodeDelete) {
event.preventDefault();
}
});
Metadata
Metadata
Assignees
Labels
No labels