Skip to main content

The Toggle Button component for classic apps

Classic apps

You're viewing documentation for classic apps, which use Retool's original app editor. The new app builder is the recommended way to build apps and where Retool focuses new development.

Best practice

For more information about using the Toggle Button component, refer to the buttons and links guide.

Properties​

All properties for this object with supported data types or values. You can write JavaScript almost anywhere in Retool to manipulate or read property values.

ariaLabel​

The accessible label for screen readers.

Type string
Format Plain Text
Configurability Inspector > Content > Accessible name
Defaultnull
Examples
false"Retool logo."

disabled​

Whether input, interaction, selection, or triggering is disabled.

Type boolean
Format True/False
Configurability Inspector > Interaction > Disabled
Defaultfalse
Examples
falsetrue

events​

A list of configured event handlers that trigger actions or queries.

Type array
Array values object
Configurability Inspector > Interaction > Event handlers
Defaultnull
Array Object Properties

event​

The event that triggers the action. Refer to the events section for details of available events for this object.

Type string
Configurability Inspector > Interaction > Event handlers > Event
Defaultnull

method​

The JavaScript method to perform when type is datasource, widget, state, or localStorage.

Type string
Configurability Inspector > Interaction > Event handlers > Edit event handler > Run script actions
Defaultnull

type​

The type of action to perform.

Type string
Configurability Inspector > Interaction > Event handlers > Edit event handler > Action
Allowed Values
ValueDescription
datasource

Control query.

widget

Control component.

script

Run script.

state

Set variable.

localStorage

Set localStorage.

util

Perform utility action (e.g., Open URL or Confetti).

Defaultnull


hidden​

Whether this object is hidden from view.

Type boolean
Format True/False
Configurability Inspector > Appearance > Hidden
Defaultfalse
Examples
falsetrue

horizontalAlign​

The horizontal alignment of the contents.

Type string
Format Plain Text
Configurability Inspector > Appearance > Alignment
Allowed Values
ValueDescription
left

Left alignment.

center

Center alignment.

right

Right alignment.

Defaultleft

iconForFalse​

The icon to display when value is false.

Type string
Format Icon Key
Configurability Inspector > Content > Add-ons > False icon
Default/icon:bold/interface-arrows-button-down
Examples
false/icon:bold/interface-arrows-button-down

iconForTrue​

The icon to display when value is true.

Type string
Format Icon Key
Configurability Inspector > Content > Add-ons > True icon
Default/icon:bold/interface-arrows-button-up
Examples
false/icon:bold/interface-arrows-button-up

id​

The unique identifier (name).

Type string
Format Plain Text
Configurability Inspector
DefaulttoggleButton1
Examples
falsequery1
falsebutton1

isHiddenOnDesktop​

Whether to show or hide this object in the desktop layout.

Type boolean
Format True/False
Configurability Inspector > Appearance > Advanced > Show on desktop
Defaultfalse
Examples
falsetrue

isHiddenOnMobile​

Whether to show or hide this object in the mobile layout.

Type boolean
Format True/False
Configurability Inspector > Appearance > Advanced > Show on mobile
Defaulttrue
Examples
falsetrue

loaderPosition​

The position of the loading indicator if loading is true.

Type string
Configurability Inspector > Interaction > Loader position
Allowed Values
ValueDescription
auto

Position automatically.

replace

Replace the text.

left

Left of text.

right

Right of text.

Defaultauto

loading​

Whether to display a loading indicator.

Type boolean
Format True/False
Configurability Inspector > Interaction > Loading
Defaultfalse
Examples
falsetrue

maintainSpaceWhenHidden​

Whether to take up space on the canvas if hidden is true.

Type boolean
Format True/False
Configurability Inspector > Appearance > Advanced > Maintain space when hidden
Defaultfalse
Examples
falsetrue

margin​

The amount of margin to render outside.

Type string
Format Plain Text
Configurability Inspector > Spacing > Margin
Allowed Values
ValueUI OptionDescription
4px 8pxNormal

Normal margin.

0None

No margin.

Default4px 8px
Examples
false4px 8px

showInEditor​

Whether the component remains visible in the editor if hidden is true.

Type boolean
Format True/False
Configurability Inspector > Appearance > Advanced > Always show in edit mode
Defaultfalse
Examples
falsetrue

style​

Custom style options.

Type object
Configurability Inspector > Appearance > style
Defaultnull

styleVariant​

The style variant to use.

Type string
Format Plain Text
Configurability Inspector > Appearance > Variant
Allowed Values
ValueDescription
solid

Solid style.

outline

Outline style.

Defaultsolid
Examples
falsesolid

Examples
falseSubmit

value​

The current value or the default value.

Type boolean
Format True/False
Configurability Inspector > Content > Default value
Defaultfalse
Examples
falsetrue

Methods​

JavaScript API methods for this object. You can write JavaScript almost anywhere in Retool and use methods to manipulate data and property values.

toggleButton.clearValue()​

Clear the current values.

Definition
toggleButton.clearValue()
Examples

Clear the current value of toggleButton.

toggleButton.clearValue();

toggleButton.resetValue()​

Reset the current value to the default value.

Definition
toggleButton.resetValue()
Examples

Reset the current value of toggleButton.

toggleButton.resetValue();

toggleButton.scrollIntoView()​

Scrolls the canvas or parent container so that the selected component appears in the visible area.

Definition
toggleButton.scrollIntoView(options)
Parameters

options​

The scroll options.

Type object
Object Properties

behavior​

The scroll behavior.

Type string
Allowed Values
ValueDescription
auto

Scroll immediately to the specified position.

smooth

Scroll gradually to the specified position.


block​

The scroll position relative to the component.

Type string
Allowed Values
ValueDescription
nearest

Scrolls only the minimum amount required for the component to appear in the visible area. Scrolling does not occur if the component is already in view.

start

Scrolls to position the component at the top of the visible area.

center

Scrolls to position the component in the middle of the visible area.

end

Scrolls to position the component at the bottom of the visible area.



Examples

Scroll the minimum amount to immediately bring toggleButton into view.

toggleButton.scrollIntoView({behavior: 'auto', block: 'nearest'});

toggleButton.setDisabled()​

Set the disabled value to toggle whether the input field is disabled. Defaults to true without a parameter.

Definition
toggleButton.setDisabled(disabled)
Parameters

disabled​

Whether input, interaction, selection, or triggering is disabled.

Type boolean
Format True/False
Default
false
Examples
true

Examples

Disable toggleButton.

toggleButton.setDisabled(true);

Enable toggleButton.

toggleButton.setDisabled(false);

toggleButton.setHidden()​

Set the hidden value to toggle whether the component is visible. Defaults to true without a parameter.

Definition
toggleButton.setHidden(hidden)
Parameters

hidden​

Whether this object is hidden from view.

Type boolean
Format True/False
Default
false
Examples
true

Examples

Hide toggleButton.

toggleButton.setHidden(true);

Unhide toggleButton.

toggleButton.setHidden(false);

toggleButton.setValue()​

Set the current value.

Definition
toggleButton.setValue(value)
Parameters

value​

The value.

Type string | number | boolean | object | array

Examples

Set the current value of toggleButton to userValue.

toggleButton.setValue(userValue);

toggleButton.toggle()​

Toggle the current value between true and false.

Definition
toggleButton.toggle()
Examples

Toggle the current value of toggleButton.

toggleButton.toggle();

Events​

Events triggered by user interactions. You can configure event handlers in the IDE to trigger queries or other actions in response to events.

EventDescription
ChangeThe value is changed.
FalseThe value is set to false.
TrueThe value is set to true.