-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat(ui-library): radio group - use slots instead of options array #1079
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @bar-tay 👋
I looked into the ACs as well as the changes and i found that we're not really using slots the way they are intended here.
We are still not using the blr-radio
component inside the radio group but instead render custom input elements. We want to get rid of the custom radio rendering inside blr-radio-group
.
There are two main problems that arise from this that we should IMO tackle here:
Problem 1 - How to render blr-radio
components?
I see two ways we can handle this. Both of which require some research and experimentation but in both cases we should expect users of blr-radio-group
to pass blr-radio
elements as children. This needs to be documented.
A) Create near perfect clones of the slotted elements
This would require cloning and observing any changes to the source elements via MutationObservers and probably modify source elements, defining trackable get/set accessors for all properties (if that's even possible) to proxy any changes to our clones.
- Pro: We don't manipulate element instances or values provided by consumers which is considered bad practice (in most cases)
- Con: Hard to implement if even possible. Even harder to implement cleanly.
B) Use the slotted elements directly
We could just display the slotted elements.
- Pro: Easy to implement
- Con: Working with shared instances can lead to all sorts of synchronisation issues when manipulating and reading variables from multiple actors. This Needs extra attention on state management and signalling to ensure that our controlling component (
blr-radio-group
) doesn't interfere with consumer code in unexpected ways.
Problem 2 - Loss of native input type="radio"
behavior
The input type="radio"
elements inside our blr-radio
component will lose some of their internal behaviour as they are isolated from one another due to shadow-dom encapsulation.
One of those behaviours we lose, but which is needed for a radio group
, is changing the state of other radio's of the same group to "off" (defined by the name=""
attribute) when the checked state changes to "on".
In short: Click one radio in the group. Other radios will automatically turn off.
We need to re-implement this behaviour with JS inside of blr-radio-group
.
For this to work we need to ensure that blr-radio
correctly updates the value of the checked
property when the user clicks on the element. This is currently not the case.
Further considerations (Not necessarily part of this PR)
- When considering Problem 1 - Solution B: How do we know when a JS program changes the
checked
state of one of theblr-radio
elements? We don't fire any events in this case. In this case ourblr-radio-group
would get out of sync and possibly have two or more radios selected simultaneously
Hi @bar-tay JFYI when you are working further on this. The second commit 6a5c68a. achieves the desired behaviour based on the click event (The wrapper of the slot in radio-group component listens to the event bubbled by the slotted element[radio-button]). However, the following part still needs to be solved. "When considering Problem 1 - Solution B: How do we know when a JS program changes the checked state of one of the blr-radio elements? We don't fire any events in this case. In this case our blr-radio-group would get out of sync and possibly have two or more radios selected simultaneously" |
6a5c68a
to
0a6b4c1
Compare
5022c25
to
7f6d00d
Compare
7f6d00d
to
7e0b74b
Compare
fc24b5f
to
5baa72f
Compare
9e5107e
to
a4718ca
Compare
3144455
to
46823f0
Compare
9336271
to
15a6ab7
Compare
fb7ba94
to
4620641
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have found one small thing in Storybook which seems not to appear on current develop.
When hasHint = true and I also switch hasError to true, it seems like the margin between radios and caption group increases. Further inspections make me think, that the reason is that the radio slots increase in height when hasError = true.
1d580e1
to
56eed8c
Compare
Hey @angsherpa456 ,
|
56eed8c
to
6ac4a33
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @angsherpa456 , I checked the component and all points except the one we discussed will be a separate task (first in the list) have been solved.
Hi @thrbnhrtmnn here is the issue as separate task for the first in the list #1138 |
…1106) * fix(ui-library): accessibility issue for background color fixed for text area fix(ui-library): removed extra class and refactored css for text area * fix(ui-library): added missing semicolon * fix(ui-library): fixed eslint errors * fix(ui-library): remove slot from select component (#1131) * fix(storybook): increase clickable area (#1130) * feat(ui-library): radio group - use slots instead of options array (#1079) * fix(ui-library): radio group size fix (#1139) (#1140) * fix(ui-library): fixed css error state * fix(ui-library): updated package * fix(ui-library): updated package --------- Co-authored-by: Ang Dawa Sherpa <[email protected]> Co-authored-by: Barkley <[email protected]>
closes #507