MCPcopy Index your code
hub / github.com/adobe/react-spectrum / useCheckbox

Function useCheckbox

packages/react-aria/src/checkbox/useCheckbox.ts:62–113  ·  view source on GitHub ↗
(
  props: AriaCheckboxProps,
  state: ToggleState,
  inputRef: RefObject<HTMLInputElement | null>
)

Source from the content-addressed store, hash-verified

60 * @param inputRef - A ref for the HTML input element.
61 */
62export function useCheckbox(
63 props: AriaCheckboxProps,
64 state: ToggleState,
65 inputRef: RefObject<HTMLInputElement | null>
66): CheckboxAria {
67 let {
68 labelProps,
69 inputProps,
70 descriptionProps,
71 errorMessageProps,
72 isSelected,
73 isPressed,
74 isDisabled,
75 isReadOnly,
76 isInvalid,
77 validationErrors,
78 validationDetails
79 } = useToggle(props, state, inputRef);
80
81 let {isIndeterminate} = props;
82 useEffect(() => {
83 // indeterminate is a property, but it can only be set via javascript
84 // https://css-tricks.com/indeterminate-checkboxes/
85 if (inputRef.current) {
86 inputRef.current.indeterminate = !!isIndeterminate;
87 }
88 });
89
90 return {
91 labelProps: mergeProps(
92 labelProps,
93 useMemo(
94 () => ({
95 // Prevent label from being focused when mouse down on it.
96 // Note, this does not prevent the input from being focused in the `click` event.
97 onMouseDown: e => e.preventDefault()
98 }),
99 []
100 )
101 ),
102 inputProps,
103 descriptionProps,
104 errorMessageProps,
105 isSelected,
106 isPressed,
107 isDisabled,
108 isReadOnly,
109 isInvalid,
110 validationErrors,
111 validationDetails
112 };
113}

Callers 10

useCheckboxGroupItemFunction · 0.90
CheckboxFunction · 0.90
TableCheckboxCellFunction · 0.90
TableSelectAllCellFunction · 0.90
TableCheckboxCellFunction · 0.90
TableSelectAllCellFunction · 0.90
TableCheckboxCellFunction · 0.90
TableSelectAllCellFunction · 0.90
useCheckboxAriaFunction · 0.90
Checkbox.tsxFile · 0.90

Calls 2

useToggleFunction · 0.90
mergePropsFunction · 0.90

Tested by

no test coverage detected