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

feat(ui-library): radio group - use slots instead of options array #1079

Merged
merged 1 commit into from
Jul 11, 2024

Conversation

bar-tay
Copy link
Contributor

@bar-tay bar-tay commented Apr 11, 2024

closes #507

@bar-tay bar-tay requested review from faselbaum and removed request for faselbaum April 11, 2024 08:06
@bar-tay bar-tay added the 🦹 needs:reviewers (code) The issue or pull request needs additional code reviewers label Apr 11, 2024
@faselbaum faselbaum self-requested a review April 15, 2024 08:41
Copy link
Collaborator

@faselbaum faselbaum left a 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 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

@angsherpa456
Copy link
Contributor

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"

@angsherpa456 angsherpa456 force-pushed the feat/507_-use_slots_radio_group branch 3 times, most recently from fc24b5f to 5baa72f Compare June 14, 2024 08:39
@faselbaum faselbaum marked this pull request as draft June 21, 2024 08:39
@faselbaum faselbaum removed the 🦹 needs:reviewers (code) The issue or pull request needs additional code reviewers label Jun 21, 2024
@faselbaum faselbaum force-pushed the feat/507_-use_slots_radio_group branch 4 times, most recently from 9e5107e to a4718ca Compare June 28, 2024 07:13
@faselbaum faselbaum force-pushed the feat/507_-use_slots_radio_group branch 2 times, most recently from 3144455 to 46823f0 Compare June 28, 2024 08:07
@faselbaum faselbaum changed the title fix(storybook): use slots instead of options array feat(ui-library): Radio Group - use slots instead of options array Jun 28, 2024
@faselbaum faselbaum force-pushed the feat/507_-use_slots_radio_group branch 2 times, most recently from 9336271 to 15a6ab7 Compare June 28, 2024 10:07
@faselbaum faselbaum marked this pull request as ready for review June 28, 2024 11:16
@faselbaum faselbaum added the 🦹 needs:reviewers (code) The issue or pull request needs additional code reviewers label Jun 28, 2024
@faselbaum faselbaum changed the title feat(ui-library): Radio Group - use slots instead of options array feat(ui-library): radio group - use slots instead of options array Jun 28, 2024
@faselbaum faselbaum force-pushed the feat/507_-use_slots_radio_group branch 3 times, most recently from fb7ba94 to 4620641 Compare July 1, 2024 08:47
Copy link
Contributor

@thrbnhrtmnn thrbnhrtmnn left a 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.

@angsherpa456 angsherpa456 force-pushed the feat/507_-use_slots_radio_group branch 3 times, most recently from 1d580e1 to 56eed8c Compare July 10, 2024 11:26
@thrbnhrtmnn
Copy link
Contributor

Hey @angsherpa456 ,
thanks the last issue I reported was fixed with the new commits. Unfortunately I found new issues after looking deeper into the component, please let me know which of these should be separate tickets and which you still want to fix within this PR:

  • For the Radios the pressed state is implemented wrong if you you click on the radio control, it is implemented correct when you click on the label
  • For the Radios the disabled and readonly state are not displayed correctly
  • The Legend has a 2 px padding left and right, which I do not see in design
  • The dark theme is not implemented for the radios

@angsherpa456 angsherpa456 force-pushed the feat/507_-use_slots_radio_group branch from 56eed8c to 6ac4a33 Compare July 11, 2024 08:31
Copy link
Contributor

@thrbnhrtmnn thrbnhrtmnn left a 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.

@angsherpa456
Copy link
Contributor

Hi @thrbnhrtmnn here is the issue as separate task for the first in the list #1138

@angsherpa456 angsherpa456 merged commit 360d47f into develop Jul 11, 2024
4 of 5 checks passed
@angsherpa456 angsherpa456 deleted the feat/507_-use_slots_radio_group branch July 11, 2024 09:35
ashk1996 added a commit that referenced this pull request Jul 22, 2024
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🦹 needs:reviewers (code) The issue or pull request needs additional code reviewers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RadioGroup - use slots to have Radios in RadioGroup & add API to change/reset checked values of radios
4 participants