aminghadersohi commented on code in PR #44452:
URL: https://github.com/apache/superset/pull/44452#discussion_r4202506952


##########
superset-frontend/src/explore/components/controls/CheckboxControl.tsx:
##########
@@ -50,24 +53,58 @@ const CheckBoxControlWrapper = styled.div`
 export default function CheckboxControl({
   value = false,
   label,
+  disabled = false,
+  disabledReason,
+  resetLabel,
   onChange = () => {},
   ...restProps
 }: CheckboxControlProps): JSX.Element {
+  const explanationId = useId();
+  const generatedCheckboxId = useId();
+  const checkboxId = restProps.name || generatedCheckboxId;
   const handleChange = useCallback((): void => {
-    onChange(!value);
-  }, [onChange, value]);
+    if (!disabled) {
+      onChange(!value);
+    }
+  }, [disabled, onChange, value]);
 
-  const checkbox = <Checkbox onChange={handleChange} checked={!!value} />;
+  const checkbox = (
+    <Checkbox
+      id={checkboxId}
+      onChange={handleChange}
+      checked={!!value}
+      disabled={disabled}
+      aria-describedby={disabled && disabledReason ? explanationId : undefined}
+    />
+  );
+  const explanation = disabled && disabledReason && (
+    <p id={explanationId}>{disabledReason}</p>
+  );
 
   if (label) {
     return (
       <CheckBoxControlWrapper>
         <ControlHeader
           {...restProps}
+          name={checkboxId}
           label={label}
           leftNode={checkbox}
-          onClick={handleChange}
+          onClick={disabled ? undefined : handleChange}

Review Comment:
   Clicking the label text now toggles twice: the span's `onClick` runs, then 
the outer `<label htmlFor>` re-dispatches the click to the input. With real 
state the box flips on and straight back off, which is why your exactly-once 
test fails in `sharded-jest-tests (8)`.
   
   ```suggestion
             onClick={
               disabled
                 ? undefined
                 : (event?: { preventDefault: () => void }) => {
                     // Stop the associated label from toggling the input again.
                     event?.preventDefault();
                     handleChange();
                   }
             }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to