Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set has-value attribute on radio-button click #2862

Merged
merged 4 commits into from
Oct 14, 2021

Conversation

vursen
Copy link
Contributor

@vursen vursen commented Oct 14, 2021

Description

The PR fixes the radio-group regression that occurred after the a11y refactoring that has been done in #2641:

The radio-group doesn't set the has-value attribute on child radio-button click. The attribute is only set on the next click on another radio-button.

Fixes #2857

Type of change

  • Bugfix

Checklist

  • I have read the contribution guide: https://vaadin.com/docs-beta/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

@vursen vursen requested a review from web-padawan October 14, 2021 12:55
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@web-padawan web-padawan merged commit 81543e0 into master Oct 14, 2021
@web-padawan web-padawan deleted the regression/radio-group/has-value branch October 14, 2021 13:11
@@ -357,10 +357,6 @@ class RadioGroup extends FieldMixin(FocusMixin(DisabledMixin(KeyboardMixin(DirMi
return;
}

if (this.__selectedRadioButton && this.__selectedRadioButton.value === newValue) {
Copy link
Contributor Author

@vursen vursen Oct 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check above doesn't make much sense and it is exactly what causes the regression:

1. Consideration

When the user selects a radio-button, the __valueObserver callback is invoked before the previously selected radio-button gets unchecked:

__selectRadioButton(radioButton) {
if (radioButton) {
this.value = radioButton.value;
} else {
this.value = '';
}
this.__radioButtons.forEach((button) => {
button.checked = button === radioButton;
});

...so it might happen that the __selectedRadioButton getter returns the previously selected radio-button instead of a new one that results in the has-value attribute inconsistency.

2. Consideration

However, even if the __valueObserver were invoked after the previously selected radio-button was unchecked, the check above wouldn't be correct: the has-value attribute would be set only when changing the value attribute but not when selecting a radio-button. Note, __selectedRadioButton would be always equal to the most recently selected radio-button = that has been just selected.

@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with platform 22.0.0.alpha8 and is also targeting the upcoming stable 22.0.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[radio-group] Regression: the has-value attribute is set inconsistently
3 participants