MCPcopy Index your code
hub / github.com/react-bootstrap/react-bootstrap / handleToggle

Function handleToggle

src/ToggleButtonGroup.tsx:96–116  ·  view source on GitHub ↗
(inputVal: any, event: any)

Source from the content-addressed store, hash-verified

94 const getValues: () => any[] = () => (value == null ? [] : [].concat(value));
95
96 const handleToggle = (inputVal: any, event: any) => {
97 if (!onChange) {
98 return;
99 }
100 const values = getValues();
101 const isActive = values.indexOf(inputVal) !== -1;
102
103 if (type === 'radio') {
104 if (!isActive) onChange(inputVal, event);
105 return;
106 }
107
108 if (isActive) {
109 onChange(
110 values.filter((n) => n !== inputVal),
111 event,
112 );
113 } else {
114 onChange([...values, inputVal], event);
115 }
116 };
117
118 invariant(
119 type !== 'radio' || !!name,

Callers 1

handlerFunction · 0.85

Calls 1

getValuesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…