IBM Carbon JS behaviour

Combo Button

Primary action always visible while the arrow body unfolds the alternates beneath it — Carbon’s space-saving split button with a flat, squared dropdown.

Documentation

Real scenarios

The component as it is used in a product — not a specimen grid.

One button, five actions

Deploy is always one click away on the labelled half; the arrow unfolds the alternates beneath. Escape, an outside tap or picking an item folds it back.

Near the bottom edge the menu opens upward — direction flips, the flat frame stays.

Secondary combo — same anatomy, gray kind.

The whole family

Primary, secondary, tertiary and danger — both halves always share one colour and one hover.

primary
secondary
tertiary
danger

Important props

Important props
Prop Type Default What it does
kind string 'primary' primary, secondary, tertiary or danger; both halves share one colour and one hover.
direction string 'bottom' Which way the menu opens; top when the button sits near the bottom edge.
primary-action click required The labelled half always runs the primary action; the menu only lists alternates.

Snippet

<div class="cbcb" data-open="false">
<button class="cbcb-main">Deploy</button>
<button class="cbcb-arrow" aria-expanded="false" aria-label="More actions">⌄</button>
<ul class="cbcb-menu" role="menu">
<li role="menuitem">Deploy to staging</li>
<li role="menuitem">Run migrations</li>
</ul>
</div>

<style>
.cbcb { position: relative; display: inline-flex; font: 400 .875rem/1 'IBM Plex Sans', sans-serif; }
.cbcb-main, .cbcb-arrow { block-size: 3rem; border: none; background: #0f62fe; color: #fff; cursor: pointer; }
.cbcb-main { padding-inline: 1rem; }
.cbcb-arrow { inline-size: 3rem; border-inline-start: 1px solid #ffffff40; }
.cbcb-menu { position: absolute; inset-block-start: 100%; inset-inline: 0; margin: 0; padding: 0;
list-style: none; background: #f4f4f4; box-shadow: 0 2px 6px rgba(0,0,0,.2); }
.cbcb[data-open='false'] .cbcb-menu { display: none; }
.cbcb-menu li { padding: .65rem 1rem; border-block-end: 1px solid #e0e0e0; }
</style>
// app/Pages/DeployToolbar.jsx — Inertia page; renders the React snippet
// below unchanged, with Inertia's Link wired into the provider.
import { Link } from '@inertiajs/react';
import { NabuXUIProvider } from '@nabuxai/ui-react';
import DeployCombo from '@/components/DeployCombo';

export default function DeployToolbar() {
  return (
    <NabuXUIProvider locale="en" linkComponent={Link}>
      <main className="nx-page">
        <DeployCombo />
      </main>
    </NabuXUIProvider>
  );
}
// DeployCombo.jsx — Carbon combo button: the primary is always one click away
import { useEffect, useRef, useState } from 'react';
import '@nabuxai/ui-core/css';

const ACTIONS = [
  { id: 'staging', label: 'Deploy to staging', msg: 'Build 842 staged on staging' },
  { id: 'migrate', label: 'Run migrations', msg: 'Migrations ran in 1.8s' },
  { id: 'cache', label: 'Clear cache', msg: 'Application cache cleared' },
];

export default function DeployCombo() {
  const [open, setOpen] = useState(false);
  const [log, setLog] = useState(null);
  const rootRef = useRef(null);

  // Escape and an outside tap fold the menu back — Carbon's dismiss contract.
  useEffect(() => {
    const onKey = (e) => e.key === 'Escape' && setOpen(false);
    const onTap = (e) => { if (!rootRef.current?.contains(e.target)) setOpen(false); };
    window.addEventListener('keydown', onKey);
    window.addEventListener('pointerdown', onTap);
    return () => {
      window.removeEventListener('keydown', onKey);
      window.removeEventListener('pointerdown', onTap);
    };
  }, []);

  const run = (msg) => { setLog(msg); setOpen(false); };

  return (
    <>
      <style>{`
        .cbcb { position: relative; display: inline-flex; font: 400 .875rem/1 'IBM Plex Sans', sans-serif; }
        .cbcb-main, .cbcb-arrow { block-size: 3rem; border: none; background: #0f62fe; color: #fff; cursor: pointer; }
        .cbcb-main { padding-inline: 1rem; }
        .cbcb-main:hover, .cbcb-arrow:hover { background: #0353e9; }
        .cbcb-arrow { display: grid; place-items: center; inline-size: 3rem; border-inline-start: 1px solid #ffffff40; }
        .cbcb-menu { position: absolute; inset-block-start: calc(100% + 2px); inset-inline: 0; z-index: 5; margin: 0; padding: 0;
                     list-style: none; background: #f4f4f4; box-shadow: 0 2px 6px rgba(0, 0, 0, .2); }
        .cbcb[data-open='false'] .cbcb-menu { display: none; }
        .cbcb-menu button { inline-size: 100%; padding: .65rem 1rem; border: none; border-block-end: 1px solid #e0e0e0;
                            background: transparent; text-align: start; cursor: pointer;
                            font: 400 .875rem/1.3 'IBM Plex Sans', sans-serif; }
        .cbcb-menu button:hover { background: #e8e8e8; }
        .cbcb-log { max-inline-size: 24rem; margin-block-start: .75rem; padding: .5rem 1rem; background: #f4f4f4;
                    border-block-start: 2px solid #0f62fe; font-size: .875rem; }
      `}</style>
      <div className="cbcb" data-open={open} ref={rootRef}>
        <button type="button" className="cbcb-main" onClick={() => run('Build 842 deployed to production')}>
          Deploy
        </button>
        <button type="button" className="cbcb-arrow" aria-expanded={open} aria-haspopup="menu"
          aria-label="More deploy actions" onClick={() => setOpen(!open)}>⌄</button>
        <ul className="cbcb-menu" role="menu" aria-label="Alternate deploy actions">
          {ACTIONS.map((a) => (
            <li role="none" key={a.id}>
              <button type="button" role="menuitem" onClick={() => run(a.msg)}>{a.label}</button>
            </li>
          ))}
        </ul>
      </div>
      <p className="cbcb-log" role="status">{log ?? 'Pick an action — the log lands here.'}</p>
    </>
  );
}
<!-- DeployCombo.vue — Carbon combo button: the primary is always one click away -->
<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref } from 'vue';
import '@nabuxai/ui-core/css';

const actions = [
  { id: 'staging', label: 'Deploy to staging', msg: 'Build 842 staged on staging' },
  { id: 'migrate', label: 'Run migrations', msg: 'Migrations ran in 1.8s' },
  { id: 'cache', label: 'Clear cache', msg: 'Application cache cleared' },
];
const open = ref(false);
const log = ref<string | null>(null);
const root = ref<HTMLElement | null>(null);

const run = (msg: string) => { log.value = msg; open.value = false; };
const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') open.value = false; };
const onTap = (e: PointerEvent) => { if (!root.value?.contains(e.target as Node)) open.value = false; };

onMounted(() => {
  window.addEventListener('keydown', onKey);
  window.addEventListener('pointerdown', onTap);
});
onBeforeUnmount(() => {
  window.removeEventListener('keydown', onKey);
  window.removeEventListener('pointerdown', onTap);
});
</script>

<template>
  <div ref="root" class="cbcb" :data-open="open">
    <button type="button" class="cbcb-main" @click="run('Build 842 deployed to production')">Deploy</button>
    <button type="button" class="cbcb-arrow" :aria-expanded="open" aria-haspopup="menu"
      aria-label="More deploy actions" @click="open = !open">⌄</button>
    <ul class="cbcb-menu" role="menu" aria-label="Alternate deploy actions">
      <li v-for="a in actions" :key="a.id" role="none">
        <button type="button" role="menuitem" @click="run(a.msg)">{{ a.label }}</button>
      </li>
    </ul>
  </div>
  <p class="cbcb-log" role="status">{{ log ?? 'Pick an action — the log lands here.' }}</p>
</template>

<style scoped>
.cbcb { position: relative; display: inline-flex; font: 400 .875rem/1 'IBM Plex Sans', sans-serif; }
.cbcb-main, .cbcb-arrow { block-size: 3rem; border: none; background: #0f62fe; color: #fff; cursor: pointer; }
.cbcb-main { padding-inline: 1rem; }
.cbcb-main:hover, .cbcb-arrow:hover { background: #0353e9; }
.cbcb-arrow { display: grid; place-items: center; inline-size: 3rem; border-inline-start: 1px solid #ffffff40; }
.cbcb-menu { position: absolute; inset-block-start: calc(100% + 2px); inset-inline: 0; z-index: 5; margin: 0; padding: 0;
             list-style: none; background: #f4f4f4; box-shadow: 0 2px 6px rgba(0, 0, 0, .2); }
.cbcb[data-open='false'] .cbcb-menu { display: none; }
.cbcb-menu button { inline-size: 100%; padding: .65rem 1rem; border: none; border-block-end: 1px solid #e0e0e0;
                    background: transparent; text-align: start; cursor: pointer;
                    font: 400 .875rem/1.3 'IBM Plex Sans', sans-serif; }
.cbcb-menu button:hover { background: #e8e8e8; }
.cbcb-log { max-inline-size: 24rem; margin-block-start: .75rem; padding: .5rem 1rem; background: #f4f4f4;
            border-block-start: 2px solid #0f62fe; font-size: .875rem; }
</style>
<!-- DeployCombo.svelte — Carbon combo button: the primary is always one click away -->
<script lang="ts">
  import { onMount } from 'svelte';
  import '@nabuxai/ui-core/css';

  const actions = [
    { id: 'staging', label: 'Deploy to staging', msg: 'Build 842 staged on staging' },
    { id: 'migrate', label: 'Run migrations', msg: 'Migrations ran in 1.8s' },
    { id: 'cache', label: 'Clear cache', msg: 'Application cache cleared' },
  ];
  let open = $state(false);
  let log = $state<string | null>(null);
  let root: HTMLElement;

  const run = (msg: string) => { log = msg; open = false; };

  onMount(() => {
    const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') open = false; };
    const onTap = (e: PointerEvent) => { if (!root.contains(e.target as Node)) open = false; };
    window.addEventListener('keydown', onKey);
    window.addEventListener('pointerdown', onTap);
    return () => {
      window.removeEventListener('keydown', onKey);
      window.removeEventListener('pointerdown', onTap);
    };
  });
</script>

<div bind:this={root} class="cbcb" data-open={open}>
  <button type="button" class="cbcb-main" onclick={() => run('Build 842 deployed to production')}>Deploy</button>
  <button type="button" class="cbcb-arrow" aria-expanded={open} aria-haspopup="menu"
    aria-label="More deploy actions" onclick={() => (open = !open)}>⌄</button>
  <ul class="cbcb-menu" role="menu" aria-label="Alternate deploy actions">
    {#each actions as a (a.id)}
      <li role="none">
        <button type="button" role="menuitem" onclick={() => run(a.msg)}>{a.label}</button>
      </li>
    {/each}
  </ul>
</div>
<p class="cbcb-log" role="status">{log ?? 'Pick an action — the log lands here.'}</p>

<style>
.cbcb { position: relative; display: inline-flex; font: 400 .875rem/1 'IBM Plex Sans', sans-serif; }
.cbcb-main, .cbcb-arrow { block-size: 3rem; border: none; background: #0f62fe; color: #fff; cursor: pointer; }
.cbcb-main { padding-inline: 1rem; }
.cbcb-main:hover, .cbcb-arrow:hover { background: #0353e9; }
.cbcb-arrow { display: grid; place-items: center; inline-size: 3rem; border-inline-start: 1px solid #ffffff40; }
.cbcb-menu { position: absolute; inset-block-start: calc(100% + 2px); inset-inline: 0; z-index: 5; margin: 0; padding: 0;
             list-style: none; background: #f4f4f4; box-shadow: 0 2px 6px rgba(0, 0, 0, .2); }
.cbcb[data-open='false'] .cbcb-menu { display: none; }
.cbcb-menu button { inline-size: 100%; padding: .65rem 1rem; border: none; border-block-end: 1px solid #e0e0e0;
                    background: transparent; text-align: start; cursor: pointer;
                    font: 400 .875rem/1.3 'IBM Plex Sans', sans-serif; }
.cbcb-menu button:hover { background: #e8e8e8; }
.cbcb-log { max-inline-size: 24rem; margin-block-start: .75rem; padding: .5rem 1rem; background: #f4f4f4;
            border-block-start: 2px solid #0f62fe; font-size: .875rem; }
</style>