Split Button
Split Buttons offer a primary action alongside a suffix trigger for secondary, related actions.
Overview
The catnip-split-button component renders a dual-part button element: a main button that emits the primary click event, and a suffix button that emits suffix-click and open-change. Consumers render and control the related action surface, such as a menu, list, or popover, and pass the controlled open state back to the split button for selected suffix styling and aria-expanded.
The default purpose="main" preserves the original pill-shaped split button, including sizes s, m, and l and appearances primary, secondary, and ghost. Use purpose="utility" for compact, 4px-corner controls; it adds size xs, appearance tertiary, and secondary + danger. Utility split buttons support primary, secondary, and tertiary; main split buttons continue to support primary, secondary, and ghost.
The suffix icon follows open by default: chevron-down when inactive and chevron-up when active. Use suffixInactiveIcon and suffixActiveIcon slots to provide custom Catnip icons, SVGs, or application-owned icon elements. If only one suffix icon slot is provided, that icon is used in both states.
Loading state: An optional loading state (aria-busy + native disabled on both halves) is supported, which visually replaces the main button's content with a spinner and disables both halves of the button.
Live example
Guidelines
Loading and disabled (interim)
Similar to the CatnipButton, re-using the standard disabled state while loading is temporary. UX is expected to decide on dedicated loading visuals. Both halves of the CatnipSplitButton are disabled when loading is set to true.
Usage
Use the Split Button when you have a primary action that is most commonly executed by the user, but you also need to provide a few less common, but related, secondary actions.
- Do keep the default
purpose="main"for a prominent, pill-shaped action. - Do use
purpose="utility"for compact toolbar and local-control actions. Utility supportsxs,tertiary, andsecondary+danger. - Do use a concise label for the main action.
- Do handle
suffix-clickin the consumer and render the related action surface next to the split button. - Do keep
open,aria-controls, andaria-haspopupsynchronized with the surface you render. - Do use
suffixInactiveIconandsuffixActiveIconwhen the suffix trigger needs custom iconography. If you provide only one, it is used for both states. - Do wire keyboard support when using
catnip-listas the related action surface (see below). - Do close the related action surface when a row is selected or when the user clicks outside the split-button/menu region.
- Do not use a Split Button if the actions are unrelated.
- Do not put a huge number of items in the related action surface. If there are many actions, consider if a different UI pattern is more appropriate.
Consumer-rendered related actions
Compose catnip-split-button with catnip-list and catnip-list-item for a "more options" menu. Split Button has no options prop — it only renders the two buttons. The consumer owns the menu rows, open state, list positioning, pointer-outside dismissal, and keyboard navigation.
The live playground on the Split Button overview page includes a copyable snippet with full menu keyboard support. The keys are listed in Accessibility — Consumer-rendered menu.
<template>
<div ref="menuRoot" class="save-split-menu">
<catnip-split-button
ref="splitBtn"
appearance="primary"
.open="isOpen"
aria-haspopup="menu"
:aria-controls="isOpen ? listId : undefined"
@click="onSave"
@suffix-click="onSuffixClick"
>
Save
</catnip-split-button>
<catnip-list v-if="isOpen" :id="listId" class="save-split-menu__panel" list-role="menu" size="m" list-aria-label="More save options">
<catnip-list-item .active="activeIndex === 0" @click="onSelect('draft')"> Save as draft </catnip-list-item>
<catnip-list-item .active="activeIndex === 1" @click="onSelect('template')"> Save as template </catnip-list-item>
<catnip-list-item .active="activeIndex === 2" intent="danger" @click="onSelect('discard')"> Discard draft </catnip-list-item>
</catnip-list>
</div>
</template>
<script setup>
import { ref } from "vue";
const listId = "save-split-menu";
const menuRoot = ref(null);
const splitBtn = ref(null);
const isOpen = ref(false);
const activeIndex = ref(-1);
const menuItems = [
{ value: "draft", label: "Save as draft" },
{ value: "template", label: "Save as template" },
{ value: "discard", label: "Discard draft", intent: "danger" }
];
function enabledIndices() {
return menuItems.map((item, i) => (item.disabled ? -1 : i)).filter((i) => i >= 0);
}
function focusSuffix() {
splitBtn.value?.shadowRoot?.querySelector(".catnip-split-button__suffix")?.focus();
}
function isSplitButtonFocused() {
const host = splitBtn.value;
if (!host) return false;
const active = document.activeElement;
return active === host || Boolean(host.shadowRoot?.contains(active));
}
function openMenu() {
isOpen.value = true;
const enabled = enabledIndices();
activeIndex.value = enabled.length ? enabled[0] : -1;
}
function closeMenu() {
isOpen.value = false;
activeIndex.value = -1;
focusSuffix();
}
function onSave() {
/* primary action */
}
function onSuffixClick() {
isOpen.value ? closeMenu() : openMenu();
}
function onSelect() {
closeMenu();
}
// Attach a window keydown handler for arrows, Home/End, Enter/Space, Escape, and typeahead.
// Attach a document pointerdown handler to close on outside click.
// See the Split Button playground for the full implementation.
</script>
<style scoped>
.save-split-menu {
position: relative;
display: inline-block;
}
.save-split-menu__panel {
position: absolute;
top: calc(100% + 4px);
left: 0;
min-width: 100%;
z-index: 1000;
}
</style>