Switch - Web Component
Browser support
Detected engine:
Chromium
Webkit
Gecko
Parameters
The Web component uses the <z-switch>
tag:
The parametrization of the component can be done with the following custom HTML params:
Name | Type | Description |
---|---|---|
label (optional) | string | Label of the input |
value (optional) | boolean | Value of the model |
checked (optional) | boolean | Overrides the "value" parameter as in the standard |
disabled (optional) | boolean | Blocks the interaction with the input component. |
required (optional) | boolean | Marks the input component as required. |
name (optional) | string | Identification for the field inside the form |
invalid (optional) | boolean | The forced state for set the input as invalid |
The available slots for the component are:
Name | Tags | Description |
---|---|---|
default | span |
label
The z-switch
component accepts a label
attribute to set the text label of the component.
value
& checked
Both value
and checked
parameters are used to set the value of the component.
disabled
The attribute disabled
will block the interaction with the component.
required
The attribute required
will set the component as required.
name
The name
attribute is used to set the name of the component. This is useful when the component is inside a form.
invalid-text
The invalid-text
attribute will set the component as invalid. Without label, the text won't be present but the switch will still be invalid,
Playground
Customization
HTML Examples
Imports
html
<link rel="stylesheet" href="/0.5.0/@zurich/web-components/styles.css" />
<script type="module" src="/0.5.0/@zurich/web-components/switch.js"></script>
Code
html
<!-- Default -->
<z-switch checked></z-switch>
<z-switch checked label="Switch"></z-switch>
<!-- Disabled -->
<z-switch disabled checked></z-switch>
<z-switch disabled checked label="Switch"></z-switch>
<!-- Invalid -->
<z-switch invalid-text="Invalid input" checked></z-switch>
<z-switch invalid-text="Invalid input" checked label="Switch"></z-switch>