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

New Shoelace release 2.1.0 #35

Merged
merged 30 commits into from
May 6, 2024
Merged

New Shoelace release 2.1.0 #35

merged 30 commits into from
May 6, 2024

Conversation

slhinyc
Copy link

@slhinyc slhinyc commented Apr 29, 2024

What's in the PR (Highlights)

  • Updated sl-switch to include new layout options (label left, label left justified), plus some minor styling updates
  • Updated sl-radio and sl-radio-group components:
    • Added form component options:label-tooltip and context-note
    • Added horizontal layout option
    • Updated how contained option is applied, so that it can be set just once from sl-radio-group and cascade to child sl-radio elements
    • Minor styling updates
  • Added new sl-checkbox-group component, based on the existing sl-radio-group component:
    • So that a group of checkboxes can have a label, help text, label tooltip, and context note, just like other form components
    • Added a horizontal layout option to the Checkbox Group
    • contained option can be applied to the Checkbox Group, to match the way this option works for the Radio Group
  • Small example updates and styling fixes to sl-dialog
  • Small example updates to sl-alert, plus change default sl-toast-stack position from top right to bottom right
  • Update checked and x-log system icons to use Font Awesome svgs

👉 Also see the Changelog page in the review app for a full list of changes for this release, which also includes changes from a previous PR that have already been merged to next but not yet tagged for release (we were holding off on cutting a new release until all the form-related components updates had been merged)


‼️ Note to reviewers:

  • Please review the new sl-checkbox-group component, including the tests and validity checks, closely. Although everything is working as expected, I'm not confident that I have done everything correctly here. I used the existing sl-radio-group as a model, but the behavior of the sl-checkbox-group is a bit different (multiple items can be checked; the group is valid if at least one checkbox in the group is checked), so I couldn't follow the sl-radio-group pattern exactly.
  • There are a lot of other changes here, but most of them are styling and doc site example updates, so I'm less worried about those.
  • There are also some new form component properties here -- the label-tooltip, context-note -- but these are following patterns already applied to other components & reviewed and approved by Daross in a previous PR that's already been merged to next

@slhinyc slhinyc requested review from kdonovan, adrianbautista and a team April 29, 2024 23:12
Copy link

vercel bot commented Apr 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
shoelace ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 6, 2024 8:05pm

@slhinyc slhinyc requested a review from davesims April 30, 2024 15:46
Copy link
Collaborator

@kdonovan kdonovan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this, @slhinyc! Giant caveat that I'm super unfamiliar with all of this, but I got it spun up locally and everything looks generally good!

One likely issue: when I submit the required checkbox group without selecting any, the submit event still fires -- and then the browser-default validation error appears (sidenote: I don't know if it's under our control, but that message is a little confusing since it's actually submit any of those boxes).

(I thought we had a test for this, but on second look I think we're only testing that submit isn't fired if we've already set setCustomValidity)

Screenshot 2024-05-01 at 4 35 32 PM Screenshot 2024-05-01 at 4 35 44 PM

Comment on lines +49 to +59
it(`should be invalid when required and no checkboxes are checked`, async () => {
const el = await fixture<SlCheckboxGroup>(html`
<sl-checkbox-group label="Select an option" required>
<sl-checkbox name="option" value="1">Option 1</sl-checkbox>
<sl-checkbox name="option" value="2">Option 2</sl-checkbox>
<sl-checkbox name="option" value="3">Option 3</sl-checkbox>
</sl-checkbox-group>
`);

expect(el.checkValidity()).to.be.false;
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this different than the check on line 12?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean. I was trying to follow the test patterns for the radio-group for these (these are the un-edited tests from the version of Shoelace we're using), and the radio-group.test.ts essentially has the same thing:

`);
const checkbox = checkboxGroup.querySelector<SlCheckbox>('#checkbox-1')!;
setTimeout(() => checkbox.click());
const event = (await oneEvent(checkboxGroup, 'sl-change')) as SlChangeEvent;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm missing where we're testing sl-input in this one

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another one where I was following the pattern in the same test for src/components/radio-group/radio-group.test.ts, but maybe it's a mistake in the Radio Group test? I just updated both to include an event listener for sl-input. Pushed a new commit!

Comment on lines +102 to +104
const anyCheckboxChecked = this.value.some(value => value.includes('true'));
const isRequiredAndEmpty = this.required && !anyCheckboxChecked;
const hasCustomValidityMessage = this.customValidityMessage !== '';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are duplicated at least once below -- would they be better as helper methods rather than locals?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another instance where I was following what's in the Radio Group component (the Shoelace default code), where some locals are repeated. Is it okay to leave, to keep things consistent across components?

Comment on lines 99 to 101
if (this.value === null || this.value === undefined) {
this.initializeValueFromCheckboxes();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just my unfamiliarity here -- do we need this still despite it being called from connectedCallback?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this because while all the tests were passing, I was getting this TypeError (see SS), and adding this if statement made it go away! I tried to adjust the tests a bunch to figure out why this is happening, but couldn't figure it out. If it's okay that I have this TypeError as long as the tests themselves are passing, then I can just delete this from the main component file, as everything is working as expected without this being repeated in the validity methods.
Screenshot 2024-05-06 at 16 05 44

@slhinyc
Copy link
Author

slhinyc commented May 6, 2024

One likely issue: when I submit the required checkbox group without selecting any, the submit event still fires -- and then the browser-default validation error appears (sidenote: I don't know if it's under our control, but that message is a little confusing since it's actually submit any of those boxes).

So this looks like an error in the example code, which I copied from the Radio Group example, but it was wrong there, too! I figured out what was missing. Following the examples on the Form Controls doc page, we needed an await Promise.all to "Wait for controls to be defined before attaching form listeners". This seems to fix the issue & the examples now all work as expected. I also fixed the issue on two Radio Group validation examples, and also added a "Set custom validity" example to the Checkbox Group, as I realized that I was missing that one.

This addresses all your comments, I believe? Let me know what you think!

@slhinyc slhinyc requested a review from kdonovan May 6, 2024 20:25
Copy link
Collaborator

@kdonovan kdonovan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkboxgroup validation is working now -- LGTM! 🚗

@slhinyc slhinyc merged commit 44ae748 into next May 6, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants