Fix an issue with uncheckable radio buttons.#1066
Merged
Alex-Jordan merged 1 commit intoopenwebwork:developfrom Apr 26, 2024
Merged
Fix an issue with uncheckable radio buttons.#1066Alex-Jordan merged 1 commit intoopenwebwork:developfrom
Alex-Jordan merged 1 commit intoopenwebwork:developfrom
Conversation
Member
Author
|
Here is a MWE for testing: |
When clicking back and forth between radio buttons in a radio group a radio button can be unexpectedly still unchecked when it should become checked. For example, in a radio group with at least two radio buttons, click on the first radio button. It will now be checked. Now click on the second radio button, and it will now be checked. Now click on the first radio button again. This time it will remain unchecked and the second radio button will also now be unchecked. Another manifestation of this is with keyboard controls. Again with a radio group containing at least two radios. Click on the first radio button (or for a pure keyboard approach navigate to the radio group with tab, and hit the spacebar when the first radio button is focused), and it will now be checked. Now use the down arrow repeatedly. As focus cycles through the radio group buttons on each subsequent full cycle the radios will be all checked, and then all unchecked on the next cycle. The way that the uncheckable radio code works is that javascript adds a data attribute to a radio button when it is checked which indicates that the radio is checked. The problem is that when another radio in the group is checked that second radio now has the data attribute added, but the first does not have the data attribute removed. So if that first radio button is now clicked again the javascript sees the data attribute, deletes it, and undoes the effect of the click and unchecks the radio when in this case it should let the effect of the click occur. To fix the issue, radio groups need to be managed instead of single radio buttons. When the data attribute is added to a radio button, the code needs to ensure the data attribute is removed from the other radio buttons in the group that have it. Of course when a second click occurs on an already checked radio button, that works as before, and the radio is unchecked (and the data attribute removed).
1fdc25a to
0fab5bf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When clicking back and forth between radio buttons in a radio group a radio button can be unexpectedly still unchecked when it should become checked. For example, in a radio group with at least two radio buttons, click on the first radio button. It will now be checked. Now click on the second radio button, and it will now be checked. Now click on the first radio button again. This time it will remain unchecked and the second radio button will also now be unchecked.
Another manifestation of this is with keyboard controls. Again with a radio group containing at least two radios. Click on the first radio button (or for a pure keyboard approach navigate to the radio group with tab, and hit the spacebar when the first radio button is focused), and it will now be checked. Now use the down arrow repeatedly. As focus cycles through the radio group buttons on each subsequent full cycle the radios will be all checked, and then all unchecked on the next cycle.
The way that the uncheckable radio code works is that javascript adds a data attribute to a radio button when it is checked which indicates that the radio is checked. The problem is that when another radio in the group is checked that second radio now has the data attribute added, but the first does not have the data attribute removed. So if that first radio button is now clicked again the javascript sees the data attribute, deletes it, and undoes the effect of the click and unchecks the radio when in this case it should let the effect of the click occur.
To fix the issue, radio groups need to be managed instead of single radio buttons. When the data attribute is added to a radio button, the code needs to ensure the data attribute is removed from the other radio buttons in the group that have it.
Of course when a second click occurs on an already checked radio button, that works as before, and the radio is unchecked (and the data attribute removed).