-
-
Notifications
You must be signed in to change notification settings - Fork 11
feat(buttons): add md-button-group component #117
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,94 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { html, LitElement, css } from 'lit' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export class ButtonGroup extends LitElement { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static styles = css` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :host { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| display: inline-flex; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| flex-direction: row; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vertical-align: middle; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* Standard group adds gap between buttons */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :host(:not([connected])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| gap: 8px; /* M3 standard button group gap */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* Target all buttons except the first one */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :host([connected]) ::slotted(*:not(:first-child)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* Make flat on the left side */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --_container-shape-start-start: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --_container-shape-end-start: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* Target variant-specific variables explicitly */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --md-button-container-shape-start-start: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --md-button-container-shape-end-start: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --md-filled-tonal-button-container-shape-start-start: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --md-filled-tonal-button-container-shape-end-start: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --md-elevated-button-container-shape-start-start: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --md-elevated-button-container-shape-end-start: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --md-outlined-button-container-shape-start-start: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --md-outlined-button-container-shape-end-start: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --md-icon-button-container-shape-start-start: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --md-icon-button-container-shape-end-start: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* Explicit border radius as fallback */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| border-start-start-radius: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| border-end-start-radius: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+19
to
+36
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The internal variables (starting with
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* Overlap borders */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| margin-inline-start: -1px; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* Target all buttons except the last one */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :host([connected]) ::slotted(*:not(:last-child)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* Make flat on the right side */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --_container-shape-start-end: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --_container-shape-end-end: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* Target variant-specific variables explicitly */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --md-button-container-shape-start-end: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --md-button-container-shape-end-end: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --md-filled-tonal-button-container-shape-start-end: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --md-filled-tonal-button-container-shape-end-end: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --md-elevated-button-container-shape-start-end: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --md-elevated-button-container-shape-end-end: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --md-outlined-button-container-shape-start-end: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --md-outlined-button-container-shape-end-end: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --md-icon-button-container-shape-start-end: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --md-icon-button-container-shape-end-end: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* Explicit border radius as fallback */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| border-start-end-radius: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| border-end-end-radius: 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* Ensure the active/hovered/focused button is on top to show full border */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :host([connected]) ::slotted(*:hover), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :host([connected]) ::slotted(*:focus-within), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :host([connected]) ::slotted(*:active) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| z-index: 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| position: relative; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+66
to
+71
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interaction states (hover, focus, active) should have a higher
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* Selected state needs to be above unselected for connected groups */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :host([connected]) ::slotted([selected]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| z-index: 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| position: relative; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static properties = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| connected: { type: Boolean, reflect: true } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| constructor() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| super() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.connected = false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+84
to
+87
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The component should have constructor() {
super()
this.connected = false
if (!this.hasAttribute('role')) {
this.setAttribute('role', 'group')
}
} |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| render() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return html`<slot></slot>` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| customElements.define('md-button-group', ButtonGroup) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
It is recommended to add a note about accessibility here, advising users to provide an
aria-labelto the<md-button-group>. Additionally, it's worth mentioning that theconnectedvariant is primarily intended for use withoutlinedbuttons to ensure borders overlap correctly as intended by the Material 3 specification.