Skip to main content
5.0.3Next5.0.35.0.25.0.15.0.04.0.94.0.84.0.73.2.03.1.03.0.13.0.02.1.12.0.101.0.0
Version: 5.0.3

Switch

Switches let users toggle some setting between two states in the UI. This can be used for creating toggblable settings, e.g. enabling advanced settings, or choosing between day and dusk theme. Switches are only useful when the user can toggle between one of two valid states. Checboxes can, however, be a better alternative than using multiple switches in a list.

Basic Usage

<triton-switch></triton-switch>
<triton-switch checked></triton-switch>
<TritonSwitch></TritonSwitch>
<TritonSwitch checked></TritonSwitch>
<html> 
<head>
<script type="module">
import { defineCustomElements } from '~node_modules/@kognifai/triton-cl-core/loader/index.es2017.js';
defineCustomElements();
</script>
</head>
<body>
<triton-switch></triton-switch>
<triton-switch checked></triton-switch>
</body>
</html>

Appearance

Internal Icons

By using the checked-icon and unchecked-icon properties, you can set custom icons for the switch.

<triton-switch checked-icon="check" unchecked-icon="close"></triton-switch>

Text Inside Switch

By using the checked-text and unchecked-text properties, you can set custom text within the switch depending on its state.

<triton-switch unchecked-text="ABC" checked-icon="DEF"></triton-switch>

Playground

API

Properties

PropertyDescriptionTypeDefault
auto-focusSet focus when component mounted if truebooleanfalse
checkedSet state of the switchbooleanfalse
checked-iconDisplay icon inside the switch when the state is checkedIcon-
checked-textDisplay text inside the switch when the state is checkedstring-
classesAppend custom classes to the switchstring-
disabledDisable the switchbooleanfalse
loadingShow a loading icon when truebooleanfalse
sizeSet the size of the componentbase body large medium small tiny xlarge xxlarge xxxlarge'body'
titleTitle for the label in the switch.string-
unchecked-iconDisplay icon inside the switch when the state is uncheckedIcon-
unchecked-textDisplay text inside the switch when the state is uncheckedstring-

Events

NameTypeDescriptionExtra
atChangeCustomEvent<BooleanChangeEventDetail>Trigger when data has change-

Slots

Main

takes any markup element if there is no title present

<triton-switch>
<div></div>
</triton-switch>

Details

Depends on