Skip to content

Commit

Permalink
Merge pull request #31851 from mkhutornyi/fix-31830
Browse files Browse the repository at this point in the history
revert ref forwarding logic in CheckboxWithLabel

(cherry picked from commit 540bedd)
  • Loading branch information
Julesssss authored and OSBotify committed Nov 28, 2023
1 parent 2144e60 commit 1b0f71a
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/components/CheckboxWithLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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 @@ -53,6 +54,9 @@ 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 @@ -75,10 +79,11 @@ const defaultProps = {
isChecked: false,
value: false,
defaultValue: false,
forwardedRef: () => {},
accessibilityLabel: undefined,
};

const CheckboxWithLabel = React.forwardRef((props, ref) => {
function CheckboxWithLabel(props) {
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 @@ -101,7 +106,7 @@ const CheckboxWithLabel = React.forwardRef((props, ref) => {
label={props.label}
style={[styles.checkboxWithLabelCheckboxStyle]}
hasError={Boolean(props.errorText)}
ref={ref}
ref={props.forwardedRef}
accessibilityLabel={props.accessibilityLabel || props.label}
/>
<PressableWithFeedback
Expand All @@ -121,10 +126,20 @@ const CheckboxWithLabel = React.forwardRef((props, ref) => {
<FormHelpMessage message={props.errorText} />
</View>
);
});
}

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

export default 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;

0 comments on commit 1b0f71a

Please sign in to comment.