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

feat(checkbox/radioButton): ensure minimum 48x48 hit target for better accessibility #3518

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
15 changes: 15 additions & 0 deletions src/components/checkbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,22 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
};
};

getAccessibleHitSlop() {
const {size = DEFAULT_SIZE} = this.props;
const verticalPadding = Math.max(0, (48 - size) / 2);
const horizontalPadding = verticalPadding;

return {
top: verticalPadding,
bottom: verticalPadding,
left: horizontalPadding,
right: horizontalPadding
};
}

renderCheckbox() {
const {selectedIcon, label, testID, style, containerStyle, indeterminate, ...others} = this.props;

return (
//@ts-ignore
<TouchableOpacity
Expand All @@ -263,6 +277,7 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
{...others}
style={[this.getBorderStyle(), style, !label && containerStyle]}
onPress={this.onPress}
hitSlop={this.getAccessibleHitSlop()}
>
{
<Animated.View
Expand Down
14 changes: 14 additions & 0 deletions src/components/radioButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,19 @@ class RadioButton extends PureComponent<Props, RadioButtonState> {
);
}

getAccessibleHitSlop() {
const {size = DEFAULT_SIZE} = this.props;
const verticalPadding = Math.max(0, (48 - size) / 2);
const horizontalPadding = verticalPadding;

return {
top: verticalPadding,
bottom: verticalPadding,
left: horizontalPadding,
right: horizontalPadding
};
}

render() {
const {onPress, onValueChange, containerStyle, contentOnLeft, ...others} = this.props;
const Container = onPress || onValueChange ? TouchableOpacity : View;
Expand All @@ -271,6 +284,7 @@ class RadioButton extends PureComponent<Props, RadioButtonState> {
style={containerStyle}
onPress={this.onPress}
{...this.getAccessibilityProps()}
hitSlop={Container === TouchableOpacity ? this.getAccessibleHitSlop() : undefined}
>
{!contentOnLeft && this.renderButton()}
{this.props.iconOnRight ? this.renderLabel() : this.renderIcon()}
Expand Down