Examples
When to use
Use IconButton when the action is familiar from its icon and the surrounding context makes it easy to understand. Use a text Button when the action is new, high impact, or needs a longer explanation.
Notifications, search, close, or compact toolbar actions with a stable label.
Do not hide “Delete account” or another consequential action behind an unfamiliar icon.
Usage
import { Bell } from "@phuctech/ui/icons";
import { IconButton } from "@phuctech/ui/components/icon-button";
export function Example() {
return (
<IconButton aria-label="View notifications" variant="outline">
<Bell aria-hidden="true" />
</IconButton>
);
}
The required aria-label is the accessible name. Keep it short and describe the action, not the icon.
Variants and states
Icons
Use a PhucTech icon from @phuctech/ui/icons and mark it aria-hidden="true". Do not use the icon as the only accessible name; the explicit aria-label is the contract.
API
Tokens
Accessibility
- Provide the required
aria-label; a tooltip is not a replacement for the accessible name. - Test focus, Enter, Space, disabled, and loading states with a keyboard.
- Keep the target at least the shared control size; do not shrink an icon only to fit more actions.
Do and don’t
Use one clear action label, a familiar icon, and a visible focus ring.
Render an unlabeled icon, rely on color alone, or put many ambiguous icons side by side.