From 70056a87d4af5f84d893a264e018b8472eaf5b43 Mon Sep 17 00:00:00 2001 From: "Ahmad K. Bawaneh" Date: Mon, 15 Jul 2024 00:58:59 +0300 Subject: [PATCH] fix #934 change listeners not fired when SuggestBox cleared from keyboard --- .../domino/ui/forms/suggest/AbstractSuggestBox.java | 10 +++++++++- .../domino/ui/forms/suggest/MultiSuggestBox.java | 1 - .../domino/ui/forms/suggest/SuggestBox.java | 13 ++++++++----- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/AbstractSuggestBox.java b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/AbstractSuggestBox.java index 70dfa0797..5808c46c7 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/AbstractSuggestBox.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/AbstractSuggestBox.java @@ -176,7 +176,7 @@ public AbstractSuggestBox(SuggestionsStore store) { }))); getInputElement() - .onKeyDown( + .onKeyUp( keyEvents -> { keyEvents .onArrowDown( @@ -224,6 +224,14 @@ public AbstractSuggestBox(SuggestionsStore store) { onBackspace(); } } + }) + .onDelete( + evt -> { + if (!isReadOnly() && !isDisabled()) { + evt.stopPropagation(); + evt.preventDefault(); + onBackspace(); + } }); }); } diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/MultiSuggestBox.java b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/MultiSuggestBox.java index cb079cb5f..0b1ef30b9 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/MultiSuggestBox.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/MultiSuggestBox.java @@ -116,7 +116,6 @@ public void onOptionSelected(O option) { } withOption(option); fieldInput.appendChild(option); - selectedOptions.add(option); option.bindTo(this); } diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/SuggestBox.java b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/SuggestBox.java index 658632ba0..626621ea2 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/SuggestBox.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/SuggestBox.java @@ -101,10 +101,7 @@ public V getValue() { /** Handles the "Backspace" key event. */ @Override protected void onBackspace() { - if (nonNull(selectedOption)) { - selectedOption.remove(); - selectedOption = null; - } + clearValue(isChangeListenersPaused()); } /** @@ -164,6 +161,7 @@ private void updateTextValue() { @Override public void onOptionDeselected(O option) { option.remove(); + V oldValue = this.selectedOption.getValue(); if (Objects.equals(this.selectedOption, option)) { this.selectedOption = null; } @@ -184,7 +182,12 @@ public void onOptionDeselected(O option) { protected SuggestBox clearValue(boolean silent) { if (nonNull(selectedOption)) { V oldValue = getValue(); - withPauseChangeListenersToggle(true, field -> onOptionDeselected(selectedOption)); + withPauseChangeListenersToggle( + true, + field -> { + onOptionDeselected(selectedOption); + getInputElement().element().value = null; + }); if (!silent) { triggerClearListeners(oldValue);