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(button): ensure minimum 48x48 hit target for better accessibility #3520

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/components/button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,19 @@ class Button extends PureComponent<Props, ButtonState> {
return null;
}

getAccessibleHitSlop() {
const containerStyle = this.getContainerSizeStyle();
const minSize = 48;
const padding = Math.max(0, (minSize - (containerStyle.height || 0)) / 2);

return {
top: padding,
bottom: padding,
left: padding,
right: padding
};
}

render() {
const {onPress, disabled, style, testID, animateLayout, modifiers, forwardedRef, ...others} = this.props;
const shadowStyle = this.getShadowStyle();
Expand Down Expand Up @@ -373,6 +386,7 @@ class Button extends PureComponent<Props, ButtonState> {
testID={testID}
{...others}
ref={forwardedRef}
hitSlop={this.getAccessibleHitSlop()}
>
{this.props.children}
{this.props.iconOnRight ? this.renderLabel() : this.renderIcon()}
Expand Down