Skip to content

Commit

Permalink
Merge pull request #31801 from mkhutornyi/fix-31795
Browse files Browse the repository at this point in the history
refactor ref forwarding in CheckboxWithLabel
  • Loading branch information
luacmartins authored Nov 23, 2023
2 parents 7a68a3d + 7a99f20 commit 458e270
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions src/components/CheckboxWithLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import variables from '@styles/variables';
import Checkbox from './Checkbox';
import FormHelpMessage from './FormHelpMessage';
import PressableWithFeedback from './Pressable/PressableWithFeedback';
import refPropTypes from './refPropTypes';
import Text from './Text';

/**
Expand Down Expand Up @@ -54,9 +53,6 @@ const propTypes = {
/** The default value for the checkbox */
defaultValue: PropTypes.bool,

/** React ref being forwarded to the Checkbox input */
forwardedRef: refPropTypes,

/** The ID used to uniquely identify the input in a Form */
/* eslint-disable-next-line react/no-unused-prop-types */
inputID: PropTypes.string,
Expand All @@ -79,11 +75,10 @@ const defaultProps = {
isChecked: false,
value: false,
defaultValue: false,
forwardedRef: () => {},
accessibilityLabel: undefined,
};

function CheckboxWithLabel(props) {
const CheckboxWithLabel = React.forwardRef((props, ref) => {
const styles = useThemeStyles();
// We need to pick the first value that is strictly a boolean
// https://github.com/Expensify/App/issues/16885#issuecomment-1520846065
Expand All @@ -106,7 +101,7 @@ function CheckboxWithLabel(props) {
label={props.label}
style={[styles.checkboxWithLabelCheckboxStyle]}
hasError={Boolean(props.errorText)}
forwardedRef={props.forwardedRef}
ref={ref}
accessibilityLabel={props.accessibilityLabel || props.label}
/>
<PressableWithFeedback
Expand All @@ -126,20 +121,10 @@ function CheckboxWithLabel(props) {
<FormHelpMessage message={props.errorText} />
</View>
);
}
});

CheckboxWithLabel.propTypes = propTypes;
CheckboxWithLabel.defaultProps = defaultProps;
CheckboxWithLabel.displayName = 'CheckboxWithLabel';

const CheckboxWithLabelWithRef = React.forwardRef((props, ref) => (
<CheckboxWithLabel
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
forwardedRef={ref}
/>
));

CheckboxWithLabelWithRef.displayName = 'CheckboxWithLabelWithRef';

export default CheckboxWithLabelWithRef;
export default CheckboxWithLabel;

0 comments on commit 458e270

Please sign in to comment.