Bedform UIButtons

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.

PropTypeDefault
disabledbooleanfalse
palette"default" | "toggle""default"
selectedbooleanfalse
type"button" | "reset" | "submit""submit"
EventDetail
changeNone

CSS variables

Tab Button also accepts all Button CSS variables.

VariablePurpose
--ore-tab-off-backgroundUnselected background
--ore-tab-off-background-hoverUnselected hover background
--ore-tab-off-background-pressedUnselected pressed background
--ore-tab-off-highlightUnselected highlight
--ore-tab-off-highlight-hoverUnselected hover highlight
--ore-tab-off-highlight-pressedUnselected pressed highlight
--ore-tab-off-shadowUnselected shadow
--ore-tab-off-foregroundUnselected text color
--ore-tab-on-backgroundSelected background
--ore-tab-on-highlightSelected highlight
--ore-tab-on-foregroundSelected text color
--ore-tab-indicatorSelection 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.

On this page