Skip to content

Commit 75b4b06

Browse files
feat(checkbox/radioButton): ensure minimum 48x48 hit target for better accessibility (#3518)
* feat(checkbox/radioButton): ensure minimum 48x48 hit target for better accessibility --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]>
1 parent 92259ba commit 75b4b06

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

demo/src/screens/componentScreens/CheckboxScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default class CheckboxScreen extends Component {
8989
disabled
9090
value={this.state.value5}
9191
onValueChange={value5 => this.setState({value5})}
92-
style={{marginRight: 10}}
92+
style={{marginRight: 20}}
9393
/>
9494
<Checkbox
9595
disabled

demo/src/screens/componentScreens/RadioButtonScreen.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export default class RadioButtonScreen extends Component {
6969
Radio Buttons
7070
</Text>
7171

72-
<RadioGroup initialValue={this.state.color || null} onValueChange={value => this.setState({color: value})}>
72+
<RadioGroup gap-s4 initialValue={this.state.color || null} onValueChange={value => this.setState({color: value})}>
7373
<Text marginB-20 text60 $textDefault>
7474
Select a color{'\n'}
7575
(enum with default value)
@@ -82,6 +82,7 @@ export default class RadioButtonScreen extends Component {
8282
</RadioGroup>
8383

8484
<RadioGroup
85+
gap-s4
8586
marginT-30
8687
initialValue={this.state.textSide}
8788
onValueChange={value => this.setState({textSide: value})}
@@ -96,7 +97,7 @@ export default class RadioButtonScreen extends Component {
9697
<Text marginT-10>You chose: {this.state.textSide}</Text>
9798
</RadioGroup>
9899

99-
<RadioGroup marginT-30 initialValue={this.state.value} onValueChange={value => this.setState({value})}>
100+
<RadioGroup gap-s4 marginT-30 initialValue={this.state.value} onValueChange={value => this.setState({value})}>
100101
<Text marginB-20 text60 $textDefault>
101102
Yes or No?
102103
</Text>
@@ -112,6 +113,7 @@ export default class RadioButtonScreen extends Component {
112113
</Text>
113114
<View row centerV marginB-10>
114115
<RadioButton
116+
gap-s4
115117
selected={this.state.individualValue2}
116118
onPress={() => this.setState({individualValue2: !this.state.individualValue2})}
117119
label="Individual Radio Button (with style)"

src/components/checkbox/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,13 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
252252
};
253253
};
254254

255+
getAccessibleHitSlop(size: number) {
256+
return Math.max(0, (48 - size) / 2);
257+
}
258+
255259
renderCheckbox() {
256260
const {selectedIcon, label, testID, style, containerStyle, indeterminate, ...others} = this.props;
261+
257262
return (
258263
//@ts-ignore
259264
<TouchableOpacity
@@ -263,6 +268,7 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
263268
{...others}
264269
style={[this.getBorderStyle(), style, !label && containerStyle]}
265270
onPress={this.onPress}
271+
hitSlop={this.getAccessibleHitSlop(this.props.size || DEFAULT_SIZE)}
266272
>
267273
{
268274
<Animated.View

src/components/radioButton/index.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,15 @@ class RadioButton extends PureComponent<Props, RadioButtonState> {
257257
);
258258
}
259259

260+
getAccessibleHitSlop(size: number) {
261+
const verticalPadding = Math.max(0, (48 - size) / 2);
262+
263+
return {
264+
top: verticalPadding,
265+
bottom: verticalPadding
266+
};
267+
}
268+
260269
render() {
261270
const {onPress, onValueChange, containerStyle, contentOnLeft, ...others} = this.props;
262271
const Container = onPress || onValueChange ? TouchableOpacity : View;
@@ -271,6 +280,7 @@ class RadioButton extends PureComponent<Props, RadioButtonState> {
271280
style={containerStyle}
272281
onPress={this.onPress}
273282
{...this.getAccessibilityProps()}
283+
hitSlop={this.getAccessibleHitSlop(this.props.size || DEFAULT_SIZE)}
274284
>
275285
{!contentOnLeft && this.renderButton()}
276286
{this.props.iconOnRight ? this.renderLabel() : this.renderIcon()}

0 commit comments

Comments
 (0)