Anchor Design System
Form

Toggle3.0

Toggle component is used as an alternative between checked and not checked states.

Installation

npm i @tryg/ui-library

Usage

Individual only imports the desired component, and only needs to be included once within the application. Which is beneficial to keep the application size small.

Webcomponent
<script type="module">
  import { defineCustomElement } from '@tryg/ui-library/dist/components/anchor-toggle';
  defineCustomElement();
</script>
<anchor-toggle>Toggle label</anchor-toggle>

Global only needs to be defined once in the application, but it will import all components even the ones that are not in use..

Webcomponent
<script type="module">
  import { defineCustomElements } from '@tryg/ui-library/dist/loader';
  defineCustomElements();
</script>
<anchor-toggle>Toggle label</anchor-toggle>

Checked

Webcomponent
<anchor-toggle checked>Toggle label</anchor-toggle>

Disabled

Webcomponent
<anchor-toggle disabled>Toggle label</anchor-toggle>

Slots

  • base: Checkbox wrapper, it handles alignment, placement, and general appearance.
  • wrapper: An inner container that includes styles for relative positioning, flex properties, overflow handling and managing hover and selected states.
  • icon: Icon within the checkbox, controlling size, visibility, and changes when checked.
  • label: The text associated with the checkbox.

Accessibility

  • Built with a native HTML <input> element.
  • Full support for browser features like form autofill.
  • Keyboard focus management and cross browser normalization.
  • Keyboard event support for Tab, Enter and Space keys.
  • Labeling support for assistive technology.
  • Indeterminate state support.

API

anchor-toggle

Properties

PropertyAttributeDescriptionTypeDefault
checkedcheckedIf true the toggle will be checkedbooleanfalse
disableddisabledIf true the user cannot interact with the togglebooleanfalse
inputIdinput-idThe id of the input fieldstring`anchor-toggle-${generateGuid()}`
namenameThe name of the control, which is submitted with the form data.stringthis.inputId
requiredrequiredIf true the toggle is marked as requiredbooleanfalse
validityMissingValueTextvalidity-missing-value-textText to be displayed if when value is missing an native form validation is usedstringundefined
valuevalueThe value of the toggle component. It does not control if its checked or not. Use checked for that.string'on'

Events

EventDescriptionType
toggledCustomEvent<ToggleEventDetail>

Methods

toggleInput(event?: any) => Promise<void>

Parameters

NameTypeDescription
eventany

Returns

Type: Promise<void>

Dependencies

Depends on

Graph


Built with StencilJS

Anchor versionStatusNotes
3.0Ready for ImplementationThis component is in sync with Figma.

On this page