Skip to content

Carousel - page control hit slop fix a11y #3763

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 3 additions & 4 deletions src/components/checkbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ImageStyle
} from 'react-native';
import {Colors, Spacings} from '../../style';
import {StyleUtils} from '../../utils';
//@ts-ignore
import Assets from '../../assets';
import {asBaseComponent} from '../../commons/new';
Expand Down Expand Up @@ -251,9 +252,7 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
};
};

getAccessibleHitSlop(size: number) {
return Math.max(0, (48 - size) / 2);
}


renderCheckbox() {
const {selectedIcon, label, testID, style, containerStyle, indeterminate, ...others} = this.props;
Expand All @@ -267,7 +266,7 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
{...others}
style={[this.getBorderStyle(), style, !label && containerStyle]}
onPress={this.onPress}
hitSlop={this.getAccessibleHitSlop(this.props.size || DEFAULT_SIZE)}
hitSlop={StyleUtils.getAccessibleHitSlop(this.props.size || DEFAULT_SIZE)}
>
{
<Animated.View
Expand Down
13 changes: 9 additions & 4 deletions src/components/pageControl/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, {PureComponent} from 'react';
import {StyleSheet, LayoutAnimation, StyleProp, ViewStyle} from 'react-native';
import {asBaseComponent} from '../../commons/new';
import {Colors} from '../../style';
import {StyleUtils} from '../../utils';
import TouchableOpacity, {TouchableOpacityProps} from '../touchableOpacity';
import View from '../view';

Expand Down Expand Up @@ -114,14 +115,12 @@ class PageControl extends PureComponent<PageControlProps, State> {

if (Array.isArray(props.size)) {
if (props.size[0] >= props.size[1] || props.size[1] >= props.size[2]) {
console.warn(
'It is recommended that largeSize > mediumSize > smallSize, currently: smallSize=',
console.warn('It is recommended that largeSize > mediumSize > smallSize, currently: smallSize=',
props.size[0],
'mediumSize=',
props.size[1],
'largeSize=',
props.size[2]
);
props.size[2]);
}
}
}
Expand Down Expand Up @@ -190,6 +189,8 @@ class PageControl extends PureComponent<PageControlProps, State> {

renderIndicator(index: number, size: number, enlargeActive?: boolean) {
const {currentPage, color, inactiveColor, onPagePress, spacing = PageControl.DEFAULT_SPACING} = this.props;
const hitSlopValue = StyleUtils.getAccessibleHitSlop(size);

return (
<TouchableOpacity
customValue={index}
Expand All @@ -201,6 +202,10 @@ class PageControl extends PureComponent<PageControlProps, State> {
getColorStyle(index === currentPage, color, inactiveColor),
getSizeStyle(size, index, currentPage, enlargeActive)
]}
hitSlop={{
top: hitSlopValue,
bottom: hitSlopValue
}}
/>
);
}
Expand Down
16 changes: 7 additions & 9 deletions src/components/radioButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ViewStyle
} from 'react-native';
import {Colors} from '../../style';
import {StyleUtils} from '../../utils';
import {asBaseComponent, forwardRef, BaseComponentInjectedProps, ForwardRefInjectedProps} from '../../commons/new';
import TouchableOpacity from '../touchableOpacity';
import View, {ViewProps} from '../view';
Expand Down Expand Up @@ -257,18 +258,12 @@ class RadioButton extends PureComponent<Props, RadioButtonState> {
);
}

getAccessibleHitSlop(size: number) {
const verticalPadding = Math.max(0, (48 - size) / 2);

return {
top: verticalPadding,
bottom: verticalPadding
};
}


render() {
const {onPress, onValueChange, containerStyle, contentOnLeft, ...others} = this.props;
const Container = onPress || onValueChange ? TouchableOpacity : View;
const hitSlopValue = StyleUtils.getAccessibleHitSlop(this.props.size || DEFAULT_SIZE);

return (
// @ts-ignore
Expand All @@ -280,7 +275,10 @@ class RadioButton extends PureComponent<Props, RadioButtonState> {
style={containerStyle}
onPress={this.onPress}
{...this.getAccessibilityProps()}
hitSlop={this.getAccessibleHitSlop(this.props.size || DEFAULT_SIZE)}
hitSlop={{
top: hitSlopValue,
bottom: hitSlopValue
}}
>
{!contentOnLeft && this.renderButton()}
{this.props.iconOnRight ? this.renderLabel() : this.renderIcon()}
Expand Down
4 changes: 4 additions & 0 deletions src/utils/styleUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ export function unpackStyle(style?: StyleProp<ViewStyle>, options: UnpackStyleOp
return JSON.parse(JSON.stringify(options.flatten ? StyleSheet.flatten(style) : style));
}
}

export function getAccessibleHitSlop(size: number) {
return Math.max(0, (48 - size) / 2);
}