Tab Button
A tab inside Toggles.
Use tab buttons only inside Toggles or another element with role="tablist", which makes selection and keyboard navigation work as a group.
Usage
See Toggles for a complete example.
TabButton is also exported from @bedform/ui/tab-button.
Palettes
<TabButton palette="default" selected>
Worlds
</TabButton>
<TabButton palette="toggle" selected>
Enabled
</TabButton>Events
Tab Button dispatches a native change event after it becomes selected through the keyboard or a click. React's onChange does not fire for buttons, so listen through a ref:
const tabRef = useRef<HTMLButtonElement>(null);
useEffect(() => {
const tab = tabRef.current;
const listener = () => console.log(tab?.getAttribute("aria-selected"));
tab?.addEventListener("change", listener);
return () => tab?.removeEventListener("change", listener);
}, []);
<TabButton ref={tabRef}>Worlds</TabButton>;API
TabButton renders a native button with role="tab" and accepts every button attribute. It forwards its ref to the button.
| Prop | Type | Default |
|---|---|---|
disabled | boolean | false |
palette | "default" | "toggle" | "default" |
selected | boolean | false |
type | "button" | "reset" | "submit" | "submit" |
| Event | Detail |
|---|---|
change | None |
CSS variables
Tab Button also accepts all Button CSS variables.
| Variable | Purpose |
|---|---|
--ore-tab-off-background | Unselected background |
--ore-tab-off-background-hover | Unselected hover background |
--ore-tab-off-background-pressed | Unselected pressed background |
--ore-tab-off-highlight | Unselected highlight |
--ore-tab-off-highlight-hover | Unselected hover highlight |
--ore-tab-off-highlight-pressed | Unselected pressed highlight |
--ore-tab-off-shadow | Unselected shadow |
--ore-tab-off-foreground | Unselected text color |
--ore-tab-on-background | Selected background |
--ore-tab-on-highlight | Selected highlight |
--ore-tab-on-foreground | Selected text color |
--ore-tab-indicator | Selection indicator color |
Accessibility
Tab Button is a native button with role="tab". The tab controller updates aria-selected from clicks and keys, and the selected prop sets it from React. Arrow keys move through tabs that are not disabled, while Home and End select the first and last tab.