-
Notifications
You must be signed in to change notification settings - Fork 734
Chip - Increased hit slop for accessibility #3746
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
Conversation
…etContainerSize logic. Added useMemo for hitSlop to enhance performance.
src/components/chip/index.tsx
Outdated
const height = ('height' in containerSize ? containerSize.height : containerSize?.minHeight) ?? 0; | ||
const width = containerSize?.width ?? 48; | ||
return { | ||
top: Math.max(0, (48 - height) / 2), |
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.
You can calc each once
src/components/chip/index.tsx
Outdated
: {[width]: size, [height]: size}; | ||
const width = typeof size === 'object' ? _.get(size, 'width') : size; | ||
const height = typeof size === 'object' ? _.get(size, 'height') : size; | ||
return useSizeAsMinimum ? {minWidth: width, minHeight: height} : {width, height}; |
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 separate the return to a different method so getContainerSize will only return the size, i.e. height and width so you can use it in the hitSlop calc and wont have to extract it from the style object.
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.
Not sure I understand. To something like this?
const chipSize = useMemo(() => {
const width = typeof size === 'object' ? _.get(size, 'width') : size;
const height = typeof size === 'object' ? _.get(size, 'height') : size;
return {width, height};
}, [size]);
const containerSizeStyle = useMemo(() => {
const {width, height} = chipSize;
return useSizeAsMinimum ? {minWidth: width, minHeight: height} : {width, height};
}, [chipSize]);
const Container = onPress ? TouchableOpacity : View;
const hitSlop = useMemo(() => {
const {width = 48, height = 48} = chipSize;
const verticalHitSlop = Math.max(0, (48 - height) / 2);
const horizontalHitSlop = Math.max(0, (48 - width) / 2);
return {
top: verticalHitSlop,
bottom: verticalHitSlop,
left: horizontalHitSlop,
right: horizontalHitSlop
};
}, [chipSize]);
return (
<Container
activeOpacity={1}
onPress={onPress}
style={[styles.container, {backgroundColor}, {borderRadius}, containerStyle, containerSizeStyle]}
.
.
.
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.
Yes
src/components/chip/index.tsx
Outdated
return ( | ||
<Container | ||
activeOpacity={1} | ||
onPress={onPress} | ||
style={[styles.container, {backgroundColor}, {borderRadius}, containerStyle, getContainerSize()]} | ||
testID={testID} | ||
hitSlop={onPress ? hitSlop : undefined} |
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.
Why do we care if the View gets the hitSlop as well?
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 guess I can pass it...
src/components/chip/index.tsx
Outdated
? {[width]: _.get(size, 'width'), [height]: _.get(size, 'height')} | ||
: {[width]: size, [height]: size}; | ||
const chipSize = useMemo(() => { | ||
const width = typeof size === 'object' ? _.get(size, 'width') : size; |
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.
Let's get rid of the _.get
Description
Increased chip hit slop to fix 48x48 hit target.
Changelog
Chips - Increased chip hit slop to hit 48x48 hit target for accessibility
Additional info
N/A