We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e609822 commit 7395c1aCopy full SHA for 7395c1a
src/Common/Toggle/Toggle.tsx
@@ -33,12 +33,13 @@ const Toggle = ({
33
shouldToggleValueOnLabelClick = false,
34
isLoading = false,
35
value = CHECKBOX_VALUE.CHECKED,
36
+ isControlled = false,
37
...props
38
}) => {
39
const [active, setActive] = React.useState(selected)
40
41
useEffectAfterMount(() => {
- if (typeof onSelect === 'function') {
42
+ if (typeof onSelect === 'function' && !isControlled) {
43
if (active !== selected) {
44
onSelect(active)
45
}
@@ -51,7 +52,11 @@ const Toggle = ({
51
52
53
function handleClick() {
54
if (!disabled) {
- setActive((active) => !active)
55
+ if (isControlled) {
56
+ onSelect(!active)
57
+ } else {
58
+ setActive((active) => !active)
59
+ }
60
61
62
0 commit comments