Components

Tabs

A component for toggling between related panels on the same page.

Workspace stats and activity.

Anatomy#

Import the component and assemble its parts:

Anatomytsx
import { Tabs } from '@egoist/solid-base/tabs';

<Tabs.Root>
  <Tabs.List>
    <Tabs.Tab />
    <Tabs.Indicator />
  </Tabs.List>
  <Tabs.Panel />
</Tabs.Root>;

Examples#

Animated panels#

Animate panels as they activate using the data-starting-style and data-ending-style attributes. The data-activation-direction attribute indicates which direction the newly active tab is relative to the previously active one, letting panels slide in from the correct side.

Workspace stats and activity.

Use the render prop and set nativeButton={false} on <Tabs.Tab> to render tabs as anchor elements. The function receives the props to spread on your link component:

Tabs as linkstsx
import { Tabs } from '@egoist/solid-base/tabs';
import { A } from '@solidjs/router';

<Tabs.Root>
  <Tabs.List>
    <Tabs.Tab
      nativeButton={false}
      render={(props) => <A {...props} href="/overview" />}
      value="overview"
    >
      Overview
    </Tabs.Tab>
  </Tabs.List>
  {/* ... */}
</Tabs.Root>;

API reference#

<Tabs.Root>

Groups the tabs and the corresponding panels. Renders a <div> element.

PropTypeDefault
valueTabsTab.Value—

The value of the currently active Tab. Use when the component is controlled. When the value is null, no Tab will be active.

defaultValueTabsTab.Value0

The default value. Use when the component is not controlled. When the value is null, no Tab will be active.

orientationTabsRoot.Orientation'horizontal'

The component orientation (layout flow direction).

onValueChange| ((value: TabsTab.Value, eventDetails: TabsRoot.ChangeEventDetails) => void)—

Callback invoked when new value is being set.

The event reason is 'none' for user-initiated changes, such as a click or keyboard navigation; 'initial' for the first automatic selection or fallback in uncontrolled roots when defaultValue is omitted or undefined, including when the implicit initial value is disabled or missing; 'disabled' for automatic fallback when the selected tab becomes disabled in uncontrolled roots; or 'missing' for automatic fallback when the selected tab is removed, or when an explicit defaultValue never matches a mounted tab in uncontrolled roots.

For automatic changes, the selected value can be null when no enabled Tab is available as a fallback.

Automatic changes cannot be canceled; calling eventDetails.cancel() for 'initial', 'disabled', or 'missing' has no effect.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-activation-direction

Indicates the direction of the activation (based on the previous active tab).

data-orientation

Indicates the orientation of the tabs.

<Tabs.Tab>

An individual interactive tab button that toggles the corresponding panel. Renders a <button> element.

PropTypeDefault
value*TabsTab.Value—

The value of the Tab.

disabledboolean—

Whether the Tab is disabled.

If a first Tab on a <Tabs.List> is disabled, it won't initially be selected. Instead, the next enabled Tab will be selected. However, it does not work like this during server-side rendering, as it is not known during pre-rendering which Tabs are disabled. To work around it, ensure that defaultValue or value on <Tabs.Root> is set to an enabled Tab's value.

nativeButtonbooleantrue

Whether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (for example, <div>).

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-activation-direction

Indicates the direction of the activation (based on the previous active tab).

data-orientation

Indicates the orientation of the tabs.

data-disabled

Present when the tab is disabled.

data-active

Present when the tab is active.

<Tabs.Indicator>

A visual indicator that can be styled to match the position of the currently active tab. Renders a <span> element.

PropTypeDefault
renderBeforeHydrationbooleanfalse

Whether to render itself before the client hydrates. This minimizes the time that the indicator isn't visible after server-side rendering.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-activation-direction

Indicates the direction of the activation (based on the previous active tab).

data-orientation

Indicates the orientation of the tabs.

CSS variableDescription
--active-tab-left

Indicates the distance on the left side from the parent's container if the tab is active.

--active-tab-right

Indicates the distance on the right side from the parent's container if the tab is active.

--active-tab-top

Indicates the distance on the top side from the parent's container if the tab is active.

--active-tab-bottom

Indicates the distance on the bottom side from the parent's container if the tab is active.

--active-tab-width

Indicates the width of the tab if it is active.

--active-tab-height

Indicates the height of the tab if it is active.

<Tabs.Panel>

A panel displayed when the corresponding tab is active. Renders a <div> element.

PropTypeDefault
value*TabsTab.Value—

The value of the TabPanel. It will be shown when the Tab with the corresponding value is active.

keepMountedbooleanfalse

Whether to keep the HTML element in the DOM while the panel is hidden.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-index

Indicates the index of the tab panel.

data-activation-direction

Indicates the direction of the activation (based on the previous active tab).

data-orientation

Indicates the orientation of the tabs.

data-hidden

Present when the panel is hidden.

<Tabs.List>

Groups the individual tab buttons. Renders a <div> element.

PropTypeDefault
activateOnFocusbooleanfalse

Whether to automatically change the active tab on arrow key focus. Otherwise, tabs will be activated using <kbd>Enter</kbd> or <kbd>Space</kbd> key press.

loopFocusbooleantrue

Whether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-activation-direction

Indicates the direction of the activation (based on the previous active tab).

data-orientation

Indicates the orientation of the tabs.