Flex
Flexbox layout primitive with token-backed gap options.
Preview
A live, theme-aware example rendered with the published component.
Loading preview…
Import
Import the component from its dedicated entry point to keep the dependency and generated bundle explicit.
tsximport { Flex } from "@tavojs/ui/flex";Normal Tavo.js applications load component styles through the Tavo.js UI plugin. If the application manages component CSS manually, also import @tavojs/ui/css/flex.
When to use
Use it when
Choose something else when
Examples
Flex example
tsximport { Flex } from "@tavojs/ui/flex";
export function FlexExample1() {
return (
<>
<Flex align="center" justify="between">...</Flex>
</>
);
}Common props and defaults
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | — | Optional class hook applied to the public root element owned by the component. |
as | string | Component<Record<string, unknown>> | — | Changes the rendered root element or component while preserving Tavo.js UI styling and public props. |
direction | "row" | "column" | — | Configures direction for this component. |
gap | "none" | "sm" | "md" | "lg" | number | string | — | Configures gap for this component. |
align | "start" | "center" | "end" | "stretch" | — | Configures align for this component. |
justify | "start" | "center" | "end" | "between" | — | Configures justify for this component. |
wrap | boolean | — | Configures wrap for this component. |
Complete TypeScript API
Import from @tavojs/ui/flex. Published exports: Flex, FlexProps.
FlexProps
| Property | Type | Required | Description |
|---|---|---|---|
children | Child | No | Inherited children attribute accepted by Flex. |
className | string | No | Optional class hook applied to the public root element owned by the component. |
sx | Sx | No | Inherited sx attribute accepted by Flex. |
id | string | No | Inherited id attribute accepted by Flex. |
role | string | No | Inherited role attribute accepted by Flex. |
style | Record<string, unknown> | No | Inherited style attribute accepted by Flex. |
title | string | No | Inherited title attribute accepted by Flex. |
tabIndex | number | No | Inherited tabIndex attribute accepted by Flex. |
hidden | boolean | No | Inherited hidden attribute accepted by Flex. |
disabled | boolean | No | Inherited disabled attribute accepted by Flex. |
onClick | TavoEventHandler<MouseEvent> | No | Inherited onClick attribute accepted by Flex. |
onChange | TavoEventHandler<Event> | No | Inherited onChange attribute accepted by Flex. |
onInput | TavoEventHandler<Event> | No | Inherited onInput attribute accepted by Flex. |
onKeyDown | TavoEventHandler<KeyboardEvent> | No | Inherited onKeyDown attribute accepted by Flex. |
onFocus | TavoEventHandler<FocusEvent> | No | Inherited onFocus attribute accepted by Flex. |
onBlur | TavoEventHandler<FocusEvent> | No | Inherited onBlur attribute accepted by Flex. |
as | PolymorphicAs | No | Changes the rendered root element or component while preserving Tavo.js UI styling and public props. |
direction | ResponsiveValue<FlexDirection> | No | Configures direction for this component. |
align | ResponsiveValue<FlexAlign> | No | Configures align for this component. |
justify | ResponsiveValue<FlexJustify> | No | Configures justify for this component. |
gap | ResponsiveValue<string | number> | No | Configures gap for this component. |
State ownership and DOM target
| Concern | Contract |
|---|---|
| State | No component state contract is exposed; the application owns the rendered content and surrounding behavior. |
| DOM target | The public root follows the as/component prop. Root attributes, className, style, and supported events are forwarded there. |
Anatomy and related components
Limitations
Avoid Flex when for interactive form state; combine with form, feedback, or data components instead.
Use only the documented props, entry points, and compound members. Internal DOM nesting and CSS class names can change without becoming part of the public component contract.
Accessibility
Layout primitives are semantic-neutral unless a component prop selects an element role.
Choose semantic elements such as main, nav, aside, or section when the region has document meaning.
Keep heading order and landmark labels app-owned.
Component status
| Contract | Current value |
|---|---|
| Maturity | stable |
| Category | layout |
| Component import | @tavojs/ui/flex |
| Explicit CSS import | @tavojs/ui/css/flex |
| Preview | Interactive preview available on this page |