Skip to content
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

17049 - migrate RadioButton to PressableWithFeedback #20250

Merged
merged 2 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
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
14 changes: 11 additions & 3 deletions src/components/RadioButton.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';
import {View, Pressable} from 'react-native';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import styles from '../styles/styles';
import Icon from './Icon';
import * as Expensicons from './Icon/Expensicons';
import PressableWithFeedback from './Pressable/PressableWithFeedback';

const propTypes = {
/** Whether radioButton is checked */
Expand All @@ -12,6 +13,9 @@ const propTypes = {
/** A function that is called when the box/label is pressed */
onPress: PropTypes.func.isRequired,

/** Specifies the accessibility label for the radio button */
accessibilityLabel: PropTypes.string.isRequired,

/** Should the input be styled for errors */
hasError: PropTypes.bool,

Expand All @@ -25,9 +29,13 @@ const defaultProps = {
};

const RadioButton = (props) => (
<Pressable
<PressableWithFeedback
disabled={props.disabled}
onPress={props.onPress}
hoverDimmingValue={1}
pressDimmingValue={1}
accessibilityLabel={props.accessibilityLabel}
accessibilityRole="radio"
Copy link
Contributor

@luacmartins luacmartins Jun 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should create a CONST for "radio"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will be added in #20251, so we can put this PR on hold until CONST values will be available

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, that seems fine. We could also add it in this PR in case it's merged first.

>
<View style={[styles.radioButtonContainer, props.isChecked && styles.checkedContainer, props.hasError && styles.borderColorDanger, props.disabled && styles.cursorDisabled]}>
<Icon
Expand All @@ -37,7 +45,7 @@ const RadioButton = (props) => (
width={14}
/>
</View>
</Pressable>
</PressableWithFeedback>
);

RadioButton.propTypes = propTypes;
Expand Down
2 changes: 1 addition & 1 deletion src/components/RadioButtonWithLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const RadioButtonWithLabel = (props) => {
<RadioButton
isChecked={props.isChecked}
onPress={props.onPress}
label={props.label}
accessibilityLabel={props.label}
hasError={props.hasError}
/>
<PressableWithFeedback
Expand Down
3 changes: 2 additions & 1 deletion src/components/RadioButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ class RadioButtons extends React.Component {
render() {
return (
<View>
{_.map(this.props.items, (item) => (
{_.map(this.props.items, (item, index) => (
<RadioButtonWithLabel
key={`${item.label}-${index}`}
isChecked={item.value === this.state.checkedValue}
style={[styles.mt4]}
onPress={() => {
Expand Down