Split button
A main action joined to a menu of related actions.
Example
<focsd-split-button label="Save" variant="action"> <focsd-menu-item value="draft">Save as draft</focsd-menu-item> <focsd-menu-item value="template">Save as template</focsd-menu-item> <focsd-menu-item value="archive" disabled>Archive</focsd-menu-item></focsd-split-button>Usage
Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.
<script type="module"> import '@focsd-dev/components/focsd-split-button.js';</script>
<focsd-split-button label="Save" variant="action">…</focsd-split-button>import { SplitButton } from '@focsd-dev/react';
export function Example() { return <SplitButton label="Save" variant="action">…</SplitButton>;}<script setup>import '@focsd-dev/components/focsd-split-button.js';</script>
<template> <focsd-split-button label="Save" variant="action">…</focsd-split-button></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-split-button.js';
// template<focsd-split-button label="Save" variant="action">…</focsd-split-button><script> import '@focsd-dev/components/focsd-split-button.js';</script>
<focsd-split-button label="Save" variant="action">…</focsd-split-button>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
label | label | string | — |
open | open | boolean | false |
variant | variant | 'plain' | 'action' | 'quiet' | 'critical' | plain |
disabled | disabled | boolean | false |
Methods
| Method | Description |
|---|---|
openMenu(edge) | Open and focus the first or last item. |
closeMenu() | Close the menu. |
Slots
| Slot | Description |
|---|---|
(default) | The focsd-menu-item elements. |
trigger | The button that opens the menu. |
CSS parts
Style the inside of the component with ::part(), for example focsd-split-button::part(group).
| Part | Description |
|---|---|
group | The group around both buttons. |
main | The primary action button (a `focsd-button`). |
menu-button | The button that opens the menu. |
menu | The menu element. |
Accessibility
- Both buttons sit in a group named by
label. The main button reads the label; the menu button is named "More actions for {label}" ("More actions" when there is no label) and hasaria-haspopup="menu"andaria-expanded. - The menu is a
role=menuoffocsd-menu-itemchildren with the same keyboard asfocsd-menu. Disabled items are skipped by the arrow keys and cannot be chosen. - Escape, or choosing an item, closes the menu and returns focus to the menu button.
- The host
clickevent comes only from the main button; clicks on the menu button and in the menu stop inside the element. Choosing an item firesfocsd-select(detail.value,detail.item). disabledturns off both buttons.
Keyboard
| Key | Action |
|---|---|
| Enter / Space / Down | On the menu button: open the menu on the first item |
| Up | On the menu button: open the menu on the last item |
| Down / Up | Move between items |
| Enter / Space | Choose the focused item |
| Escape | Close the menu and return to the menu button |
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.