-
Notifications
You must be signed in to change notification settings - Fork 734
feat(checkbox/radioButton): ensure minimum 48x48 hit target for better accessibility #3518
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
Changes from 10 commits
10c3c97
18aca35
29c3852
9ce4651
e3f67db
14921a6
e5e72ff
c7d9235
84eb5b9
d73d48e
f8133df
2a1a3cf
3b19c50
1413792
4d29687
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -252,8 +252,16 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> { | |
}; | ||
}; | ||
|
||
getAccessibleHitSlop() { | ||
const {size = DEFAULT_SIZE} = this.props; | ||
const hitTargetPadding = Math.max(0, (48 - size) / 2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return Math.max(0, (48 - size) / 2); |
||
|
||
return hitTargetPadding; | ||
} | ||
|
||
renderCheckbox() { | ||
const {selectedIcon, label, testID, style, containerStyle, indeterminate, ...others} = this.props; | ||
|
||
return ( | ||
//@ts-ignore | ||
<TouchableOpacity | ||
|
@@ -263,6 +271,7 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> { | |
{...others} | ||
style={[this.getBorderStyle(), style, !label && containerStyle]} | ||
onPress={this.onPress} | ||
hitSlop={this.getAccessibleHitSlop()} | ||
> | ||
{ | ||
<Animated.View | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -257,6 +257,16 @@ class RadioButton extends PureComponent<Props, RadioButtonState> { | |
); | ||
} | ||
|
||
getAccessibleHitSlop() { | ||
const {size = DEFAULT_SIZE} = this.props; | ||
const verticalPadding = Math.max(0, (48 - size) / 2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why only vertical? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Horizontally the |
||
|
||
return { | ||
top: verticalPadding, | ||
bottom: verticalPadding | ||
}; | ||
} | ||
|
||
nitzanyiz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
render() { | ||
const {onPress, onValueChange, containerStyle, contentOnLeft, ...others} = this.props; | ||
const Container = onPress || onValueChange ? TouchableOpacity : View; | ||
|
@@ -271,6 +281,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()} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make it a pure function that gets the size and returns the hitslop