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

IgcButtonGroup: Setting the variable bound to the selected prop to false doesn't update the UI of the button group #1041

Closed
PlamenD95 opened this issue Jan 22, 2024 · 5 comments · Fixed by #1168

Comments

@PlamenD95
Copy link

PlamenD95 commented Jan 22, 2024

Consider the following sample:

webcomponents button group reset

The idea of the use case is that there would exist a "Reset button" in a given application, whose click handler sets the variable bound to the selected property of the toggle buttons in a button group to false.

However, in the UI the toggle button continues appearing as selected even though the click handler of the separate "Reset" button sets the variable to false.

Here is a small sample app with a button group, consisting of two toggle buttons and two separate buttons - one should set the selection to the second of the toggle buttons, and the other should reset the selection:
https://codesandbox.io/p/sandbox/reset-selected-sample-rsxq8k?file=%2Findex.html%3A20%2C116

It would be useful to be able to have the styling of the toggle buttons in a button group be updated to selected or de-selected, when setting the variable bound to the selected property of the toggle button.

@PlamenD95 PlamenD95 added 🆕 status: new The issue is new and will be reviewed when somebody picks it up. feature button-group labels Jan 22, 2024
@rkaraivanov
Copy link
Member

Are you referring to the selected-items attribute of the button group or to the selected property of a single toggle button?

@PlamenD95
Copy link
Author

Yes, this is concerning the selected property of the toggle button in a button group, I'll update the description of the issue to clarify this

@rkaraivanov
Copy link
Member

Can you also provide a sample reproducing the issue?

@PlamenD95
Copy link
Author

No problem, I've added a sample in sandbox.

@rkaraivanov
Copy link
Member

Looking at the sample I don't see how the selected attribute/property is reactive after the initial rendering. Clicking on the set/reset buttons invokes and updates the bound variable(s) but that won't rebind the state of the selected property. The sample is a little bit skewed since there is no actual reactive binding of state.

In the context of vanilla JS that can be achieved with:

resetButton.addEventListener("click", () =>
  document
    .querySelectorAll("#group > igc-toggle-button[selected]")
    .forEach((b) => (b.selected = false))
);

Still there may be some reasoning for this request.
One option is to add a method on the group component itself, to reset the current selection.
The other is to allow passing an empty array to selectedItems which will reset the current selection.

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

Successfully merging a pull request may close this issue.

3 participants