Skip to content

Checkbox.Item ignores disable prop #3014

@kendallroth

Description

@kendallroth

Current behaviour

Trying to disable Checkbox.Item only tweaks the checkbox style (not label) and does not prevent item presses.

Expected behaviour

Checkbox and label should appear disabled and be non-interactable.

Code sample

<Checkbox.Item
  disabled
  label="Sample"
  status={value ? "checked" : "unchecked"}
/>

What have you tried

Noticed that the CheckboxItem component does not pass disabled on to the TouchableRipple as would be expected, and patched with patch-package.

diff --git a/node_modules/react-native-paper/src/components/Checkbox/CheckboxItem.tsx b/node_modules/react-native-paper/src/components/Checkbox/CheckboxItem.tsx
index 93d5af4..fc28092 100644
--- a/node_modules/react-native-paper/src/components/Checkbox/CheckboxItem.tsx
+++ b/node_modules/react-native-paper/src/components/Checkbox/CheckboxItem.tsx
@@ -87,6 +87,7 @@ type Props = {
  */
 
 const CheckboxItem = ({
+  disabled,
   style,
   status,
   label,
@@ -98,7 +99,7 @@ const CheckboxItem = ({
   position = 'trailing',
   ...props
 }: Props) => {
-  const checkboxProps = { ...props, status, theme };
+  const checkboxProps = { ...props, disabled, status, theme };
   const isLeading = position === 'leading';
   let checkbox;
 
@@ -111,14 +112,14 @@ const CheckboxItem = ({
   }
 
   return (
-    <TouchableRipple onPress={onPress} testID={testID}>
+    <TouchableRipple disabled={disabled} onPress={onPress} testID={testID}>
       <View style={[styles.container, style]} pointerEvents="none">
         {isLeading && checkbox}
         <Text
           style={[
             styles.label,
             {
-              color: theme.colors.text,
+              color: disabled ? theme.colors.disabled : theme.colors.text,
               textAlign: isLeading ? 'right' : 'left',
             },
             labelStyle,

Your Environment

software version
ios or android both
react-native 0.64.3
react-native-paper 4.9.2
node 16.6.0
npm or yarn npm 7.20.6
expo sdk 43

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions