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

17051 - migrated Checkbox to PressableWithFeedback #20257

Merged
merged 11 commits into from
Jun 29, 2023
13 changes: 10 additions & 3 deletions src/components/Checkbox.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
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 themeColors from '../styles/themes/default';
import stylePropTypes from '../styles/stylePropTypes';
import Icon from './Icon';
import * as Expensicons from './Icon/Expensicons';
import PressableWithFeedback from './Pressable/PressableWithFeedback';

const propTypes = {
/** Whether checkbox is checked */
Expand Down Expand Up @@ -34,6 +35,9 @@ const propTypes = {

/** A ref to forward to the Pressable */
forwardedRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({current: PropTypes.instanceOf(React.Component)})]),

/** A ref to forward to the Pressable */
Copy link
Contributor

Choose a reason for hiding this comment

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

@Skalakid Wrong type comment here. Could you update this?

accessibilityLabel: PropTypes.string,
};

const defaultProps = {
Expand All @@ -45,6 +49,7 @@ const defaultProps = {
forwardedRef: undefined,
children: null,
onMouseDown: undefined,
accessibilityLabel: '',
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
};

function Checkbox(props) {
Expand All @@ -67,7 +72,7 @@ function Checkbox(props) {
};

return (
<Pressable
<PressableWithFeedback
disabled={props.disabled}
Copy link
Contributor

Choose a reason for hiding this comment

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

👋 Just a heads-up that this has caused a small regression in #22413
BaseGenericPressable didn't have the logic to disable onKeyDown handler when disabled prop is true
We resolved this by adding the following condition

onKeyDown={!isDisabled ? onKeyDown : undefined}

onPress={firePressHandlerOnClick}
onMouseDown={props.onMouseDown}
Expand All @@ -76,6 +81,8 @@ function Checkbox(props) {
onKeyDown={handleSpaceKey}
accessibilityRole="checkbox"
accessibilityState={{checked: props.isChecked}}
accessibilityLabel={props.accessibilityLabel}
pressDimmingValue={1}
>
{props.children ? (
props.children
Expand All @@ -100,7 +107,7 @@ function Checkbox(props) {
)}
</View>
)}
</Pressable>
</PressableWithFeedback>
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/TextInput/BaseTextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ class BaseTextInput extends Component {
/>
{Boolean(this.props.secureTextEntry) && (
<Checkbox
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
style={styles.textInputIconContainer}
style={[styles.flex1, styles.textInputIconContainer]}
onPress={this.togglePasswordVisibility}
onMouseDown={(e) => e.preventDefault()}
>
Expand Down