Installation
To begin, install the
@flexilla/tabs
package, or skip this if you’ve already installed @flexilla/flexilla
. Structure
Core Elements
-
tabs-container
: Wraps all tab-related elements. Must include thedata-fx-tabs
attribute. -
tabs-list-wrapper
(optional): Wraps thetab-list
. If used, it must include thedata-tabs-list-wrapper
attribute. -
tab-list
: Contains the individualtab-trigger
elements, with the attributedata-tab-list
. -
tabs-panel-container
(optional): Wraps thetab-panel
elements and must include thedata-panels-container
attribute if used. -
tab-trigger
: Each clickable tab link, with the attributesdata-tabs-trigger
anddata-target
(wheredata-target
is theid
of the corresponding tab-panel). -
tab-panel
: The corresponding content for each tab, identified bydata-tab-panel
andid
.
Here is an example of the basic HTML structure:
Example
Component Initialization
After installation, you can initialize the component in your project:
Custom Tab Indicator
You can add a custom indicator to visually highlight the active tab. There are two ways to implement this:
-
Using the
data-attribute
:Add thedata-indicator-class-name
attribute to thetabs-container
: -
Using the options object:You can pass the indicator’s class name through the
indicatorOptions
in the options object:
CSS Requirements
For custom indicators, specific CSS is needed. If you’re using UnoCSS or TailwindCSS with
@flexilla/uno-preset
or @flexilla/tailwind-plugin
, use the pre-built ui-tabs-indicator
class. For pure CSS, add this to your stylesheet: Example
Vertical Orientation
Flexilla Tabs support vertical orientation as well, making it versatile for different layouts.
Attributes
Flexilla uses specific
data-attributes
to handle tab states, allowing easy customization. data-state
The
data-state
attribute helps track the active/inactive states of a tab panel, which can be styled in CSS: -
active
: Marks the open tab panel. -
inactive
: Marks hidden panels.
aria-selected
This attribute is added to each
tab-trigger
, setting its value to true
for the selected tab and false
for others, ensuring accessibility. Adding Keyframe Animations
To add animations when switching between tab panels (instead of simply toggling visibility), use CSS keyframes.
-
Create Keyframes
-
Use It
-
With
data-*
attribute: -
With JavaScript options:
-
Props, Parameters & Options
Parameters
tabs-container
HTMLElement|string
The container element for the tabs. Must be a valid selector or an HTML element.
options
TabsOptions
The options object for configuring tab behavior.
Options
The options object provides flexibility in customizing the Tabs component.
onTabChange
method
Executes when the active tab changes.
Methods
Initialization
Use the
init
static method to initialize tabs easily: Auto Initialization
Auto-initialize all elements with the
data-fx-tabs
attribute or a custom selector: Programmatic Tab Change
You can programmatically switch between tabs using the
changeTab
method: