Skip to content

feat(Avatar): support colorful#12460

Open
kmcfaul wants to merge 4 commits into
patternfly:mainfrom
kmcfaul:avatar-colorful
Open

feat(Avatar): support colorful#12460
kmcfaul wants to merge 4 commits into
patternfly:mainfrom
kmcfaul:avatar-colorful

Conversation

@kmcfaul

@kmcfaul kmcfaul commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

What: Closes #12442

  • Adds color, initials, and children props to Avatar
  • Adds examples using direct svg, initials, and icons
  • Updates other Avatar examples to newer avatar icon & condense format of size example
  • Adds tests
  • Bumps core version to pull in avatar styles
    • Updates charts snaps that look to be changed from core bump cc @mcoker Is this expected?

Notes:

  • Since alt is a required prop for Avatar, repurposed alt to function as aria-label for children/initials structure (passing aria-label as well as alt should still function and override alt). LMK if we'd rather keep the props separate and make alt optional.
  • isBordered doesn't work with colorful (colorful has precedence over bordered modifier when both are applied). Should these modifiers be allowed to be used together?
  • Using children or initials without color prop looks off. Should we still be applying pf-m-colorful for the formatting without a color specified?

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Avatar supports colorful variants and can display custom initials or arbitrary content (icons/SVG) in addition to images.
  • Documentation

    • Updated avatar examples to show colors, initials, icons, size variations, and new layout.
  • Tests

    • Added tests confirming initials, children content, and color variants render correctly.
  • Chores

    • Updated core PatternFly dependency to a new prerelease version across packages.

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 232f12f1-c420-4f56-b480-ab660d851c81

📥 Commits

Reviewing files that changed from the base of the PR and between a048504 and 25e2682.

⛔ Files ignored due to path filters (7)
  • packages/react-charts/src/victory/components/ChartContainer/__snapshots__/ChartContainer.test.tsx.snap is excluded by !**/*.snap
  • packages/react-charts/src/victory/components/ChartDonut/__snapshots__/ChartDonut.test.tsx.snap is excluded by !**/*.snap
  • packages/react-charts/src/victory/components/ChartDonutUtilization/__snapshots__/ChartDonutThreshold.test.tsx.snap is excluded by !**/*.snap
  • packages/react-charts/src/victory/components/ChartDonutUtilization/__snapshots__/ChartDonutUtilization.test.tsx.snap is excluded by !**/*.snap
  • packages/react-charts/src/victory/components/ChartLegend/__snapshots__/ChartLegend.test.tsx.snap is excluded by !**/*.snap
  • packages/react-charts/src/victory/components/ChartLegendTooltip/__snapshots__/ChartLegendTooltip.test.tsx.snap is excluded by !**/*.snap
  • packages/react-charts/src/victory/components/ChartPoint/__snapshots__/ChartPoint.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (4)
  • packages/react-core/src/components/Avatar/Avatar.tsx
  • packages/react-core/src/components/Avatar/examples/AvatarIcons.tsx
  • packages/react-core/src/components/Avatar/examples/AvatarInitials.tsx
  • packages/react-core/src/components/Avatar/examples/avatar.css
✅ Files skipped from review due to trivial changes (2)
  • packages/react-core/src/components/Avatar/examples/AvatarIcons.tsx
  • packages/react-core/src/components/Avatar/examples/avatar.css
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/react-core/src/components/Avatar/examples/AvatarInitials.tsx
  • packages/react-core/src/components/Avatar/Avatar.tsx

Walkthrough

Adds color variants, initials, and children support to Avatar with conditional div/img rendering; updates PatternFly dependency to 6.6.0-prerelease.8; includes tests and multiple example files demonstrating colorful SVGs, initials, and icons.

Changes

Avatar colorful and nested content support

Layer / File(s) Summary
PatternFly dependency updates
packages/react-core/package.json, packages/react-docs/package.json, packages/react-icons/package.json, packages/react-styles/package.json, packages/react-tokens/package.json
@patternfly/patternfly bumped from 6.5.2 to 6.6.0-prerelease.8 across packages.
Avatar component interface and conditional rendering
packages/react-core/src/components/Avatar/Avatar.tsx
Added optional children, color (red/orangered/orange/yellow/green/teal/blue/purple/gray), and initials to AvatarProps; Avatar now renders a div (role="img", aria-label, optional color class, initials span) when initials or children exist, otherwise renders an img.
Avatar test coverage for new features
packages/react-core/src/components/Avatar/__tests__/Avatar.test.tsx
Tests verifying initials and children rendering and that color applies the correct modifier classes (including a parameterized test.each).
Avatar examples and documentation
packages/react-core/src/components/Avatar/examples/Avatar.md, AvatarBasic.tsx, AvatarBordered.tsx, AvatarColorful.tsx, AvatarIcons.tsx, AvatarInitials.tsx, AvatarSizeVariations.tsx, avatar.css
Docs reworked with a "Colorful avatars" section; examples updated to new SVG asset; new example files for SVGs, initials, and icons; CSS added for example layout.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • mcoker
  • nicolethoen
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(Avatar): support colorful' clearly and concisely summarizes the main change—adding colorful avatar support with new color props and children/initials rendering.
Linked Issues check ✅ Passed All objectives from issue #12442 are met: color prop support added, children/initials rendering implemented, examples demonstrating all features provided, tests added, and ARIA handling updated.
Out of Scope Changes check ✅ Passed All changes are directly related to colorful avatar support—component implementation, examples, tests, and required dependency updates. No unrelated changes detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@patternfly-build

patternfly-build commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/react-core/src/components/Avatar/__tests__/Avatar.test.tsx (1)

75-92: ⚡ Quick win

Add a regression test for colorful-over-bordered precedence.

Current additions validate colorful classes, but not the contract that bordered must be omitted when colorful is used.

Suggested test
+test('Does not apply bordered modifier when color is used', () => {
+  render(
+    <Avatar alt="avatar" color="red" isBordered>
+      Test
+    </Avatar>
+  );
+  expect(screen.getByText('Test')).toHaveClass(styles.modifiers.colorful);
+  expect(screen.getByText('Test')).not.toHaveClass(styles.modifiers.bordered);
+});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/react-core/src/components/Avatar/__tests__/Avatar.test.tsx` around
lines 75 - 92, Add a regression test in Avatar.test.tsx that verifies the
"colorful-over-bordered" precedence by rendering <Avatar alt="avatar"
color="red" bordered> (or iterate colors with test.each) and asserting the
rendered node has styles.modifiers.colorful (or styles.modifiers[color]) and
does NOT have styles.modifiers.bordered; place the test near the existing color
tests and use screen.getByText('Test') for assertions to match the current test
patterns.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/react-core/src/components/Avatar/Avatar.tsx`:
- Around line 37-43: avatarClasses is built including isBordered unconditionally
which causes pf-m-bordered to persist for colorful avatars; update the logic so
bordered is only applied when color is not set. For example, keep the existing
avatarClasses for the non-colorful branch (use css(styles.avatar,
styles.modifiers[size], isBordered && styles.modifiers.bordered, className)) but
for the colorful branch compute a separate class list (e.g., baseColored =
css(styles.avatar, styles.modifiers[size], className) or reuse avatarClasses
without the bordered modifier) and use that when rendering the color path so
styles.modifiers.bordered is not included when color is truthy; reference
avatarClasses, styles.modifiers.bordered, isBordered and the color branch where
css(avatarClasses, color && styles.modifiers.colorful, color &&
styles.modifiers[color]) is used.

---

Nitpick comments:
In `@packages/react-core/src/components/Avatar/__tests__/Avatar.test.tsx`:
- Around line 75-92: Add a regression test in Avatar.test.tsx that verifies the
"colorful-over-bordered" precedence by rendering <Avatar alt="avatar"
color="red" bordered> (or iterate colors with test.each) and asserting the
rendered node has styles.modifiers.colorful (or styles.modifiers[color]) and
does NOT have styles.modifiers.bordered; place the test near the existing color
tests and use screen.getByText('Test') for assertions to match the current test
patterns.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 94ebea1f-1682-44bc-8b86-ef1a67268557

📥 Commits

Reviewing files that changed from the base of the PR and between 8b528bb and 6e56f07.

⛔ Files ignored due to path filters (2)
  • packages/react-core/src/components/assets/img_avatar-light.svg is excluded by !**/*.svg
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (15)
  • packages/react-core/package.json
  • packages/react-core/src/components/Avatar/Avatar.tsx
  • packages/react-core/src/components/Avatar/__tests__/Avatar.test.tsx
  • packages/react-core/src/components/Avatar/examples/Avatar.md
  • packages/react-core/src/components/Avatar/examples/AvatarBasic.tsx
  • packages/react-core/src/components/Avatar/examples/AvatarBordered.tsx
  • packages/react-core/src/components/Avatar/examples/AvatarColorful.tsx
  • packages/react-core/src/components/Avatar/examples/AvatarIcons.tsx
  • packages/react-core/src/components/Avatar/examples/AvatarInitials.tsx
  • packages/react-core/src/components/Avatar/examples/AvatarSizeVariations.tsx
  • packages/react-core/src/components/Avatar/examples/avatar.css
  • packages/react-docs/package.json
  • packages/react-icons/package.json
  • packages/react-styles/package.json
  • packages/react-tokens/package.json

Comment on lines +37 to +43
const avatarClasses = css(styles.avatar, styles.modifiers[size], isBordered && styles.modifiers.bordered, className);

if (initials || children) {
return (
<div
className={css(avatarClasses, color && styles.modifiers.colorful, color && styles.modifiers[color])}
role="img"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Colorful avatars currently still keep pf-m-bordered when isBordered is true.

Line 37 builds avatarClasses with isBordered unconditionally, and Line 42 reuses it in the colorful path. That violates the documented behavior that colorful styling takes precedence over bordered.

Proposed fix
-  const avatarClasses = css(styles.avatar, styles.modifiers[size], isBordered && styles.modifiers.bordered, className);
+  const baseAvatarClasses = css(styles.avatar, styles.modifiers[size], className);

   if (initials || children) {
     return (
       <div
-        className={css(avatarClasses, color && styles.modifiers.colorful, color && styles.modifiers[color])}
+        className={css(
+          baseAvatarClasses,
+          !color && isBordered && styles.modifiers.bordered,
+          color && styles.modifiers.colorful,
+          color && styles.modifiers[color]
+        )}
         role="img"
         aria-label={alt}
         {...props}
       >
@@
-  return <img src={src} alt={alt} className={avatarClasses} {...props} />;
+  return <img src={src} alt={alt} className={css(baseAvatarClasses, isBordered && styles.modifiers.bordered)} {...props} />;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/react-core/src/components/Avatar/Avatar.tsx` around lines 37 - 43,
avatarClasses is built including isBordered unconditionally which causes
pf-m-bordered to persist for colorful avatars; update the logic so bordered is
only applied when color is not set. For example, keep the existing avatarClasses
for the non-colorful branch (use css(styles.avatar, styles.modifiers[size],
isBordered && styles.modifiers.bordered, className)) but for the colorful branch
compute a separate class list (e.g., baseColored = css(styles.avatar,
styles.modifiers[size], className) or reuse avatarClasses without the bordered
modifier) and use that when rendering the color path so
styles.modifiers.bordered is not included when color is truthy; reference
avatarClasses, styles.modifiers.bordered, isBordered and the color branch where
css(avatarClasses, color && styles.modifiers.colorful, color &&
styles.modifiers[color]) is used.

@mcoker mcoker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, just add isInline to the <Icon> components in the examples. The other comments are nits/questions.

#ws-react-c-avatar-with-svgs,
#ws-react-c-avatar-with-initials,
#ws-react-c-avatar-with-icons {
display: flex;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd also add flex-wrap: wrap so these wrap if there isn't enough space. An alternative is to remove the flex CSS and put spaces between the avatars in the examples, I think I've seen it done like {' '} before.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added the wrap, we have done {' '} before but sometimes prettier formats things oddly when that's used.

Comment on lines +7 to +9
<Icon size="xl">
<RhUiAiChatbotIcon />
</Icon>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should probably review this with design, to see if using an icon as a child is a use case and if we need to change the icon size so it isn't clipped by the circle shape.

If you add isInline and leave the size it will fix the icon color

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Using an icon is the use case for chatbot. It may not need to be in an Icon but that's the easiest way to adjust the size that I could see.

Comment thread packages/react-core/src/components/Avatar/examples/AvatarInitials.tsx Outdated
@mcoker

mcoker commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Updates charts snaps that look to be changed from core bump cc @mcoker Is this expected?

@kmcfaul yupp! Chart color tokens with transparency use rgb() instead of rgba() now due to some new stylelint rules in core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avatar - support for new colorful icons and nested structure

3 participants