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
Toggletip
A toggletip is a small "i" button that opens an explanation when clicked. Unlike a tooltip, it stays open until the user closes it, and it may hold links and buttons. Put it next to a label or a heading that needs more context.
Retention period
Signed copies are kept for 10 years, then moved to the archive. Read the policy
HTMLReactReact + Tailwind<pstyle="display: flex; align-items: center; gap: 8px; margin: 0">
Retention period
<ui-toggletiplabel="About the retention period">
Signed copies are kept for 10 years, then moved to the archive. <ahref="#accessibility">Read the policy</a>
</ui-toggletip>
</p><pstyle={{ display:'flex', alignItems:'center', gap:8 }}>
Retention period
<UiToggletiplabel="About the retention period">
Signed copies are kept for 10 years, then moved to the archive. <ahref="/policy">Read the policy</a>
</UiToggletip>
</p><pclassName="flex items-center gap-2">
Retention period
<Toggletiplabel="About the retention period">
Signed copies are kept for 10 years, then moved to the archive. <ahref="/policy">Read the policy</a>
</Toggletip>
</p>
Installation
npmshadcn · Web componentshadcn · React + TailwindManualnpminstall@purpurabog/uinpxshadcn@4add@kanok-ui/toggletipnpxshadcn@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/toggletip.json# to its target:# components/ui/primitives/toggletip/toggletip.ts# 3. Do the same for the items it needs (registry/<name>.json):# core-popup, shared-align, shared-element, shared-events, shared-field, shared-localize, 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 explanation inside the element and name the button with label.
HTMLReactReact + Tailwind<scripttype="module">import'@purpurabog/ui/toggletip';</script>
<ui-toggletiplabel="About the retention period">
Signed copies are kept for 10 years.
</ui-toggletip>import { UiToggletip } from'@purpurabog/ui/react';
<UiToggletiplabel="About the retention period">
Signed copies are kept for 10 years.
</UiToggletip>import { Toggletip } from'@/components/ui/react-tw/popover';
<Toggletiplabel="About the retention period">
Signed copies are kept for 10 years.
</Toggletip>
React + Tailwind's Toggletip lives in the popover file, as both are built on the same parts.
Toggletip or tooltip?
Tooltip
Toggletip
Opens on
Hover and keyboard focus
A click, Enter or Space on the "i" button
Closes on
The pointer or focus leaving, Esc
Another click, Esc, a click outside, focus leaving both the button and the bubble
Content
One line of plain text
Text, links and buttons
Trigger
The control it explains
Its own "i" button
See the tooltip page for the definition tooltip and the popover too.
Beside a heading
The toggletip is an inline element that sits on the text's middle line. Put it right after the words it explains, so it reads as part of the same line.
Approval route
Contracts go to the department head first. Above 5 million baht, Finance approves as well.
HTMLReactReact + Tailwind<divstyle="display: flex; align-items: center; gap: 4px">
<h3style="margin: 0; font: var(--ui-font-heading-02)">Approval route</h3>
<ui-toggletiplabel="About the approval route">
Contracts go to the department head first. Above 5 million baht, Finance approves as well.
</ui-toggletip>
</div><divstyle={{ display:'flex', alignItems:'center', gap:4 }}>
<h3>Approval route</h3>
<UiToggletiplabel="About the approval route">
Contracts go to the department head first. Above 5 million baht, Finance approves as well.
</UiToggletip>
</div><divclassName="flex items-center gap-1">
<h3className="type-heading-02">Approval route</h3>
<Toggletiplabel="About the approval route">
Contracts go to the department head first. Above 5 million baht, Finance approves as well.
</Toggletip>
</div>
Links and buttons inside
The content follows the button in the Tab order, so a keyboard user reaches a link or a button inside with the next Tab. A link put directly inside takes the primary colour.
HTMLReactReact + Tailwind<pstyle="display: flex; align-items: center; gap: 8px; margin: 0">
e-Signature
<ui-toggletipid="toggletip-esign"label="About e-signatures">
An e-signature is valid under the Electronic Transactions Act B.E. 2544.
<ahref="#links-and-buttons-inside"style="display: block; margin-block: 8px">Which documents can be signed online?</a>
<ui-buttonid="toggletip-esign-done"size="sm"kind="tertiary">Got it</ui-button>
</ui-toggletip>
</p>
<scripttype="module">
const tip = document.getElementById('toggletip-esign');
document.getElementById('toggletip-esign-done').addEventListener('click', () => tip.hide());
</script><UiToggletiplabel="About e-signatures"open={open} onUiToggle={(e) =>setOpen(e.detail.open)}>
An e-signature is valid under the Electronic Transactions Act B.E. 2544.
<ahref="/help/e-signature"style={{ display:'block', marginBlock:8 }}>Which documents can be signed online?</a>
<UiButtonsize="sm"kind="tertiary"onClick={() =>setOpen(false)}>Got it</UiButton>
</UiToggletip><Toggletiplabel="About e-signatures"open={open} onOpenChange={setOpen}>
<spanclassName="grid gap-2">
<span>An e-signature is valid under the Electronic Transactions Act B.E. 2544.</span>
<ahref="/help/e-signature">Which documents can be signed online?</a>
<span><Buttonsize="sm"kind="tertiary"onClick={() =>setOpen(false)}>Got it</Button></span>
</span>
</Toggletip>
When the bubble closes while focus is inside it (the "Got it" button, Esc), focus goes back to the "i" button.
Placement
The bubble opens below the button (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 the button.Right Opens on the right of the button.Bottom start Lined up with the start edge of the button.
HTMLReactReact + Tailwind<divstyle="display: flex; flex-wrap: wrap; gap: 32px; align-items: center">
<spanstyle="display: flex; align-items: center; gap: 4px">Top <ui-toggletipplacement="top"label="Opens above">Opens above the button.</ui-toggletip></span>
<spanstyle="display: flex; align-items: center; gap: 4px">Right <ui-toggletipplacement="right"label="Opens on the right">Opens on the right of the button.</ui-toggletip></span>
<spanstyle="display: flex; align-items: center; gap: 4px">Bottom start <ui-toggletipplacement="bottom-start"label="Opens below, start">Lined up with the start edge of the button.</ui-toggletip></span>
</div><UiToggletipplacement="top"label="Opens above">Opens above the button.</UiToggletip>
<UiToggletipplacement="right"label="Opens on the right">Opens on the right of the button.</UiToggletip>
<UiToggletipplacement="bottom-start"label="Opens below, start">Lined up with the start edge of the button.</UiToggletip><Toggletipplacement="top"label="Opens above">Opens above the button.</Toggletip>
<Toggletipplacement="right"label="Opens on the right">Opens on the right of the button.</Toggletip>
<Toggletipplacement="bottom-start"label="Opens below, start">Lined up with the start edge of the button.</Toggletip>
Another icon
The "i" is the default. Put another 16px icon in the trigger slot (icon in React + Tailwind), for example Carbon's Help (see Icons). It takes the button's colour.
Stamp duty
The duty is 0.1% of the rent for the whole term, paid within 15 days of signing.
HTMLReactReact + Tailwind<pstyle="display: flex; align-items: center; gap: 8px; margin: 0">
Stamp duty
<ui-toggletiplabel="How stamp duty is worked out">
<svgslot="trigger"viewBox="0 0 32 32"aria-hidden="true"><pathd="M16 2a14 14 0 1 0 14 14A14 14 0 0 0 16 2Zm0 26a12 12 0 1 1 12-12 12 12 0 0 1-12 12Z"/><circlecx="16"cy="23.5"r="1.5"/><pathd="M17 8h-1.5a4.49 4.49 0 0 0-4.5 4.5v.5h2v-.5a2.5 2.5 0 0 1 2.5-2.5H17a2.5 2.5 0 0 1 0 5h-2v4.5h2V17a4.5 4.5 0 0 0 0-9Z"/></svg>
The duty is 0.1% of the rent for the whole term, paid within 15 days of signing.
</ui-toggletip>
</p>import { Help as HelpIcon } from'@carbon/icons-react';
<UiToggletiplabel="How stamp duty is worked out">
<HelpIconslot="trigger"aria-hidden="true" />
The duty is 0.1% of the rent for the whole term, paid within 15 days of signing.
</UiToggletip>import { Help as HelpIcon } from'@carbon/icons-react';
<Toggletiplabel="How stamp duty is worked out"icon={<HelpIconaria-hidden="true" />}>
The duty is 0.1% of the rent for the whole term, paid within 15 days of signing.
</Toggletip>
Open state and events
open is the state; show() and hide() set it. ui-toggle fires after the bubble opens or closes, with detail.open.
Deposit
The deposit is two months' rent, returned within 30 days after the lease ends.
Open:
HTMLReactReact + Tailwind<pstyle="display: flex; align-items: center; gap: 8px; margin: 0">
Deposit
<ui-toggletipid="toggletip-deposit"label="About the deposit">The deposit is two months' rent, returned within 30 days after the lease ends.</ui-toggletip>
</p>
<pstyle="margin: 0">Open: <outputid="toggletip-deposit-out">false</output></p>
<scripttype="module">
const tip = document.getElementById('toggletip-deposit');
const out = document.getElementById('toggletip-deposit-out');
tip.addEventListener('ui-toggle', (event) => (out.value =String(event.detail.open)));
</script>const [open, setOpen] =useState(false);
<UiToggletiplabel="About the deposit"open={open} onUiToggle={(e) =>setOpen(e.detail.open)}>
The deposit is two months' rent, returned within 30 days after the lease ends.
</UiToggletip>
<p>Open: <output>{String(open)}</output></p>const [open, setOpen] =useState(false);
<Toggletiplabel="About the deposit"open={open} onOpenChange={setOpen}>
The deposit is two months' rent, returned within 30 days after the lease ends.
</Toggletip>
<p>Open: <output>{String(open)}</output></p>
Leave open out in React + Tailwind and the toggletip keeps its own state.
Keyboard
Key
What it does
Enter, Space
On the button: open or close the bubble
Tab
From the button into the content; leaving both closes the bubble
Esc
Closes the bubble and gives focus back to the button when it was inside
A click outside the button and the bubble closes it too.
Accessibility
The trigger is a real <button> with aria-expanded and aria-controls. Its name is label, else "More information" in the page language (Thai or English).
The bubble has role="group" with the same name, so screen readers say what the content is about.
Give label the topic ("About the deposit"), not "Info": a page with several toggletips needs a different name on each.
Unstyled React parts with the same behaviour: Headless Popover, with closeOnFocusOut.
API
Generated from the package. In React, pass a property as a prop of the same name; events are props too (the React column).
<ui-toggletip> · React UiToggletip
Attributes
Attribute
Property
Type
Default
Description
align
Carbon's name for placement (same values)
label
label
string
''
Accessible name of the trigger, e.g. "More about retention".
placement
placement
Placement
'bottom'
open
open
boolean
false
Events
Event
React
Description
ui-toggle
onUiToggle
detail: { open }, after it opens or closes
Slots
Slot
Description
(default)
Bubble content (text, links, buttons)
trigger
Custom trigger icon (default: an "i" information icon)
CSS parts
Part
Description
trigger
The info button
bubble
The popover content box
caret
The arrow pointing at the trigger
CSS custom properties
Custom property
Default
Description
--ui-menu-border
/ --ui-menu-radius - Border and corners of the bubble (the menu settings)
--ui-icon-control-radius
Corners of its small icon buttons, their hover fill and ring (default 0; Kanok: round)
--ui-focus-offset
outline-offset of its focus ring (default -2px: inside; Kanok: 2px outside)