For the complete documentation index, see llms.txt. This page is also available as Markdown.

Loading States

Show your users loading spinners, modals, and more as they wait for requests to complete.

Actions may involve a long-running process (such as completing a cart checkout) and HTML may not re-render instantly. You can help your users during the wait using Loading States. Loading States allow you to show/hide elements, add/remove classes, or toggle HTML attributes until the server responds.

Toggling Elements

Let's look at an action that takes too long.

<cfscript>
    function addTask(){
        sleep( 5000 ); // Optimize this code yo!
    }
</cfscript>

We can annotate our <div> with wire:loading to display Adding Task while the checkout action is running.

<cfoutput>
    <div>
        <button wire:click="addTask">Add Task</button>
    
        <div wire:loading>
            Adding Task...
        </div>
    </div>
</cfoutput>

<cfscript>
    function addTask(){
        sleep( 5000 ); // Optimize this code yo!
    }
</cfscript>

After the action completes, the Adding Task... output will disappear. 👋

Toggling Attributes

Targeting Specific Actions

You can target a specific action so that the element is only visible if a specific action is loading using wire:target.

Delaying

If you want to avoid flickering because loading is very fast, you can add a .delay modifier, and it will only show up if loading takes longer than 200ms.

If you wish, you can customize the delay duration with the following modifiers:

Display Property

Loading State elements are set with a CSS property of display: inline-block; by default. You can override this behavior by using various directive modifiers.

Hiding

If you want to display an element except during a loading state, you can apply the wire:loading.remove directive.

Last updated