Bootstrap 5 Loading Buttons
Loading Buttons
Bootstrap loading buttons are interactive elements that provide visual feedback to users, indicating that an action is being processed. These buttons typically display a loading spinner or animation.
Other frameworks
CoreUI components are available as native Angular, React, and Vue components. To learn more please visit the following pages.
Basic example
Create basic Bootstrap Loading Buttons with different styles: primary, outline, and ghost. These buttons show a loading state when clicked.
<button type="button" class="btn btn-primary" data-coreui-timeout="2000" data-coreui-toggle="loading-button">Submit</button>
<button type="button" class="btn btn-outline-primary" data-coreui-toggle="loading-button">Submit</button>
<button type="button" class="btn btn-ghost-primary" data-coreui-toggle="loading-button">Submit</button>
Spinners
Border
The default option. Use loading buttons with a border spinner to indicate loading status.
<button type="button" class="btn btn-info" data-coreui-toggle="loading-button">Submit</button>
<button type="button" class="btn btn-outline-success" data-coreui-toggle="loading-button">Submit</button>
<button type="button" class="btn btn-ghost-warning" data-coreui-toggle="loading-button">Submit</button>
Grow
Switch to a grow spinner for Bootstrap loading buttons by adding data-coreui-spinner-type="grow"
.
<button type="button" class="btn btn-info" data-coreui-spinner-type="grow" data-coreui-toggle="loading-button">Submit</button>
<button type="button" class="btn btn-outline-success" data-coreui-spinner-type="grow" data-coreui-toggle="loading-button">Submit</button>
<button type="button" class="btn btn-ghost-warning" data-coreui-spinner-type="grow" data-coreui-toggle="loading-button">Submit</button>
Usage
Heads up! In our documentation, all examples show standard CoreUI implementation. If you are using a Bootstrap-compatible version of CoreUI, remember to use the following changes:
- In the constructor, please use bootstrap instead of coreui. For example,
new bootstrap.Alert(...)
instead ofnew coreui.Alert(...)
- In events, please use bs instead of coreui, for example
close.bs.alert
instead ofclose.coreui.alert
- In data attributes, please use bs instead of coreui. For example,
data-bs-toggle="..."
instead ofdata-coreui-toggle="..."
Via data attributes
Add data-coreui-toggle="loading-button"
to a button
element.
<button type="button" class="btn btn-primary" data-coreui-toggle="loading-button">Submit</button>
Via JavaScript
Call the loading button via JavaScript:
<div class="btn btn-primary btn-loading"></div>
const loadingButtonElementList = Array.prototype.slice.call(document.querySelectorAll('.btn-loading'))
const loadingButtonList = loadingButtonElementList.map(loadingButtonEl => {
return new coreui.DatePicker(loadingButtonEl)
})
Options
As options can be passed via data attributes or JavaScript, you can append an option name to data-coreui-
, as in data-coreui-animation="{value}"
. Make sure to change the case type of the option name from “camelCase” to “kebab-case” when passing the options via data attributes. For example, use data-coreui-custom-class="beautifier"
instead of data-coreui-customClass="beautifier"
.
As of CoreUI 4.2.0, all components support an experimental reserved data attribute data-coreui-config
that can house simple component configuration as a JSON string. When an element has data-coreui-config='{"delay":0, "title":123}'
and data-coreui-title="456"
attributes, the final title
value will be 456
and the separate data attributes will override values given on data-coreui-config
. In addition, existing data attributes are able to house JSON values like data-coreui-delay='{"show":0,"hide":150}'
.
Name | Type | Default | Description |
---|---|---|---|
disabledOnLoading |
boolean | false |
Makes button disabled when loading. |
spinnerType |
‘border’, ‘grow’ | 'border' |
Sets type of spinner. |
timeout |
boolean, number | false |
Automatically starts loading animation and stops after a determined amount of milliseconds. |
Methods
Method | Description |
---|---|
start |
Starts loading. |
stop |
Stops loading. |
dispose |
Destroys an element’s loading button. (Removes stored data on the DOM element) |
getInstance |
Static method which allows you to get the multi select instance associated with a DOM element. |
const myBtnLoading = document.getElementById('btn-loading')
const myBtn = new coreui.LoadingButton(myBtnLoading)
myBtn.start()
Events
Loading Button component exposes a few events for hooking into multi select functionality.
Method | Description |
---|---|
start.coreui.loading-button |
Fires immediately when the start method is called. |
stop.coreui.loading-button |
Fires immediately when the stop method is called. |
const myBtnLoading = document.getElementById('myBtnLoading')
myBtnLoading.addEventListener('stop.coreui.loading-button', () => {
// do something...
})