Toggle button
Toggle button
Component demo
Interactive example
<ic-toggle-buttonid="toggle-btn"label="Switch to oat milk"></ic-toggle-button>
<IcToggleButtonlabel="Switch to oat milk"onIcToggleChecked={(event)=>console.log(event.detail.checked)}/>
Toggle button details
Props
All components also accept native properties supported by the DOM, such asclassName
and
style
.
|
|
|
---|---|---|
|
The accessible label that will be applied to the toggle button. This is required for the icon variant of toggle buttons. |
|
|
The appearance of the toggle button. |
|
|
If |
|
|
If |
|
|
The placement of the icon in relation to the toggle button label. |
|
|
The label to display in the toggle button. This is required for the default variant of toggle buttons. |
|
|
If |
|
|
The size of the toggle button to be displayed. |
|
|
If |
|
|
The variant of the toggle button. |
|
The accessible label that will be applied to the toggle button. This is required for the icon variant of toggle buttons. |
The appearance of the toggle button. |
If |
If |
The placement of the icon in relation to the toggle button label. |
The label to display in the toggle button. This is required for the default variant of toggle buttons. |
If |
The size of the toggle button to be displayed. |
If |
The variant of the toggle button. |
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
.
|
|
|
---|---|---|
|
|
|
|
Toggle button group details
Props
All components also accept native properties supported by the DOM, such asclassName
and
style
.
|
|
|
---|---|---|
|
The accessible label of the toggle button group component to provide context for screen reader users. |
|
|
The appearance of the toggle button group, e.g dark, or light. |
|
|
If |
|
|
If |
|
|
The placement of the icons in relation to the toggle button labels. |
|
|
If |
|
|
If |
|
|
Sets whether single or multiple options can be toggled. If |
|
|
The size of the toggle buttons to be displayed. This does not affect the font size of the accessible label. |
|
|
The variant of the toggle button. |
|
The accessible label of the toggle button group component to provide context for screen reader users. |
The appearance of the toggle button group, e.g dark, or light. |
If |
If |
The placement of the icons in relation to the toggle button labels. |
If |
If |
Sets whether single or multiple options can be toggled. If |
The size of the toggle buttons to be displayed. This does not affect the font size of the accessible label. |
The variant of the toggle button. |
Events
All components also accept native events supported by the DOM, such as
onClick
and
onKeyDown
.
|
|
|
---|---|---|
|
|
|
|
Variants
Other states
Interactive example
<ic-toggle-buttonlabel="Switch to oat milk"disabled="true"></ic-toggle-button><ic-toggle-buttonlabel="Switch to oat milk"disabled="true"toggle-checked="true"></ic-toggle-button><ic-toggle-buttonlabel="Switch to oat milk"loading="true"></ic-toggle-button><ic-toggle-buttonlabel="Switch to oat milk"loading="true"toggle-checked="true"></ic-toggle-button>
<IcToggleButtonlabel="Switch to oat milk"disabled/><IcToggleButtonlabel="Switch to oat milk"disabledtoggleChecked/><IcToggleButtonlabel="Switch to oat milk"loading/><IcToggleButtonlabel="Switch to oat milk"loadingtoggleChecked/>
With icon
Interactive example
<ic-toggle-buttonlabel="Switch to oat milk"><svgslot="icon"xmlns="http://www.w3.org/2000/svg"viewBox="0 0 24 24"><pathd="M2,21V19H20V21H2M20,8V5H18V8H20M20,3A2,2 0 0,1 22,5V8A2,2 0 0,1 20,10H18V13A4,4 0 0,1 14,17H8A4,4 0 0,1 4,13V3H20M16,5H6V13A2,2 0 0,0 8,15H14A2,2 0 0,0 16,13V5Z"/></svg></ic-toggle-button>
<IcToggleButtonlabel="Switch to oat milk"><SlottedSVGslot="icon"xmlns="http://www.w3.org/2000/svg"height="24"viewBox="0 0 24 24"width="24"fill="#000000"><pathd="M2,21V19H20V21H2M20,8V5H18V8H20M20,3A2,2 0 0,1 22,5V8A2,2 0 0,1 20,10H18V13A4,4 0 0,1 14,17H8A4,4 0 0,1 4,13V3H20M16,5H6V13A2,2 0 0,0 8,15H14A2,2 0 0,0 16,13V5Z"/></SlottedSVG></IcToggleButton>
Sizing
Interactive example
<ic-toggle-buttonlabel="Switch to oat milk"size="small"></ic-toggle-button><ic-toggle-buttonlabel="Switch to oat milk"></ic-toggle-button><ic-toggle-buttonlabel="Switch to oat milk"size="large"></ic-toggle-button>
<IcToggleButtonlabel="Switch to oat milk"size="small"/><IcToggleButtonlabel="Switch to oat milk"size="default"/><IcToggleButtonlabel="Switch to oat milk"size="large"/>
With badge
Interactive example
<ic-toggle-buttonlabel="Switch to oat milk"><ic-badgetext-label="1"slot="badge"variant="success"></ic-badge></ic-toggle-button>
<IcToggleButtonlabel="Switch to oat milk"><IcBadgetextLabel="1"slot="badge"variant="success"/></IcToggleButton>
Dark
Interactive example
<ic-toggle-buttonlabel="Switch to oat milk"appearance="dark"></ic-toggle-button><ic-toggle-buttonlabel="Switch to oat milk"appearance="dark"loading="true"></ic-toggle-button><ic-toggle-buttonlabel="Switch to oat milk"appearance="dark"loading="true"toggle-checked="true"></ic-toggle-button>
<IcToggleButtonlabel="Switch to oat milk"appearance="dark"/><IcToggleButtonlabel="Switch to oat milk"appearance="dark"loading/><IcToggleButtonlabel="Switch to oat milk"appearance="dark"loadingtoggleChecked/>
Light
Interactive example
<ic-toggle-buttonlabel="Switch to oat milk"appearance="light"></ic-toggle-button><ic-toggle-buttonlabel="Switch to oat milk"appearance="light"loading="true"></ic-toggle-button><ic-toggle-buttonlabel="Switch to oat milk"appearance="light"loading="true"toggle-checked="true"></ic-toggle-button>
<IcToggleButtonlabel="Switch to oat milk"appearance="light"/><IcToggleButtonlabel="Switch to oat milk"appearance="light"loading/><IcToggleButtonlabel="Switch to oat milk"appearance="light"loadingtoggleChecked/>
Full width
Interactive example
<ic-toggle-button-groupaccessible-label="Alternatives to milk selection"full-width="true"select-type="single"><ic-toggle-buttonlabel="Switch to oat milk"></ic-toggle-button><ic-toggle-buttonlabel="Switch to almond milk"></ic-toggle-button><ic-toggle-buttonlabel="Switch to coconut milk"></ic-toggle-button><ic-toggle-buttonlabel="Switch to rice milk"></ic-toggle-button></ic-toggle-button-group>
<IcToggleButtonGroupaccessibleLabel="Alternatives to milk selection"fullWidthselectType="single"><IcToggleButtonlabel="Switch to oat milk"/><IcToggleButtonlabel="Switch to almond milk"/><IcToggleButtonlabel="Switch to coconut milk"/><IcToggleButtonlabel="Switch to rice milk"/></IcToggleButtonGroup>
Icon only
Interactive example
<ic-toggle-button-groupaccessible-label="Coffee icon variants"variant="icon"><ic-toggle-buttonaccessible-label="Coffee icon"variant="icon"><svgxmlns="http://www.w3.org/2000/svg"height="24"viewBox="0 0 24 24"width="24"fill="#000000"><pathd="M2,21V19H20V21H2M20,8V5H18V8H20M20,3A2,2 0 0,1 22,5V8A2,2 0 0,1 20,10H18V13A4,4 0 0,1 14,17H8A4,4 0 0,1 4,13V3H20M16,5H6V13A2,2 0 0,0 8,15H14A2,2 0 0,0 16,13V5Z"/></svg></ic-toggle-button><ic-toggle-buttonaccessible-label="Loading coffee"variant="icon"loading="true"><svgxmlns="http://www.w3.org/2000/svg"height="24"viewBox="0 0 24 24"width="24"fill="#000000"><pathd="M2,21V19H20V21H2M20,8V5H18V8H20M20,3A2,2 0 0,1 22,5V8A2,2 0 0,1 20,10H18V13A4,4 0 0,1 14,17H8A4,4 0 0,1 4,13V3H20M16,5H6V13A2,2 0 0,0 8,15H14A2,2 0 0,0 16,13V5Z"/></svg></ic-toggle-button><ic-toggle-buttonaccessible-label="Disabled coffee"variant="icon"disabled="true"><svgxmlns="http://www.w3.org/2000/svg"height="24"viewBox="0 0 24 24"width="24"fill="#000000"><pathd="M2,21V19H20V21H2M20,8V5H18V8H20M20,3A2,2 0 0,1 22,5V8A2,2 0 0,1 20,10H18V13A4,4 0 0,1 14,17H8A4,4 0 0,1 4,13V3H20M16,5H6V13A2,2 0 0,0 8,15H14A2,2 0 0,0 16,13V5Z"/></svg></ic-toggle-button></ic-toggle-button-group>
<IcToggleButtonGroupaccessibleLabel="Coffee icon variants"variant="icon"><IcToggleButtonvariant="icon"accessibleLabel="Coffee icon"><SlottedSVGxmlns="http://www.w3.org/2000/svg"height="24"viewBox="0 0 24 24"width="24"fill="#000000"><pathd="M2,21V19H20V21H2M20,8V5H18V8H20M20,3A2,2 0 0,1 22,5V8A2,2 0 0,1 20,10H18V13A4,4 0 0,1 14,17H8A4,4 0 0,1 4,13V3H20M16,5H6V13A2,2 0 0,0 8,15H14A2,2 0 0,0 16,13V5Z"/></SlottedSVG></IcToggleButton><IcToggleButtonvariant="icon"accessibleLabel="Loading coffee"loading><SlottedSVGxmlns="http://www.w3.org/2000/svg"height="24"viewBox="0 0 24 24"width="24"fill="#000000"><pathd="M2,21V19H20V21H2M20,8V5H18V8H20M20,3A2,2 0 0,1 22,5V8A2,2 0 0,1 20,10H18V13A4,4 0 0,1 14,17H8A4,4 0 0,1 4,13V3H20M16,5H6V13A2,2 0 0,0 8,15H14A2,2 0 0,0 16,13V5Z"/></SlottedSVG></IcToggleButton><IcToggleButtonvariant="icon"accessibleLabel="Disabled coffee"disabled><SlottedSVGxmlns="http://www.w3.org/2000/svg"height="24"viewBox="0 0 24 24"width="24"fill="#000000"><pathd="M2,21V19H20V21H2M20,8V5H18V8H20M20,3A2,2 0 0,1 22,5V8A2,2 0 0,1 20,10H18V13A4,4 0 0,1 14,17H8A4,4 0 0,1 4,13V3H20M16,5H6V13A2,2 0 0,0 8,15H14A2,2 0 0,0 16,13V5Z"/></SlottedSVG></IcToggleButton></IcToggleButtonGroup>
Icon right
Interactive example
<ic-toggle-button-groupaccessible-label="Alternatives to milk selection"icon-placement="right"><ic-toggle-buttonlabel="Switch to oat milk"><svgslot="icon"xmlns="http://www.w3.org/2000/svg"height="24"viewBox="0 0 24 24"width="24"fill="#000000"><pathd="M2,21V19H20V21H2M20,8V5H18V8H20M20,3A2,2 0 0,1 22,5V8A2,2 0 0,1 20,10H18V13A4,4 0 0,1 14,17H8A4,4 0 0,1 4,13V3H20M16,5H6V13A2,2 0 0,0 8,15H14A2,2 0 0,0 16,13V5Z"/></svg></ic-toggle-button><ic-toggle-buttonlabel="Switch to almond milk"><svgslot="icon"xmlns="http://www.w3.org/2000/svg"height="24"viewBox="0 0 24 24"width="24"fill="#000000"><pathd="M2,21V19H20V21H2M20,8V5H18V8H20M20,3A2,2 0 0,1 22,5V8A2,2 0 0,1 20,10H18V13A4,4 0 0,1 14,17H8A4,4 0 0,1 4,13V3H20M16,5H6V13A2,2 0 0,0 8,15H14A2,2 0 0,0 16,13V5Z"/></svg></ic-toggle-button></ic-toggle-button-group>
<IcToggleButtonGroupaccessibleLabel="Alternatives to milk selection"iconPlacement="right"><IcToggleButtonlabel="Switch to oat milk"iconPlacement="right"><SlottedSVGslot="icon"xmlns="http://www.w3.org/2000/svg"height="24"viewBox="0 0 24 24"width="24"fill="#000000"><pathd="M2,21V19H20V21H2M20,8V5H18V8H20M20,3A2,2 0 0,1 22,5V8A2,2 0 0,1 20,10H18V13A4,4 0 0,1 14,17H8A4,4 0 0,1 4,13V3H20M16,5H6V13A2,2 0 0,0 8,15H14A2,2 0 0,0 16,13V5Z"/></SlottedSVG></IcToggleButton><IcToggleButtonlabel="Switch to almond milk"iconPlacement="right"><SlottedSVGslot="icon"xmlns="http://www.w3.org/2000/svg"height="24"viewBox="0 0 24 24"width="24"fill="#000000"><pathd="M2,21V19H20V21H2M20,8V5H18V8H20M20,3A2,2 0 0,1 22,5V8A2,2 0 0,1 20,10H18V13A4,4 0 0,1 14,17H8A4,4 0 0,1 4,13V3H20M16,5H6V13A2,2 0 0,0 8,15H14A2,2 0 0,0 16,13V5Z"/></SlottedSVG></IcToggleButton></IcToggleButtonGroup>
Icon top
Interactive example
<ic-toggle-button-groupaccessible-label="Alternatives to milk selection"icon-placement="top"><ic-toggle-buttonlabel="Switch to oat milk"><svgslot="icon"xmlns="http://www.w3.org/2000/svg"height="24"viewBox="0 0 24 24"width="24"fill="#000000"><pathd="M2,21V19H20V21H2M20,8V5H18V8H20M20,3A2,2 0 0,1 22,5V8A2,2 0 0,1 20,10H18V13A4,4 0 0,1 14,17H8A4,4 0 0,1 4,13V3H20M16,5H6V13A2,2 0 0,0 8,15H14A2,2 0 0,0 16,13V5Z"/></svg></ic-toggle-button><ic-toggle-buttonlabel="Switch to almond milk"><svgslot="icon"xmlns="http://www.w3.org/2000/svg"height="24"viewBox="0 0 24 24"width="24"fill="#000000"><pathd="M2,21V19H20V21H2M20,8V5H18V8H20M20,3A2,2 0 0,1 22,5V8A2,2 0 0,1 20,10H18V13A4,4 0 0,1 14,17H8A4,4 0 0,1 4,13V3H20M16,5H6V13A2,2 0 0,0 8,15H14A2,2 0 0,0 16,13V5Z"/></svg></ic-toggle-button></ic-toggle-button-group>
<IcToggleButtonGroupaccessibleLabel="Alternatives to milk selection"iconPlacement="top"><IcToggleButtonlabel="First toggle"iconPlacement="top"><SlottedSVGslot="icon"xmlns="http://www.w3.org/2000/svg"height="24"viewBox="0 0 24 24"width="24"fill="#000000"><pathd="M0 0h24v24H0V0z"fill="none"/><pathd="M17.65 6.35C16.2 4.9 14.21 4 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08c-.82 2.33-3.04 4-5.65 4-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z"/></SlottedSVG></IcToggleButton><IcToggleButtonlabel="Second toggle"iconPlacement="top"><SlottedSVGslot="icon"xmlns="http://www.w3.org/2000/svg"height="24"viewBox="0 0 24 24"width="24"fill="#000000"><pathd="M0 0h24v24H0V0z"fill="none"/><pathd="M17.65 6.35C16.2 4.9 14.21 4 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08c-.82 2.33-3.04 4-5.65 4-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z"/></SlottedSVG></IcToggleButton></IcToggleButtonGroup>