-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
Components using the FormToggle component can use this to supply help text based on the state of the checkbox.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,9 +25,15 @@ class ToggleControl extends Component { | |
} | ||
|
||
render() { | ||
const { label, checked, help, instanceId } = this.props; | ||
const { label, checked, help, checkedHelp, instanceId } = this.props; | ||
const id = `inspector-toggle-control-${ instanceId }`; | ||
|
||
// allow customizing the help text based on checked state | ||
let helpLabel = help; | ||
if ( checkedHelp ) { | ||
helpLabel = checked ? checkedHelp : help; | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jasmussen
Contributor
|
||
|
||
let describedBy; | ||
if ( help ) { | ||
describedBy = id + '__help'; | ||
|
@@ -37,7 +43,7 @@ class ToggleControl extends Component { | |
<BaseControl | ||
label={ label } | ||
id={ id } | ||
help={ help } | ||
help={ helpLabel } | ||
className="components-toggle-control" | ||
> | ||
<FormToggle | ||
|
It's a bit confusing that the
help
prop corresponds to the unchecked state. What if we just switch the value from outside?help={ !! imageCrop ? 'x is checked' : 'x is not checked' }