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
37 changes: 37 additions & 0 deletions docs/components/buttons-menus/button-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,41 @@ For selection-based button groups that represent different states or views, use
</div>
```

**Composition variants**

There are two ways to compose a selection button:

**Input wrapped inside label** — nest the input directly inside a `<label>` element, removing the need for `for`/`id`.
This variant is required for icon-only buttons to support and display **tooltips** correctly:

```html
<div class="btn-group" role="group" aria-label="Layout selection">
<label>
<input type="checkbox" class="btn-check" aria-label="One pane" siTooltip="One pane" checked />
<si-icon class="btn btn-icon icon" icon="element-layout-pane-1" />
</label>

Comment on lines +230 to +234

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am still unsure, what we should recommend to projects here.

I guess wrapping it in a label is the way nicer approach, and as written in the other PR, maybe maybe moving the btn btn-icon classes to the label

<label>
<input type="checkbox" class="btn-check" aria-label="Two panes" siTooltip="Two panes" />
<si-icon class="btn btn-icon icon" icon="element-layout-pane-2" />
</label>
Comment thread
dauriamarco marked this conversation as resolved.
</div>
```

**`for` / `id` linking** — place the input before the label and connect them via matching `for` and `id` attributes.
This is the standard HTML pattern and works well for text labels:

```html
<div class="btn-group" role="group" aria-label="View selection">
<input type="radio" class="btn-check" name="view" id="view-day" checked />
<label class="btn" for="view-day">Day</label>

<input type="radio" class="btn-check" name="view" id="view-week" />
<label class="btn" for="view-week">Week</label>

<input type="radio" class="btn-check" name="view" id="view-month" />
<label class="btn" for="view-month">Month</label>
</div>
```

<si-docs-component example="buttons/selection-buttons" height="350"></si-docs-component>
44 changes: 11 additions & 33 deletions src/app/examples/buttons/selection-buttons.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@
aria-label="One pane"
checked
/>
<span class="btn btn-icon">
<si-icon class="icon" icon="element-layout-pane-1" />
</span>
<si-icon class="btn btn-icon icon" icon="element-layout-pane-1" />
</label>

<label>
Expand All @@ -53,9 +51,7 @@
siTooltip="Two panes"
aria-label="Two panes"
/>
<span class="btn btn-icon">
<si-icon class="icon" icon="element-layout-pane-2" />
</span>
<si-icon class="btn btn-icon icon" icon="element-layout-pane-2" />
</label>

<label>
Expand All @@ -66,9 +62,7 @@
siTooltip="Three panes"
aria-label="Three panes"
/>
<span class="btn btn-icon">
<si-icon class="icon" icon="element-layout-pane-3" />
</span>
<si-icon class="btn btn-icon icon" icon="element-layout-pane-3" />
</label>
</div>
</div>
Expand Down Expand Up @@ -105,37 +99,27 @@ <h4>Multi-select</h4>
<div class="btn-group mb-6" role="group" aria-label="Category filter">
<label>
<input type="checkbox" class="btn-check" siTooltip="Garden" aria-label="Garden" checked />
<span class="btn btn-icon">
<si-icon class="icon" icon="element-garden" />
</span>
<si-icon class="btn btn-icon icon" icon="element-garden" />
</label>

<label>
<input type="checkbox" class="btn-check" siTooltip="Mobile" aria-label="Mobile" />
<span class="btn btn-icon">
<si-icon class="icon" icon="element-smartphone" />
</span>
<si-icon class="btn btn-icon icon" icon="element-smartphone" />
</label>

<label>
<input type="checkbox" class="btn-check" siTooltip="Cloud" aria-label="Cloud" checked />
<span class="btn btn-icon">
<si-icon class="icon" icon="element-cloud" />
</span>
<si-icon class="btn btn-icon icon" icon="element-cloud" />
</label>

<label>
<input type="checkbox" class="btn-check" siTooltip="AI" aria-label="AI" />
<span class="btn btn-icon">
<si-icon class="icon" icon="element-ai" />
</span>
<si-icon class="btn btn-icon icon" icon="element-ai" />
</label>

<label>
<input type="checkbox" class="btn-check" siTooltip="Network" aria-label="Network" />
<span class="btn btn-icon">
<si-icon class="icon" icon="element-network" />
</span>
<si-icon class="btn btn-icon icon" icon="element-network" />
</label>
</div>

Expand Down Expand Up @@ -294,16 +278,12 @@ <h4>Sizing</h4>
siTooltip="Heating"
aria-label="Heating"
/>
<span class="btn btn-icon">
<si-icon class="icon" icon="element-sun" />
</span>
<si-icon class="btn btn-icon icon" icon="element-sun" />
</label>

<label>
<input type="radio" class="btn-check" name="btnradio8" siTooltip="Water" aria-label="Water" />
<span class="btn btn-icon">
<si-icon class="icon" icon="element-water" />
</span>
<si-icon class="btn btn-icon icon" icon="element-water" />
</label>

<label>
Expand All @@ -314,9 +294,7 @@ <h4>Sizing</h4>
siTooltip="Cooling"
aria-label="Cooling"
/>
<span class="btn btn-icon">
<si-icon class="icon" icon="element-cooling-state" />
</span>
<si-icon class="btn btn-icon icon" icon="element-cooling-state" />
</label>
</div>

Expand Down
Loading