feat(polls/web) fixed issue with duplicating value to next input on keypress

This commit is contained in:
Calin Chitu 2022-04-01 16:53:52 +03:00 committed by Calinteodor
parent 84ac6298eb
commit 03286eb07e
1 changed files with 17 additions and 1 deletions

View File

@ -60,6 +60,18 @@ const PollCreate = (props: AbstractProps) => {
}, [ lastFocus ]);
const checkModifiers = useCallback(ev => {
// Composition events used to add accents to characters
// despite their absence from standard US keyboards,
// to build up logograms of many Asian languages
// from their base components or categories and so on.
if (ev.isComposing || ev.keyCode === 229) {
// keyCode 229 means that user pressed some button,
// but input method is still processing that.
// This is a standard behavior for some input methods
// like entering japanese or сhinese hieroglyphs.
return true;
}
// Because this isn't done automatically on MacOS
if (ev.key === 'Enter' && ev.metaKey) {
ev.preventDefault();
@ -90,7 +102,11 @@ const PollCreate = (props: AbstractProps) => {
}
if (ev.key === 'Enter') {
addAnswer(i + 1);
// We add a new option input
// only if we are on the last option input
if (i === answers.length - 1) {
addAnswer(i + 1);
}
requestFocus(i + 1);
ev.preventDefault();
} else if (ev.key === 'Backspace' && ev.target.value === '' && answers.length > 1) {