From 1576da01c4399be83db9521fd0882a8ee29a0ded Mon Sep 17 00:00:00 2001 From: Baptiste Grob <60621355+baptiste-grob@users.noreply.github.com> Date: Wed, 27 Jan 2021 15:32:26 +0100 Subject: [PATCH] fix: check onKeyUp instead of onKeyDown --- .../views/challenge_modal/challenge_modal.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/views/challenge_modal/challenge_modal.tsx b/app/assets/javascripts/views/challenge_modal/challenge_modal.tsx index cc4495e74..a1f486b7c 100644 --- a/app/assets/javascripts/views/challenge_modal/challenge_modal.tsx +++ b/app/assets/javascripts/views/challenge_modal/challenge_modal.tsx @@ -40,6 +40,7 @@ class ChallengeModalCtrl extends PureViewCtrl { application!: WebApplication; challenge!: Challenge; onDismiss!: () => void; + submitting = false; /** @template */ protectionsSessionDurations = ProtectionSessionDurations; @@ -177,6 +178,10 @@ class ChallengeModalCtrl extends PureViewCtrl { if (!this.validate()) { return; } + if (this.submitting) { + return; + } + this.submitting = true; await this.setState({ processing: true }); const values: ChallengeValue[] = []; for (const inputValue of Object.values(this.getState().values)) { @@ -200,6 +205,7 @@ class ChallengeModalCtrl extends PureViewCtrl { } else { this.setState({ processing: false }); } + this.submitting = false; }, 50); } @@ -378,10 +384,9 @@ function ChallengePrompts({ ctrl.state.values[prompt.id]!.value = value; ctrl.onTextValueChange(prompt); }} - onKeyDown={(event) => { + onKeyUp={(event) => { if (event.key === 'Enter') { event.preventDefault(); - event.stopPropagation(); ctrl.submit(); } }}