Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions all.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
import './buttons/elevated-button.js'
import './buttons/button.js'
import './buttons/button-group.js'
import './buttons/filled-tonal-button.js'
import './buttons/outlined-button.js'
import './buttons/text-button.js'
Expand Down Expand Up @@ -48,6 +49,7 @@ import './text/text-field.js'
// LINT.IfChange(exports)
// go/keep-sorted start
export * from './buttons/button.js'
export * from './buttons/button-group.js'
export * from './checkbox/checkbox.js'
export * from './chips/chip.js'
export * from './chips/chip-set.js'
Expand Down
24 changes: 24 additions & 0 deletions buttons/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,30 @@ Changes from previous version:
</div>
```

## Button Groups

[Material 3 Button Groups](https://m3.material.io/components/button-groups/overview)

Standard Button Group:

```html
<md-button-group>
<md-button>One</md-button>
<md-button>Two</md-button>
<md-button>Three</md-button>
</md-button-group>
```

Connected Button Group:

```html
<md-button-group connected>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

It is recommended to add a note about accessibility here, advising users to provide an aria-label to the <md-button-group>. Additionally, it's worth mentioning that the connected variant is primarily intended for use with outlined buttons to ensure borders overlap correctly as intended by the Material 3 specification.

<md-button color="outlined">One</md-button>
<md-button color="outlined">Two</md-button>
<md-button color="outlined">Three</md-button>
</md-button-group>
```

## Floating Action Button - FAB

[Material 3 Floating Action Button](https://m3.material.io/components/floating-action-button/overview)]
Expand Down
94 changes: 94 additions & 0 deletions buttons/button-group.js
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)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using :first-child and :last-child selectors on slotted elements can be brittle. If a user includes non-visual elements like <style> or <script> as the first child in the light DOM, the first actual button will incorrectly match :not(:first-child) and have its left corners flattened. Consider using a more specific selector if the button tags are known, or managing these styles via JavaScript by inspecting assignedElements() to identify the first and last visible elements.

/* 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The internal variables (starting with _) and explicit border-radius properties set via ::slotted are redundant and ineffective. They are overridden by the md-button component's own shadow DOM styles (specifically its :host styles). Only the public --md-* variables are inherited and applied correctly by the slotted components.

Suggested change
--_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;
/* 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;


/* 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Interaction states (hover, focus, active) should have a higher z-index than the selected state. This ensures that the border of the interacting button is fully visible and not partially covered by an adjacent selected button's border in a connected group.

Suggested change
:host([connected]) ::slotted(*:hover),
:host([connected]) ::slotted(*:focus-within),
:host([connected]) ::slotted(*:active) {
z-index: 1;
position: relative;
}
/* 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: 2;
position: relative;
}


/* 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The component should have role="group" to be correctly identified by assistive technologies as a button group. You can set this as a default attribute in the constructor or connectedCallback.

  constructor() {
    super()
    this.connected = false
    if (!this.hasAttribute('role')) {
      this.setAttribute('role', 'group')
    }
  }


render() {
return html`<slot></slot>`
}
}

customElements.define('md-button-group', ButtonGroup)
2 changes: 2 additions & 0 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* for production.
*/
import './buttons/button.js'
import './buttons/button-group.js'
import './checkbox/checkbox.js'
import './chips/chip.js'
import './chips/chip-set.js'
Expand All @@ -27,6 +28,7 @@ import './tabs/tabs.js'
import './text/text-field.js'

export * from './buttons/button.js'
export * from './buttons/button-group.js'
export * from './checkbox/checkbox.js'
export * from './chips/chip.js'
export * from './chips/chip-set.js'
Expand Down