@@ -109,14 +109,16 @@ export const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
109
109
return (
110
110
< div
111
111
className = { cn (
112
- "group flex cursor-pointer items-start gap-x-2 transition" ,
112
+ "group flex items-start gap-x-2 transition " ,
113
+ props . readOnly || disabled ? "cursor-default" : "cursor-pointer" ,
113
114
buttonClassName ,
114
115
isChecked && isCheckedClassName ,
115
- isDisabled && isDisabledClassName ,
116
+ ( isDisabled || props . readOnly ) && isDisabledClassName ,
116
117
className
117
118
) }
118
119
onClick = { ( e ) => {
119
- if ( isDisabled ) return ;
120
+ //returning false is not setting the state to false, it stops the event from bubbling up
121
+ if ( isDisabled || props . readOnly === true ) return false ;
120
122
setIsChecked ( ( c ) => ! c ) ;
121
123
} }
122
124
>
@@ -127,12 +129,15 @@ export const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
127
129
value = { value }
128
130
checked = { isChecked }
129
131
onChange = { ( e ) => {
132
+ //returning false is not setting the state to false, it stops the event from bubbling up
133
+ if ( isDisabled || props . readOnly === true ) return false ;
130
134
setIsChecked ( ! isChecked ) ;
131
135
} }
132
136
disabled = { isDisabled }
133
137
className = { cn (
134
138
inputPositionClasses ,
135
- "cursor-pointer rounded-sm border border-slate-700 bg-transparent transition checked:!bg-indigo-500 group-hover:bg-slate-900 group-hover:checked:bg-indigo-500 group-focus:ring-1 focus:ring-indigo-500 focus:ring-offset-0 focus:ring-offset-transparent focus-visible:outline-none focus-visible:ring-indigo-500 disabled:border-slate-650 disabled:!bg-slate-700"
139
+ props . readOnly || disabled ? "cursor-default" : "cursor-pointer" ,
140
+ "rounded-sm border border-slate-700 bg-transparent transition checked:!bg-indigo-500 read-only:border-slate-650 read-only:!bg-slate-700 group-hover:bg-slate-900 group-hover:checked:bg-indigo-500 group-focus:ring-1 focus:ring-indigo-500 focus:ring-offset-0 focus:ring-offset-transparent focus-visible:outline-none focus-visible:ring-indigo-500 disabled:border-slate-650 disabled:!bg-slate-700"
136
141
) }
137
142
id = { id }
138
143
ref = { ref }
@@ -141,7 +146,10 @@ export const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
141
146
< div className = "flex items-center gap-x-2" >
142
147
< label
143
148
htmlFor = { id }
144
- className = { cn ( "cursor-pointer" , labelClassName ) }
149
+ className = { cn (
150
+ props . readOnly || disabled ? "cursor-default" : "cursor-pointer" ,
151
+ labelClassName
152
+ ) }
145
153
onClick = { ( e ) => e . preventDefault ( ) }
146
154
>
147
155
{ label }
0 commit comments