-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(react-avatar): add base hooks for Avatar component #35696
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
base: master
Are you sure you want to change the base?
Conversation
5b90a26 to
560dfec
Compare
📊 Bundle size reportUnchanged fixtures
|
|
Pull request demo site: URL |
| @@ -0,0 +1,7 @@ | |||
| { | |||
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.
🕵🏾♀️ visual changes to review in the Visual Change Report
vr-tests-react-components/Avatar Converged 10 screenshots
| Image Name | Diff(in Pixels) | Image Type |
|---|---|---|
| vr-tests-react-components/Avatar Converged.basic - High Contrast.normal.chromium.png | 141 | Changed |
| vr-tests-react-components/Avatar Converged.basic - RTL.normal.chromium.png | 106 | Changed |
| vr-tests-react-components/Avatar Converged.basic - Dark Mode.normal.chromium.png | 30 | Changed |
| vr-tests-react-components/Avatar Converged.image-bad-url+icon.normal.chromium.png | 106 | Changed |
| vr-tests-react-components/Avatar Converged.customSize+icon+active.normal.chromium.png | 2826 | Changed |
| vr-tests-react-components/Avatar Converged.color - High Contrast.normal.chromium.png | 4504 | Changed |
| vr-tests-react-components/Avatar Converged.color+active.normal.chromium.png | 6586 | Changed |
| vr-tests-react-components/Avatar Converged.size+icon+badge+square.normal.chromium.png | 6366 | Changed |
| vr-tests-react-components/Avatar Converged.color+active - Dark Mode.normal.chromium.png | 2702 | Changed |
| vr-tests-react-components/Avatar Converged.badgeMask.normal.chromium.png | 5 | Changed |
vr-tests-react-components/Charts-DonutChart 1 screenshots
| Image Name | Diff(in Pixels) | Image Type |
|---|---|---|
| vr-tests-react-components/Charts-DonutChart.Dynamic - RTL.default.chromium.png | 5570 | Changed |
vr-tests-react-components/Positioning 2 screenshots
| Image Name | Diff(in Pixels) | Image Type |
|---|---|---|
| vr-tests-react-components/Positioning.Positioning end.updated 2 times.chromium.png | 760 | Changed |
| vr-tests-react-components/Positioning.Positioning end.chromium.png | 28 | Changed |
vr-tests-react-components/Skeleton converged 1 screenshots
| Image Name | Diff(in Pixels) | Image Type |
|---|---|---|
| vr-tests-react-components/Skeleton converged.Opaque Skeleton with circle - High Contrast.default.chromium.png | 1 | Changed |
vr-tests-react-components/TagPicker 1 screenshots
| Image Name | Diff(in Pixels) | Image Type |
|---|---|---|
| vr-tests-react-components/TagPicker.disabled - High Contrast.disabled input hover.chromium.png | 1319 | Changed |
vr-tests-react-components/Tree 3 screenshots
| Image Name | Diff(in Pixels) | Image Type |
|---|---|---|
| vr-tests-react-components/Tree.persona - High Contrast.default.chromium.png | 1102 | Changed |
| vr-tests-react-components/Tree.persona - Dark Mode.default.chromium.png | 208 | Changed |
| vr-tests-react-components/Tree.persona.default.chromium.png | 828 | Changed |
There were 6 duplicate changes discarded. Check the build logs for more information.
| }); | ||
| } | ||
|
|
||
| // Set default icon children if icon slot exists |
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.
| // Set default icon children if icon slot exists |
|
|
||
| if (!userProvidedAriaLabel && !userProvidedAriaLabelledby) { | ||
| if (props.name) { | ||
| // Include the badge in labelledby if it exists |
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.
| // Include the badge in labelledby if it exists |
| if (badge) { | ||
| state.root['aria-labelledby'] = state.root.id + ' ' + badge.id; | ||
| } | ||
| // aria-label is already set by base function, keep it |
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.
| // aria-label is already set by base function, keep it |

Previous Behavior
New Behavior
Added
useAvatarBase_unstablehook that contains state for logic and slots (but excludes the badge slot and badge-related props). Exports are commented out intentionally, as we'll uncomment them in experimental branch for experimental release.Example how to compose a custom Avatar component:
Note: There are no public API changes or modifications to the behavior of existing components, and all unit and VR tests are passing. The new hook
useAvatarBase_unstableand types (AvatarBaseProps, AvatarBaseState) are now exported for composing custom Avatar components.Related Issue(s)
Partially implements #35562