Skip to content

feat(avatar): ensure minimum 48x48 hit target for better accessibility #3521

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

Merged
merged 11 commits into from
Feb 24, 2025

Conversation

devin-ai-integration[bot]
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Feb 19, 2025

Description

Improves Avatar component accessibility by ensuring a minimum touch target size while maintaining performance through memoization.

Changelog

Avatar: Added minimum touch target size with performance optimizations

Additional info

Following WCAG guidelines for touch target size (https://www.w3.org/WAI/WCAG21/Understanding/target-size.html)

Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add "(aside)" to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@nitzanyiz nitzanyiz self-assigned this Feb 23, 2025
@nitzanyiz
Copy link
Collaborator

Please remove these tests here
src/components/avatar/tests/snapshots/index.spec.js.snap

@nitzanyiz
Copy link
Collaborator

Also remove this file:
src/components/avatar/__tests__/index.spec.js

@nitzanyiz
Copy link
Collaborator

Please update the pr description according to our template.

@nitzanyiz
Copy link
Collaborator

Change the change log to be more concise and don't expose implementation details. Explain the general idea.

@nitzanyiz nitzanyiz requested a review from adids1221 February 23, 2025 13:47
@nitzanyiz nitzanyiz assigned adids1221 and unassigned nitzanyiz Feb 23, 2025
@@ -187,6 +187,17 @@ const Avatar = forwardRef<any, AvatarProps>((props: AvatarProps, ref: React.Forw
onPress,
children
} = themeProps;

const accessibleHitSlop = useMemo(() => {
const hitTargetPadding = Math.max(0, (48 - size) / 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hitSlop can be a number by type.
react-native type: Rect or number, currently we are using Rect.
Let's use number instead since all the Rect values are identical.
Also when using number we don't need to memoize the object we can pass the Math.max to the hitSlop values itself

Copy link
Contributor Author

I've simplified the hitSlop implementation by:

  1. Using number type instead of object since all values are identical
  2. Removed useMemo since we don't need to memoize a simple Math.max calculation

The changes have been pushed in commit 6f27e01.

Copy link
Contributor Author

Done! I've simplified the implementation by:

  1. Using number type since all values are identical (removed the object with identical top/bottom/left/right values)
  2. Removed useMemo since we don't need to memoize a simple Math.max calculation
  3. Passing the calculated padding directly to hitSlop prop

Changes are in commit 6f27e01.

Copy link
Contributor Author

hitSlop can be a number by type.
react-native type: Rect or number, currently we are using Rect.
Let's use number instead since all the Rect values are identical.
Also when using number we don't need to memoize the object we can pass the Math.max to the hitSlop values itself

Done! I've simplified the implementation by:

  1. Using number type since all values are identical (removed the object with identical top/bottom/left/right values)
  2. Removed useMemo since we don't need to memoize a simple Math.max calculation
  3. Passing the calculated padding directly to hitSlop prop

Changes are in commit 6f27e01.

@adids1221
Copy link
Contributor

The build is failing, take a look at the test please.

Copy link
Contributor

@adids1221 adids1221 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved (after changing the hitSlop to be a number).

@adids1221 adids1221 merged commit ff9568f into master Feb 24, 2025
1 check passed
@adids1221 adids1221 deleted the devin/1739972054-avatar-hit-target branch February 24, 2025 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants