Icon toggles allow users to take actions and make choices with a single tap.
import Material.IconToggle as IconToggle
type Msg
= Clicked
main =
IconToggle.iconToggle
(IconToggle.config
|> IconToggle.setOn True
|> IconToggle.setOnChange Clicked
)
{ offIcon = "favorite_outlined"
, onIcon = "favorite"
}Specify a message when the user changes the icon toggle
Specify whether an icon toggle is disabled
Disabled icon buttons cannot be interacted with and have no visual interaction effect.
Specify the HTML5 aria-label attribute of an icon toggle
Specify additional attributes
Icon toggles are a variant of icon buttons that change the icon when their state changes.
IconToggle.iconToggle
(IconToggle.config |> IconToggle.setOn True)
{ offIcon = "favorite_border"
, onIcon = "favorite"
}Icon toggle view function
To set an icon toggle to its on state, set its setOn configuration option to
True.
IconToggle.iconToggle
(IconToggle.config |> IconToggle.setOn True)
{ offIcon = "favorite_border"
, onIcon = "favorite"
}To disable an icon toggle, set its setDisabled configuration option to
True.
Disabled icon buttons cannot be interacted with and have no visual interaction
effect.
IconToggle.iconToggle
(IconToggle.config |> IconToggle.setDisabled True)
{ offIcon = "favorite_border"
, onIcon = "favorite"
}To set the HTML5 arial-label attribute of an icon toggle, use its setLabel
configuration option.
IconToggle.iconToggle
(IconToggle.config
|> IconToggle.setLabel (Just "Add to favorites")
)
{ offIcon = "favorite_border"
, onIcon = "favorite"
}You may programatically focus an icon toggle by assigning an id attribute to it
and use Browser.Dom.focus.
IconToggle.iconToggle
(IconToggle.config
|> IconToggle.setAttributes
[ Html.Attributes.id "my-icon-toggle" ]
)
{ offIcon = "favorite_border"
, onIcon = "favorite"
}
Icon toggle configuration