A toggle button provides a quick way to see whether a given option is enabled or disabled and to toggle between these states. Place a toggle button to the right of a label, in a table, or below a section describing what is enabled or disabled.
A toggle button should be used if the main intent is to make a binary choice, such as turning something on or off, and the choice is not part of a form.
API status: | general |
---|---|
Included in AUI core? | Not in core You must explicitly require the web resource key. |
Web resource key: |
com.atlassian.auiplugin:aui-toggle
|
AMD Module key: | N/A |
Experimental API: | 5.9 |
General API: | 7.8 |
Web Component API: | 5.9 |
Define a basic toggle button.
The label
attribute is required for a screen reader to announce the button. If you want to have an
actual visible label, use <aui-label>
.
You can set the default checked
and disabled
states directly in the HTML, or
using Javascript to modify the elements' attributes/properties.
Sometimes you need to provide more information relating to the state of a control. This can be achieved using the
tooltip-on
and tooltip-off
attributes.
The busy property can be used to handle asynchronous requests. Bind to the change
event
to trigger an AJAX request and display a spinner when the toggle is pressed:
Attributes and properties can be set and accessed directly on the aui-toggle
element.
Name | Attribute | Property | Type | Description |
---|---|---|---|---|
label required |
String |
Text used by screen readers when announcing the toggle button (required for accessibility). |
||
checked |
Boolean | If set, the toggle will be set to the 'on' state. | ||
disabled |
Boolean | If set, the user will not be able to interact with the toggle. | ||
form |
String |
The HTML5 attribute. Not supported in IE10 or older. |
||
name |
String | The name of the toggle button element, used to reference the element in JavaScript or form data. | ||
value |
String | The value associated with the toggle button element (sent on form submission). | ||
busy |
Boolean |
Sets the toggle to a busy state, displaying the busy spinner. |
||
tooltip-on |
String |
Sets the tooltip text that is shown when the toggle is set to the ‘on’ state. |
||
tooltip-off |
String |
Sets the tooltip text that is shown when the toggle is set to the ‘off’ state. |