Skip to content

Commit

Permalink
fix #934 change listeners not fired when SuggestBox cleared from keyb…
Browse files Browse the repository at this point in the history
…oard
  • Loading branch information
vegegoku committed Jul 14, 2024
1 parent 1065c23 commit 70056a8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public AbstractSuggestBox(SuggestionsStore<T, E, O> store) {
})));

getInputElement()
.onKeyDown(
.onKeyUp(
keyEvents -> {
keyEvents
.onArrowDown(
Expand Down Expand Up @@ -224,6 +224,14 @@ public AbstractSuggestBox(SuggestionsStore<T, E, O> store) {
onBackspace();
}
}
})
.onDelete(
evt -> {
if (!isReadOnly() && !isDisabled()) {
evt.stopPropagation();
evt.preventDefault();
onBackspace();
}
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ public void onOptionSelected(O option) {
}
withOption(option);
fieldInput.appendChild(option);
selectedOptions.add(option);
option.bindTo(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down Expand Up @@ -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;
}
Expand All @@ -184,7 +182,12 @@ public void onOptionDeselected(O option) {
protected SuggestBox<V, E, O> 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);
Expand Down

0 comments on commit 70056a8

Please sign in to comment.