Switch
Switch
Component demo
Interactive example
<ic-switchlabel="Coffee preferences"></ic-switch><script> const switchEl = document.querySelector('ic-switch'); switchEl.addEventListener('icChange', (ev) => { console.log({ checked: ev.detail.checked, value: ev.detail.value }) })</script>
<IcSwitchlabel="Coffee preferences"onIcChange={(ev)=>console.log({ checked: ev.detail.checked, value: ev.detail.value})}/>
Switch details
Props
All components also accept native properties supported by the DOM, such asclassName
and
style
.
|
|
|
---|---|---|
|
The aria-label applied to the switch when no visual 'name' is provided. |
|
|
If |
|
|
If |
|
|
The helper text that will be displayed for additional field guidance. |
|
|
If |
|
|
The name of the control, which is submitted with the form data. |
|
|
If |
|
|
The size of the switch component. |
|
|
|
|
|
The value of the toggle does not mean if it's checked or not, use the |
|
The aria-label applied to the switch when no visual 'name' is provided. |
If |
If |
The helper text that will be displayed for additional field guidance. |
If |
The name of the control, which is submitted with the form data. |
If |
The size of the switch component. |
|
The value of the toggle does not mean if it's checked or not, use the |
Slots
A slot allows for any type of element or markup to be passed into and rendered within a web component. This creates more flexibility than using a prop which must take a specific type of data.
Content can be slotted into a component by adding it as a top-level child of the component.
Slots can have a name to identify them. These specify which slot the content will be inserted into, and therefore where it will be rendered and how it will be used within the component. The name of the slot to be used can be specified by passing it via a
slot
attribute on the slotted content.
|
|
---|---|
|
|
|
Events
All components also accept native events supported by the DOM, such as
onClick
and
onKeyDown
.
|
|
|
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Methods
|
|
|
---|---|---|
|
|
|
|
Variants
State
Interactive example
<ic-switchlabel="Coffee preferences"show-state="true"></ic-switch>
<IcSwitchlabel="Coffee preferences"showState/>
Small
Interactive example
<ic-switchlabel="Coffee preferences"show-state="true"size="small"></ic-switch>
<IcSwitchlabel="Coffee preferences"showStatesize="small"/>
Disabled
Interactive example
<ic-switchlabel="Coffee preferences"show-state="true"disabled="true"></ic-switch><ic-switchlabel="Coffee preferences"show-state="true"disabled="true"checked="true"></ic-switch>
<IcSwitchlabel="Coffee preferences"showStatedisabled/><IcSwitchlabel="Coffee preferences"showStatedisabledchecked/>
Helper text and right adornment
Interactive example
<ic-switchlabel="Coffee preferences"helper-text="Choose your coffee preferences"><svgslot="right-adornment"width="24"height="24"viewBox="0 0 24 24"fill="none"xmlns="http://www.w3.org/2000/svg"><pathd="M2,21H20V19H2M20,8H18V5H20M20,3H4V13A4,4 0 0,0 8,17H14A4,4 0 0,0 18,13V10H20A2,2 0 0,0 22,8V5C22,3.89 21.1,3 20,3Z"/></svg></ic-switch>
<IcSwitchlabel="Coffee preferences"helperText="Choose your coffee preferences"><SlottedSVGslot="right-adornment"width="24"height="24"viewBox="0 0 24 24"fill="none"xmlns="http://www.w3.org/2000/svg"><pathd="M2,21H20V19H2M20,8H18V5H20M20,3H4V13A4,4 0 0,0 8,17H14A4,4 0 0,0 18,13V10H20A2,2 0 0,0 22,8V5C22,3.89 21.1,3 20,3Z"/></SlottedSVG></IcSwitch>