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

On first interaction the last Radio item in a Radio group is always selected #476

Closed
IanMatthewHuff opened this issue May 5, 2023 · 6 comments
Assignees
Labels
bug Something isn't working has workaround A bug or feature request that has a workaround. upstream issue A blocked issue that is caused by an upstream issue in FAST

Comments

@IanMatthewHuff
Copy link
Member

Describe the bug

We're currently using the <VSCodeRadioGroup> and <VSCodeRadio> controls in a VS Code Webview. When you first try to click on any of the Radio Buttons the last button in the list will always be selected. After this first click / selection it will then work correctly from now on out.

To reproduce

We are using the React Components in a webview, but I can reproduce this with the radio-group-sample CodeSandbox provided by this repo.

  1. Open this website: https://codesandbox.io/s/radio-group-sample-5c8rq2?file=/index.html
  2. Attempt to click the first or second item in one of the radio groups
  3. To repro again, just reload the browser in the codesandbox

Expected behavior

The radio control that is clicked should be selected.

Current behavior

The last radio control in the group is selected.

Screenshots

RadioIssue

Also this is non-blocking and I'm far from an HTML guru (so I might be misunderstanding).
But per the docs here: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/change_event

When a <input type="checkbox"> element is checked or unchecked (by clicking or using the keyboard);
When a <input type="radio"> element is checked (but not when unchecked);

I hooked up to the onChange of <VSCodeRadio> and currently I see it firing for the radio button that is being deselected or switched away from, and from the radio button that is being switched to. Per the docs I would have expected it only for the item that is being switched to.

@IanMatthewHuff IanMatthewHuff added the bug Something isn't working label May 5, 2023
@IanMatthewHuff
Copy link
Member Author

Also just to say this is the first extension that I've worked on since the UI toolkit has been available, and it's been a real boon so far. Great addition for helping make things more consistent.

@degrammer
Copy link

I'm having the same issue, in my case, it happens when rendering the vscode-radio-group, not just when clicking a vscode-radio, the last item is always checked.

@hawkticehurst
Copy link
Member

Hi all, it looks like this is a bug with FAST Foundation (the technology we use to build the toolkit), so I've gone ahead and bubbled the issue up to them.

I'll keep this issue open to track the bug on the toolkit side of things and adopt the FAST change/fix once it lands :)

In the meantime let me know if you have any questions and I'll do my best to answer them!

@hawkticehurst
Copy link
Member

hawkticehurst commented May 15, 2023

Actually, a quick addendum/temporary solution!

Looking at the FAST code again I think I realized what's going wrong.

I believe the issue is caused when no explicit value attribute is set on the radio elements. When this happens a current-value attribute is automatically set with the exact same value for all radio elements. This subsequently causes a boolean check in FAST Foundation code to pass for all radio elements and eventually select the last radio element because (presumably) it is the last radio element to have the check run on it.

By explicitly adding value attributes with different values, the component works.

So to be clear, this works:

<vscode-radio-group>
  <label slot="label">Radio Group Label</label>
  <vscode-radio value="hi">Radio Label</vscode-radio>
  <vscode-radio value="hello">Radio Label</vscode-radio>
  <vscode-radio value="hey">Radio Label</vscode-radio>
</vscode-radio-group>

And this does not:

<vscode-radio-group>
  <label slot="label">Radio Group Label</label>
  <vscode-radio>Radio Label</vscode-radio>
  <vscode-radio>Radio Label</vscode-radio>
  <vscode-radio>Radio Label</vscode-radio>
</vscode-radio-group>

@hawkticehurst
Copy link
Member

I'm still leaving the FAST issue open and asking them to better handle when value attributes are not explicitly set. But adding explicit value attributes should fix this problem in the meantime!

Please let me know if this works on your end and if there are any further issues you run into :)

@hawkticehurst hawkticehurst added the upstream issue A blocked issue that is caused by an upstream issue in FAST label Aug 10, 2023
hawkticehurst added a commit that referenced this issue Oct 13, 2023
Description of changes

Update radio docs (and associated CodeSandbox demos) to discuss and provide a warning about the upstream bug described in #476 and offer/demonstrate a workaround fix.
@hawkticehurst hawkticehurst added the has workaround A bug or feature request that has a workaround. label Oct 23, 2023
@hawkticehurst
Copy link
Member

Hi all,

Back with a final update: I'm very sorry to say that the toolkit is being deprecated and all active development will be coming to a close.

There was an announcement last week where you can learn more details and leave any questions or comments you may have.

Beyond that, thank you so much filing this issue and apologies for never getting around to addressing it. It means a lot that you contributed to the improvement of this project. I wish you all the best in your future VS Code extension endeavors!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working has workaround A bug or feature request that has a workaround. upstream issue A blocked issue that is caused by an upstream issue in FAST
Projects
None yet
Development

No branches or pull requests

3 participants