Tailwind Stepper component provides a visually intuitive way to guide users through multi-step processes or forms. Utilizing Tailwind's utility classes, it offers customizable styles for each step, making it easy to indicate progress and navigate between steps.
Manage and interact with KTStepper instances using these static methods of KTStepper JavaScript class.
Method
Description
init()
Automatically initializes KTStepper object for all elements with the data-kt-stepper="true" attribute on page load.
createInstances()
Allows to create KTStepper instances for all elements that have been dynamically added to the DOM but haven't been activated yet.
getInstance(element)
Returns the KTStepper object associated with the given DOM element .
// Initialize all steppersKTStepper.init();// Initialzie pending steppersKTStepper.createInstances();// Get stepper objectconst stepperEl = document.querySelector('#my_stepper');const stepper = KTStepper.getInstance(stepperEl);
Events
KTStepper custom events allows you to register callback functions(event listeners) that will be invoked automatically whenever specific custom events are triggered within the component.
Event
Description
change
This event triggers before a stepper step is changed, allowing actions to be performed prior to the step transition.
changed
This event triggers after a stepper step has changed, providing a hook to execute actions following the step transition.
Defines a Tailwind class applied to hide the stepper contents when they are not active.
data-kt-stepper-number="true"
Specifies an element that for dynamically print step number.
Classes
first
Applied to the stepper root element when current step is first.
last
Applied to the stepper root element when current step is last.
between
Applied to the stepper root element when current step is between.
active
Applied to the stepper active item.
completed
Applied to the stepper completed item.
pending
Applied to the stepper pending item.
kt-stepper-item-active:*
A custom Tailwind variant for the currently active stepper item, highlighting the current step in the process.
kt-stepper-item-completed:*
A custom Tailwind variant for stepper items that have been completed, indicating past steps in the process.
kt-stepper-item-pending:*
A custom Tailwind variant for stepper items that are pending, indicating future steps yet to be reached in the process.
goFirst()
Navigates to the first step in the stepper sequence.
goLast()
Navigates to the last step in the stepper sequence.
goNext()
Moves the stepper to the next step in the sequence.
goBack()
Moves the stepper to the previous step in the sequence.
update()
Updates the stepper layout and state to reflect any changes in the DOM or stepper configuration.
getStep(itemElement)
Returns the step number associated with the specified DOM element object.
getItemElement(step)
Returns the DOM element object associated with the specified step number.
getTotalSteps()
Returns the total number of steps in the stepper sequence.
getItemElements()
Returns an array of all the DOM element objects in the stepper sequence.
getOption(name)
Retrieves the value of a configuration option by name parameter from a KTStepper instance.
getElement()
Retrieves the DOM element linked to a specific KTStepper instance.
on(eventName, handler)
Allows attaching event listeners to the KTStepper custom events using the eventName and eventId string parameters. These events enable programmatic interaction based on user actions or internal state changes of KTStepper. The function returns string as a unique identifier for the registered listener, allowing you to remove it later if needed.
off(eventName, eventId)
Removes an event listener for the eventName and eventId parameters attached with the on method.
dispose()
Removes the KTStepper instance from an element, including any associated data stored on the DOM element.
element
getOrCreateInstance(element)
Returns the existing KTStepper object for the provided DOM element element , or creates a new instance if none exists, then returns the same.