Skip to content

Feat/disable prop radio button item #1900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion example/src/Examples/RadioButtonExample.tsx
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import {
useTheme,
} from 'react-native-paper';

type State = 'normal' | 'normal-ios' | 'custom';
type State = 'normal' | 'normal-ios' | 'normal-item' | 'custom';

const RadioButtonExample = () => {
const [checked, setChecked] = React.useState<State>('normal');
@@ -59,6 +59,12 @@ const RadioButtonExample = () => {
</View>
</View>
</TouchableRipple>
<RadioButton.Item
label="Normal 3 - Item"
value="normal-item"
status={checked === 'normal-item' ? 'checked' : 'unchecked'}
onPress={() => setChecked('normal-item')}
/>
<View style={styles.row}>
<Paragraph>Checked (Disabled)</Paragraph>
<RadioButton value="first" status="checked" disabled />
@@ -67,6 +73,18 @@ const RadioButtonExample = () => {
<Paragraph>Unchecked (Disabled)</Paragraph>
<RadioButton value="second" status="unchecked" disabled />
</View>
<RadioButton.Item
label="Checked - Item (Disabled)"
value="third"
status="checked"
disabled
/>
<RadioButton.Item
label="Unchecked - Item (Disabled)"
value="fourth"
status="unchecked"
disabled
/>
</View>
);
};
21 changes: 15 additions & 6 deletions src/components/RadioButton/RadioButtonItem.tsx
Original file line number Diff line number Diff line change
@@ -23,6 +23,10 @@ export type Props = {
* Label to be displayed on the item.
*/
label: string;
/**
* Whether radio is disabled.
*/
disabled?: boolean;
/**
* Function to execute on press.
*/
@@ -98,6 +102,7 @@ class RadioButtonItem extends React.Component<Props> {
style,
labelStyle,
onPress,
disabled,
color,
uncheckedColor,
status,
@@ -109,12 +114,15 @@ class RadioButtonItem extends React.Component<Props> {
{(context?: RadioButtonContextType) => {
return (
<TouchableRipple
onPress={() =>
handlePress({
onPress: onPress,
onValueChange: context?.onValueChange,
value,
})
onPress={
disabled
? undefined
: () =>
handlePress({
onPress: onPress,
onValueChange: context?.onValueChange,
value,
})
}
>
<View style={[styles.container, style]} pointerEvents="none">
@@ -125,6 +133,7 @@ class RadioButtonItem extends React.Component<Props> {
</Text>
<RadioButton
value={value}
disabled={disabled}
status={status}
color={color}
uncheckedColor={uncheckedColor}