SplitButton
BasicActions
<co-split-button>SplitButton pairs a main action with a menu of related ones, such as Submit Claim with Submit and Print.
import { SplitButton } from 'health-components';
Examples
Showcase
Secondary
Small
Disabled
Usage
<SplitButton label="Submit Claim" onClick={submit}
items={[{ label: "Submit and Print CMS-1500", onSelect: submitPrint }, { label: "Save as Draft", onSelect: saveDraft }]} />
When to use
- One action is clearly the default and two to five variations exist: Submit Claim, Submit and Print, Save as Draft.
When not to use
- The options are equally likely: use separate buttons.
- The menu holds unrelated actions: use a KebabMenu.
Variants and states
| Variant | What it is |
|---|---|
| primary | Main action filled. |
| secondary | Outlined, for less important groups such as Export. |
| open | Menu shown; closes on Escape or outside click. |
Accessibility
- The arrow is its own button with aria-haspopup="menu" and aria-expanded.
- Escape closes the menu.
Do and don't
- Do: "Submit Claim" with "Submit and Print CMS-1500" and "Save as Draft" in the menu.
- Don't: Hiding "Void Claim" in a split menu under "Submit Claim".
Props
| Prop | Type | Default | Description |
|---|---|---|---|
label * | string | — | Main action label ("Submit Claim"); required |
onClick | (event: MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => void | none | Runs the main action |
items * | MenuItem[] | — | Related actions in the menu: Array<{label, hint?, icon?, danger?, disabled?, onSelect?}>; required |
variant | 'primary' | 'secondary' | 'primary' | 'primary' | 'secondary' |
size | 'sm' | 'md' | 'md' | 'sm' | 'md' |
menuLabel | string | "More options" | aria-label of the arrow button |
defaultOpen | boolean | false | Open on first render (uncontrolled) |
open | boolean | undefined (uncontrolled) | Controlled open state of the menu |
onOpenChange | (open: boolean) => void | — | Called when the menu opens or closes |
onItemSelect | (item: MenuActionItem, index: number) => void | none | Called with the chosen item and its index, after the item's own onSelect (one handler for every item) |
disabled | boolean | false | Disables both halves |
align | MenuAlign | 'right' | 'right' | 'left': menu alignment |
className | string | — | Class on the wrapper |
Every component also accepts className.
Angular, Vue and HTML
Register the elements once (Angular guide), then use <co-split-button>. Attributes take strings; arrays and objects are set as properties (Angular [prop], Vue :prop) or as JSON attributes. Callbacks are DOM events with the value in event.detail.
Angular template
<co-split-button label="…" variant="…" [items]="items" (co-click)="onClick($event.detail)"></co-split-button>
| Kind | Name | Description |
|---|---|---|
| attribute | label | Main action label ("Submit Claim"); required |
| property / JSON attribute | items | Related actions in the menu: Array<{label, hint?, icon?, danger?, disabled?, onSelect?}>; required |
| attribute | variant | 'primary' | 'secondary'; default 'primary' |
| attribute | size | 'sm' | 'md'; default 'md' |
| attribute | menu-label / menuLabel | aria-label of the arrow button; default "More options" |
| attribute | default-open / defaultOpen | Open on first render (uncontrolled); default false |
| attribute | open | Controlled open state of the menu; default undefined (uncontrolled) |
| attribute | disabled | Disables both halves; default false |
| attribute | align | 'right' | 'left': menu alignment; default 'right' |
| attribute | class-name / className | Class on the wrapper |
| event | co-click | Runs the main action; default none (React: onClick) |
| event | co-open-change | Called when the menu opens or closes (React: onOpenChange) |
| event | co-item-select | Called with the chosen item and its index, after the item's own onSelect (one handler for every item); default none (React: onItemSelect) |