TabProvider
Provides a tab store to Tab components.
Code examples
Optional Props
activeId
string | null | undefined
The current active item id
. The active item is the element within the
composite widget that has either DOM or virtual focus (in case
virtualFocus
is enabled).
null
represents the base composite element (the one with a composite role). Users will be able to navigate out of it using arrow keys.If
activeId
is initially set tonull
, theincludesBaseElement
prop will also default totrue
, which means the base composite element itself will have focus and users will be able to navigate to it using arrow keys.
Live examples
combobox
ComboboxStore<ComboboxStoreSelectedValue> | null | undefined
A reference to a combobox store. This is automatically set when rendering tabs inside a Combobox.
Live examples
composite
CompositeStore<CompositeStoreItem> | null | undefined
A reference to another composite store. This is automatically set when rendering tabs as part of another composite widget, such as Combobox or Select.
Live examples
defaultActiveId
string | null | undefined
The composite item id that should be active by default when the composite
widget is rendered. If null
, the composite element itself will have focus
and users will be able to navigate to it using arrow keys. If undefined
,
the first enabled item will be focused.
defaultItems
T[] | undefined = []
The defaut value for the
items
state.
defaultSelectedId
string | null | undefined
The id of the tab whose panel is currently visible. If it's undefined
, it
will be automatically set to the first enabled tab.
Live examples
focusLoop
boolean | Orientation = true
Determines how the focus behaves when the user reaches the end of the composite widget.
On one-dimensional composite widgets:
true
loops from the last item to the first item and vice-versa.horizontal
loops only iforientation
ishorizontal
or not set.vertical
loops only iforientation
isvertical
or not set.If
includesBaseElement
is set totrue
(oractiveId
is initially set tonull
), the composite element will be focused in between the last and first items.
On two-dimensional composite widgets (when using
CompositeRow
or explicitly
passing a rowId
prop to composite items):
true
loops from the last row/column item to the first item in the same row/column and vice-versa. If it's the last item in the last row, it moves to the first item in the first row and vice-versa.horizontal
loops only from the last row item to the first item in the same row.vertical
loops only from the last column item to the first item in the column row.If
includesBaseElement
is set totrue
(oractiveId
is initially set tonull
), vertical loop will have no effect as moving down from the last row or up from the first row will focus on the composite element.If
focusWrap
matches the value offocusLoop
, it'll wrap between the last item in the last row or column and the first item in the first row or column and vice-versa.
Live examples
focusShift
boolean = false
Works only on two-dimensional composite widgets.
If enabled, moving up or down when there's no next item or when the next item is disabled will shift to the item right before it.
focusWrap
boolean | Orientation = false
Works only on two-dimensional composite widgets.
If enabled, moving to the next item from the last one in a row or column will focus on the first item in the next row or column and vice-versa.
true
wraps between rows and columns.horizontal
wraps only between rows.vertical
wraps only between columns.If
focusLoop
matches the value offocusWrap
, it'll wrap between the last item in the last row or column and the first item in the first row or column and vice-versa.
id
string
The ID of the composite store is used to reference elements within the composite widget before hydration. If not provided, a random ID will be generated.
includesBaseElement
boolean = false
Indicates if the composite base element (the one with a composite
role
Live examples
items
T[]
Lists all items along with their metadata. This state is automatically
updated when an item is registered or unregistered using the
registerItem
function.
orientation
Orientation = "horizontal"
Defines the orientation of the composite widget. If the composite has a
single row or column (one-dimensional), the orientation
value determines
which arrow keys can be used to move focus:
both
: all arrow keys work.horizontal
: only left and right arrow keys work.vertical
: only up and down arrow keys work.
It doesn't have any effect on two-dimensional composites.
rtl
boolean = false
Determines how the
next
and
previous
functions will behave. If rtl
is set to true
, they will be inverted.
This only affects the composite widget behavior. You still need to set
dir="rtl"
on HTML/CSS.
selectedId
string | null | undefined
The id of the tab whose panel is currently visible. If it's undefined
, it
will be automatically set to the first enabled tab.
Live examples
selectOnMove
boolean | undefined = true
Determines if the tab should be selected when it receives focus. If set to
false
, the tab will only be selected upon clicking, not when using arrow
keys to shift focus.
Live examples
setActiveId
((activeId: string | null | undefined) => void) | undefined
A callback that gets called when the
activeId
state changes.
setItems
BivariantCallback<(items: T[]) => void> | undefined
A callback that gets called when the
items
state
changes.
Code examples
const [items, setItems] = useState([]);
setSelectedId
((selectedId: string | null | undefined) => void) | undefined
Function that will be called when the
selectedId
state
changes.
Live examples
store
Store<Partial<S>> | undefined
Another store object that will be kept in sync with the original store.
Live examples
virtualFocus
boolean = false
If enabled, the composite element will act as an
aria-activedescendant
In both scenarios, the item in focus will carry the
data-active-item
attribute.