OverviewInstallationMigrating to 1.0Themes and layersKanok designCustomizingIconsForms and validationFrameworksUsing with AIButtonText inputText areaNumber inputSearchSelectDropdownComboboxMulti-selectCheckboxRadio buttonToggleDate pickerTime pickerSliderFile uploaderModalSide panelTearsheetNotificationToastTooltipDefinition tooltipPopoverToggletipMenuData tableStructured listPaginationContained listTree viewTabsBreadcrumbLinkPagination navContent switcherAccordionProgress indicatorUI shellTagTileCardProduct cardCode snippetCopy buttonUser avatarTruncated textListLoadingInline loadingProgress barSkeletonBadge indicatorStatus indicatorGridHeadingLayerAction setPage headerBig numberEdit in placeIntroductionText inputText areaNumber inputSearchSelectDropdownComboboxMulti-selectCheckboxRadio buttonToggleDate pickerTime pickerSliderFile uploaderTabsPagination navContent switcherTooltipDefinition tooltipPopoverMenuAccordionProgress indicatorUI shellModalSide panelTearsheetNotificationToastData tableStructured listPaginationTree viewCode snippetCopy buttonTruncated textLoadingTagCardProduct cardEdit in place
Popover
A popover is a floating box with your own content beside a trigger: a few filters, a short form, settings for a table. It is Carbon's Popover, the box behind tooltips, toggletips and menus. You decide when it opens; auto-close lets Esc and a click outside close it.
npmshadcn · Web componentshadcn · React + TailwindManualnpminstall@purpurabog/uinpxshadcn@4add@kanok-ui/popovernpxshadcn@4add@kanok-ui/tw-popover# Web component# 1. Install the dependenciesnpminstalllit@^3.3.0# 2. Copy each file's "content" from# https://cdn.jsdelivr.net/npm/@purpurabog/ui@2.3.0/registry/popover.json# to its target:# components/ui/primitives/popover/popover.ts# 3. Do the same for the items it needs (registry/<name>.json):# core-hover-open, core-popup, shared-align, shared-element, shared-events, shared-field, shared-position, tokens# React + Tailwind# 1. Install the dependenciesnpminstall@purpurabog/ui@^2.3.0# 2. Copy each file's "content" from# https://cdn.jsdelivr.net/npm/@purpurabog/ui@2.3.0/registry/tw-popover.json# to its target:# components/ui/react-tw/popover.tsx# 3. Do the same for the items it needs (registry/<name>.json):# core-hover-open, core-position, tw-dom, tw-floating, tw-i18n, tw-refs, tw-theme, tw-utils
npm gives you every component from the package. shadcn copies the source into your app instead: a copy pinned to this version that you can change. The shadcn commands need the @kanok-ui registry in your components.json once, see Installation.
Use it
Put the trigger in the trigger slot and the content inside. The popover doesn't open by itself: toggle open when the trigger is clicked.
show() and hide() on the element do the same as setting open. In React + Tailwind the trigger is the trigger prop: it gets aria-expanded and aria-controls.
The user must finish or cancel a task before going back to the page.
Close it yourself
Without auto-close, only your code closes the popover: Esc and clicks outside do nothing. Use it when the user must answer, for example a "what's new" hint with its own button.
Bulk signing
New: sign up to 50 contracts at onceSelect the contracts in the list, then choose Sign.
Got it
HTMLReactReact + Tailwind<ui-popoverid="popover-hint"label="New feature"placement="right">
<ui-buttonslot="trigger"kind="tertiary">Bulk signing</ui-button>
<divstyle="display: grid; gap: 8px; padding: 16px; width: 240px">
<strong>New: sign up to 50 contracts at once</strong>
<span>Select the contracts in the list, then choose Sign.</span>
<div><ui-buttonid="popover-hint-done"size="sm">Got it</ui-button></div>
</div>
</ui-popover>
<scripttype="module">
const popover = document.getElementById('popover-hint');
const trigger = popover.querySelector('[slot="trigger"]');
trigger.addEventListener('click', () => (popover.open =!popover.open));
document.getElementById('popover-hint-done').addEventListener('click', () => {
popover.open =false;
trigger.focus();
});
</script><UiPopoverlabel="New feature"placement="right"open={open}>
<UiButtonslot="trigger"kind="tertiary"onClick={() =>setOpen(!open)}>Bulk signing</UiButton>
<divstyle={{ display:'grid', gap:8, padding:16, width:240 }}>
<strong>New: sign up to 50 contracts at once</strong>
<span>Select the contracts in the list, then choose Sign.</span>
<div><UiButtonsize="sm"onClick={() =>setOpen(false)}>Got it</UiButton></div>
</div>
</UiPopover><Popoverlabel="New feature"placement="right"open={open} trigger={<Buttonkind="tertiary"onClick={() =>setOpen(!open)}>Bulk signing</Button>}>
<divclassName="grid w-60 gap-2 p-4">
<strong>New: sign up to 50 contracts at once</strong>
<span>Select the contracts in the list, then choose Sign.</span>
<div><Buttonsize="sm"onClick={() =>setOpen(false)}>Got it</Button></div>
</div>
</Popover>
When your code closes the popover while focus is inside it, give focus back to the trigger yourself, as the demo does. With auto-close, Esc does that for you.
Placement
The box opens below the trigger (placement="bottom"). top, left, right and the -start / -end forms move it; it flips when there is no room. align is Carbon's name for the same attribute.
Top
Opens above
Bottom start
Lined up with the start edge
Right
Opens on the right
HTMLReactReact + Tailwind<divid="popover-placement"style="display: flex; flex-wrap: wrap; gap: 16px; align-items: center">
<ui-popoverplacement="top"auto-closelabel="Above">
<ui-buttonslot="trigger"kind="tertiary"size="sm">Top</ui-button>
<divstyle="padding: 16px">Opens above</div>
</ui-popover>
<ui-popoverplacement="bottom-start"auto-closelabel="Below, start">
<ui-buttonslot="trigger"kind="tertiary"size="sm">Bottom start</ui-button>
<divstyle="padding: 16px">Lined up with the start edge</div>
</ui-popover>
<ui-popoverplacement="right"auto-closelabel="Right">
<ui-buttonslot="trigger"kind="tertiary"size="sm">Right</ui-button>
<divstyle="padding: 16px">Opens on the right</div>
</ui-popover>
</div>
<scripttype="module">
for (const popover of document.querySelectorAll('#popover-placement ui-popover')) {
popover.querySelector('[slot="trigger"]').addEventListener('click', () => (popover.open =!popover.open));
}
</script><UiPopoverplacement="top"autoCloselabel="Above"open={open} onUiToggle={(e) =>setOpen(e.detail.open)}>…</UiPopover>
<UiPopoverplacement="bottom-start"autoCloselabel="Below, start" …>…</UiPopover>
<UiPopover placement="right"autoCloselabel="Right" …>…</UiPopover><Popoverplacement="top"autoCloselabel="Above"open={open} onOpenChange={setOpen} trigger={…}>…</Popover>
<Popoverplacement="bottom-start"autoCloselabel="Below, start" …>…</Popover>
<Popover placement="right"autoCloselabel="Right" …>…</Popover>
Caret and shadow
The caret (12×6px, 10px from the trigger) and the drop shadow are on by default. caret="false" puts the box flush against the trigger with no arrow; drop-shadow="false" removes the shadow, for a box on a layer that already stands out.
high-contrast (highContrast in React) gives the box the inverse colours of a tooltip: dark in the light theme, light in the dark one.
Signing order
Ananya signs first, then Somchai, then the customer.
HTMLReactReact + Tailwind<ui-popoverid="popover-contrast"high-contrastauto-closelabel="Signing order">
<ui-buttonslot="trigger"kind="tertiary">Signing order</ui-button>
<divstyle="padding: 16px; width: 220px">Ananya signs first, then Somchai, then the customer.</div>
</ui-popover>
<scripttype="module">
const popover = document.getElementById('popover-contrast');
popover.querySelector('[slot="trigger"]').addEventListener('click', () => (popover.open =!popover.open));
</script><UiPopoverhighContrastautoCloselabel="Signing order"open={open} onUiToggle={(e) =>setOpen(e.detail.open)}>
<UiButtonslot="trigger"kind="tertiary"onClick={() =>setOpen(!open)}>Signing order</UiButton>
<divstyle={{ padding:16, width:220 }}>Ananya signs first, then Somchai, then the customer.</div>
</UiPopover><PopoverhighContrastautoCloselabel="Signing order"open={open} onOpenChange={setOpen} trigger={<Buttonkind="tertiary"onClick={() =>setOpen(!open)}>Signing order</Button>}>
<divclassName="w-56 p-4">Ananya signs first, then Somchai, then the customer.</div>
</Popover>
Tab tip
tab-tip (Carbon's isTabTip) makes a square box with no caret, flush under the trigger, as if the two were one piece. Use it for settings behind an icon button in a toolbar, usually with placement="bottom-end".
A popover can hold a short form, such as renaming a record in place. Prevent the submit, use the values, close the popover and give focus back to the trigger.
save and name are the same in both React versions. In React, give focus back to the trigger after setOpen(false) (a ref on it) when focus was inside.
Keep it open
With auto-close, Esc and a click outside first fire ui-request-close with detail.reason (escape or outside). It is cancelable: preventDefault() keeps the box open, for example while a note isn't saved. ui-toggle fires after it opens or closes. Type a note below, then press Esc or click outside.
Add a note
Save note
Last request:
HTMLReactReact + Tailwind<ui-popoverid="popover-note"label="Note for the signer"auto-closeplacement="bottom-start">
<ui-buttonslot="trigger"kind="tertiary">Add a note</ui-button>
<divstyle="display: grid; gap: 16px; padding: 16px; width: 280px">
<ui-text-areaid="popover-note-text"label="Note for the signer"rows="3"></ui-text-area>
<div><ui-buttonid="popover-note-save"size="sm">Save note</ui-button></div>
</div>
</ui-popover>
<pstyle="margin: 0">Last request: <outputid="popover-note-out">none</output></p>
<scripttype="module">
const popover = document.getElementById('popover-note');
const trigger = popover.querySelector('[slot="trigger"]');
const text = document.getElementById('popover-note-text');
const out = document.getElementById('popover-note-out');
trigger.addEventListener('click', () => (popover.open =!popover.open));
popover.addEventListener('ui-request-close', (event) => {
const unsaved = text.value.trim() !=='';
out.value = unsaved ?`${event.detail.reason}, kept open: the note isn't saved`: event.detail.reason;
if (unsaved) event.preventDefault();
});
document.getElementById('popover-note-save').addEventListener('click', () => {
out.value =`saved "${text.value.trim()}"`;
text.value ='';
popover.open =false;
trigger.focus();
});
</script>const [note, setNote] =useState('');
<UiPopoverlabel="Note for the signer"autoCloseplacement="bottom-start"open={open}
onUiToggle={(e) =>setOpen(e.detail.open)}
onUiRequestClose={(e) => note.trim() && e.preventDefault()}
>
<UiButtonslot="trigger"kind="tertiary"onClick={() =>setOpen(!open)}>Add a note</UiButton>
<UiTextArealabel="Note for the signer"rows={3} value={note} onInput={(e) =>setNote((e.target as { value:string }).value)} />
<UiButtonsize="sm"onClick={save}>Save note</UiButton>
</UiPopover>// open stays true unless you set it: ignore the request while the note isn't saved
<Popoverlabel="Note for the signer"autoCloseplacement="bottom-start"open={open}
onOpenChange={(next) =>!note.trim() &&setOpen(next)}
trigger={<Buttonkind="tertiary"onClick={() =>setOpen(!open)}>Add a note</Button>}
>
<TextArealabel="Note for the signer"rows={3} value={note} onChange={(e) =>setNote(e.target.value)} />
<Buttonsize="sm"onClick={save}>Save note</Button>
</Popover>
Open on hover
Beyond Carbon: open-on-hover (openOnHover) opens the popover while the pointer rests on its trigger (after 100ms) and closes it 300ms after the pointer leaves both the trigger and the popover, so the pointer can move onto the content. A keyboard user opens it by tabbing to the trigger; Esc closes it and keeps focus on the trigger. On a touch screen a tap opens and closes it. Use it for previews, such as a larger picture of a receipt; keep actions the user must reach in a popover that opens on click.
Moves through the trigger and the content in page order
Esc
With auto-close, from the trigger or the content: asks to close and gives focus back to the trigger. A control inside that uses Esc itself (an open dropdown) handles it first
Enter, Space on the trigger
Whatever your click handler does, usually toggles open
Accessibility
The box has role="group" named by label. Give it a label that says what the content is.
The popover sets aria-expanded on the trigger (expanded on a <ui-button> or <ui-icon-button>).
Focus doesn't move into the box when it opens. Keep the content short and right after the trigger, so a keyboard user reaches it with the next Tab.
For a task the user must finish before going on, use a modal instead.
Generated from the package. In React, pass a property as a prop of the same name; events are props too (the React column).
<ui-popover> · React UiPopover
Attributes
Attribute
Property
Type
Default
Description
align
Carbon's name for placement (same values)
open
open
boolean
false
placement
placement
Placement
'bottom'
caret
caret
boolean
true
On by default; caret="false" hides it.
drop-shadow
dropShadow
boolean
true
On by default; drop-shadow="false" removes it.
high-contrast
highContrast
boolean
false
tab-tip
tabTip
boolean
false
Carbon isTabTip: square box flush against the trigger (toolbar settings panels).
auto-close
autoClose
boolean
false
Close on Escape and on clicks outside the trigger and the box.
label
label
string
''
Accessible name of the box (role=group).
open-on-hover
openOnHover
boolean
false
Beyond Carbon (its Popover has no hover mode; the tooltip's timings): the popover opens and closes itself. A mouse resting on the trigger opens it after 100ms, and leaving the trigger and the box closes it after 300ms (the pointer can move onto the box, WCAG 1.4.13); keyboard focus on the trigger opens it at once, and focus leaving the trigger and the box closes it; a tap (touch, pen) on the trigger toggles it; Escape and a press outside close it. While focus is in the box, or on the trigger by keyboard, it stays open.
Events
Event
React
Description
ui-toggle
onUiToggle
detail: { open } after it opens or closes
ui-request-close
onUiRequestClose
cancelable; auto-close fires it before closing on Escape / outside click
Slots
Slot
Description
trigger
The element the box is positioned against
(default)
Box content
CSS parts
Part
Description
content
The floating box
caret
The arrow
CSS custom properties
Custom property
Default
Description
--ui-menu-border
/ --ui-menu-radius - Border and corners of the bubble (the menu settings)