Skip to content

feat(buttons): add md-button-group component#117

Open
treeder wants to merge 1 commit into
mainfrom
feature/m3-button-groups-9380220746247726231
Open

feat(buttons): add md-button-group component#117
treeder wants to merge 1 commit into
mainfrom
feature/m3-button-groups-9380220746247726231

Conversation

@treeder
Copy link
Copy Markdown
Member

@treeder treeder commented May 17, 2026

Implements the Material 3 Button Group layout component, supporting standard and connected variants.


PR created automatically by Jules for task 9380220746247726231 started by @treeder

This patch introduces the `md-button-group` component following the Material 3 guidelines. It supports the default standard group (with an 8px gap) and the `connected` attribute to group buttons together with overlapping borders. Component exports are added to `all.js` and `common.js`, and documentation is included in `buttons/README.md`.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the md-button-group component, providing support for both standard and connected button layouts. The review feedback focuses on improving the robustness of the implementation by suggesting more reliable selectors for slotted elements, removing redundant CSS variables, and ensuring the component is accessible by adding the role="group" attribute. Additionally, there are recommendations to adjust z-index values for better visual layering during interactions and to enhance the documentation with accessibility guidelines and usage notes.

Comment thread buttons/button-group.js
}

/* 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.

Comment thread buttons/button-group.js
Comment on lines +19 to +36
--_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;
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;

Comment thread buttons/button-group.js
Comment on lines +66 to +71
:host([connected]) ::slotted(*:hover),
:host([connected]) ::slotted(*:focus-within),
:host([connected]) ::slotted(*:active) {
z-index: 1;
position: relative;
}
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;
}

Comment thread buttons/button-group.js
Comment on lines +84 to +87
constructor() {
super()
this.connected = false
}
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')
    }
  }

Comment thread buttons/README.md
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.

@treeder treeder marked this pull request as ready for review May 17, 2026 03:44
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.

1 participant