Skip to content

Commit

Permalink
fix #914 RadioGroup change listener not triggered when Radios are sel…
Browse files Browse the repository at this point in the history
…ected with keyboard
  • Loading branch information
vegegoku committed Apr 15, 2024
1 parent 7da1246 commit 6fb9c5f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions domino-ui/src/main/java/org/dominokit/domino/ui/forms/Radio.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ public Radio(T value, String label) {
radioElement.addEventListener("click", listener);
inputElement.addEventListener(
"change",
evt -> {
DomGlobal.console.info("CHANGEEEEEEEED.!");
if (isEnabled() && !isReadOnly()) {
setChecked(isChecked(), isChangeListenersPaused());
}
});
inputElement.addEventListener(
"checked",
evt -> {
if (isEnabled() && !isReadOnly()) {
setChecked(isChecked(), isChangeListenersPaused());
Expand Down Expand Up @@ -262,6 +270,7 @@ public Radio<T> toggleChecked() {
private Radio<T> setChecked(boolean value, boolean silent) {
boolean oldState = isChecked();
if (value == oldState) {
onChanged(silent);
return this;
}
if (nonNull(radioGroup)) {
Expand All @@ -286,6 +295,22 @@ private Radio<T> setChecked(boolean value, boolean silent) {
return this;
}

private Radio<T> onChanged(boolean silent) {
if (nonNull(radioGroup)) {
if (!(radioGroup.isReadOnly() || radioGroup.isDisabled())) {
if (!silent) {
triggerChangeListeners(!isChecked(), isChecked());
}
radioGroup.onSelectionChanged((T) radioGroup.getValue(), this, silent);
}
} else {
if (!silent) {
triggerChangeListeners(!isChecked(), isChecked());
}
}
return this;
}

/**
* Checks if the radio button is currently checked.
*
Expand Down

0 comments on commit 6fb9c5f

Please sign in to comment.