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

Add new d2l-button-toggle component. #5048

Merged
merged 9 commits into from
Oct 8, 2024
Merged

Add new d2l-button-toggle component. #5048

merged 9 commits into from
Oct 8, 2024

Conversation

dbatiste
Copy link
Contributor

@dbatiste dbatiste commented Oct 4, 2024

GAUD-6936

This PR adds a new d2l-button-toggle component. It provides two slots (pressed and not-pressed) allowing the consumer to place either d2l-button-icon or d2l-button-subtle within.

The slot approach was taken (rather than baking the buttons into this component) in order to allow consumers the ability to use different types of buttons (which themselves have different APIs).

Still need docs.

Copy link
Contributor

github-actions bot commented Oct 4, 2024

Thanks for the PR! 🎉

We've deployed an automatic preview for this PR - you can see your changes here:

URL https://live.d2l.dev/prs/BrightspaceUI/core/pr-5048/

Note

The build needs to finish before your changes are deployed.
Changes to the PR will automatically update the instance.

dbatiste and others added 2 commits October 7, 2024 09:26
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
}

async _handleClick(pressed) {
this.pressed = pressed;
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't the underlying <button>s get aria-pressed="true"

Copy link
Contributor Author

@dbatiste dbatiste Oct 7, 2024

Choose a reason for hiding this comment

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

Not necessarily. Jeff and I did a bunch of investigation into that. Using aria-pressed is one approach but the guidelines (specifically the Mozilla description for aria-pressed) suggest that it's not required if the state is communicated via the label. Jeff preferred not using it due the confusion around the label and the state.

Copy link
Member

Choose a reason for hiding this comment

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

Interesting, cool. Probably worth calling that out as a "strong recommendation" or requirement in the docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah agreed. I have a side conv with Jeff to craft something for this, since we'll want to provide some guidance around how they should set their labels.

}

async _handleClick(pressed) {
this.pressed = pressed;
Copy link
Member

Choose a reason for hiding this comment

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

Interesting, cool. Probably worth calling that out as a "strong recommendation" or requirement in the docs.

elem.focus();
}

async _handleClick(pressed) {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a use case for firing an event when the state changes? I'm worried that if we don't, consumers might wire up to the individual subtle/icon buttons and need to do some extra work to determine the state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I was just mulling that over. I think you're right, and we should probably expose a specific event to avoid any confusion with them wiring up different handlers to each button.

@@ -39,6 +39,7 @@ <h2 class="d2l-heading-3">Components</h2>
<li><a href="components/button/demo/button-add.html">d2l-button-add</a></li>
<li><a href="components/button/demo/button-icon.html">d2l-button-icon</a></li>
<li><a href="components/button/demo/button-subtle.html">d2l-button-subtle</a></li>
<li><a href="components/button/demo/button-toggle.html">d2l-button-toggle</a></li>
Copy link
Member

Choose a reason for hiding this comment

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

There's also the root README where we list out all the things (although I think we should ditch that at some point).

if (changedProperties.get('pressed') === undefined) return;

/** Dispatched when the pressed state changes */
this.dispatchEvent(new CustomEvent('d2l-button-toggle-change'));
Copy link
Member

Choose a reason for hiding this comment

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

For change events, we have just used 'change' as the event name for our form inputs since I think we consider it a more built-in type of event. Could use that here -- I'm good either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that could certainly work in this case as well. I'll mull it over while I wait for Jeff's input on the docs. Or if anyone else has a preference I am happy to oblige. I know we have a mix across our components, and in some of those cases there may be reasons to be specific.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did a little poking around and it seems like the change event was originally intended for form elements INPUT, SELECT, and TEXTAREA. Unless there is any strong opinion, I'll leave this as d2l-button-toggle-change (or just d2l-button-toggle).

@dbatiste dbatiste marked this pull request as ready for review October 8, 2024 13:28
@dbatiste dbatiste requested a review from a team as a code owner October 8, 2024 13:28
@dbatiste dbatiste merged commit ddef2b8 into main Oct 8, 2024
6 checks passed
@dbatiste dbatiste deleted the dbatiste/button-toggle branch October 8, 2024 13:35
Copy link

🎉 This PR is included in version 3.50.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

2 participants