Toggle inputs, much like checkbox inputs are used to capture binary choices; they can be used to toggle the state of something on or off. Unlike checkbox inputs however, toggles should be used when the effect of the interaction is immediate, for example, immediately persisting the users selection.
Ez toggle should:
Toggle inputs are used to offer binary choices. Use a toggle input only when the effect of the interaction is immediate.
Add a descriptive label to the right of the toggle input that when interacted with will toggle the state of the input.
When providing a choice that requires an asynchronous action to take affect, it can be beneficial to indicate the progress of the action to the user. Use the optional status
prop to indicate whether the toggled changes have been successfully applied.
The checked
value should always be updated optimistically to reflect the new state and assume the asynchronous action completes successfully. Should the asynchronous action fail to complete, the checked
value will need to be reset accordingly.
The status
prop accepts the following values:
status="progress"
when the change is still in-flight, or confirmation has not yet been received.status="success"
when the change has been successfully applied.status="error"
when the change could not be applied.Use the disabled
prop to prevent users from being able to interact with the toggle input and to convey the inactive state to assistive technologies.
Add a descriptive label to the right of the toggle input that when interacted with will toggle the state of the input.