Skip to content

Add standard states and horizontal parity to Avatar component#90

Merged
bradpotts merged 1 commit into
mainfrom
fix/avatar-standard-states-9336953692732881863
May 25, 2026
Merged

Add standard states and horizontal parity to Avatar component#90
bradpotts merged 1 commit into
mainfrom
fix/avatar-standard-states-9336953692732881863

Conversation

@bradpotts
Copy link
Copy Markdown
Contributor

@bradpotts bradpotts commented May 25, 2026

This PR hardens the Avatar component styling contract by adding missing interaction states (disabled, loading, hover, focus, active) and the fullWidth structural variant. It ensures visual parity with other interactive components in the library and provides both pseudo-selector and forced-state class support. Includes updated unit tests and CSS contract validation.


PR created automatically by Jules for task 9336953692732881863 started by @bradpotts

Summary by CodeRabbit

  • New Features

    • Expanded avatar component with new styling states: disabled, loading, interactive, and full-width options.
    • Added smooth transitions for avatar background, color, and border changes.
    • Implemented focus ring indicators for improved accessibility.
  • Documentation

    • New example added showcasing avatar component states and interactions.

Review Change Stack

…component

Updated the Avatar component to include missing interaction states
(disabled, loading, interactive, hovered, focused, active) and the
fullWidth structural variant.

Changes:
- src/styles/components.css: Added CSS classes for standard states,
  transitions, and focus ring support.
- src/recipes/avatar.ts: Updated recipe to include new boolean and
  forced-state flags.
- tests/alert-avatar-recipe.test.ts: Added unit test coverage for new
  Avatar states.
- tests/css-contract.test.ts: Included Avatar in the exhaustive CSS
  parity contract.

Co-authored-by: bradpotts <4887598+bradpotts@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 25, 2026

Walkthrough

This PR extends the avatar component recipe with boolean state flags for styling control (disabled, loading, interactive, hovered, focused, active, fullWidth), updates class generation to emit corresponding modifier classes, adds CSS rules for all avatar states and interactions, and provides test coverage validating both recipe behavior and CSS contract compliance.

Changes

Avatar State Styling

Layer / File(s) Summary
Avatar recipe options and class generation
src/recipes/avatar.ts
AvatarRecipeOptions gains boolean state flags and getAvatarClasses now emits conditional modifier classes including is-hover, is-focus, is-active, and sp-avatar--full based on option values.
Avatar CSS base styles and state modifiers
src/styles/components.css
Base .sp-avatar block expanded with transparent border and transition properties; new .sp-avatar--full, .sp-avatar--interactive, and state-specific selectors added for hover, focus-visible, active, disabled, and loading states.
Avatar recipe behavior tests
tests/alert-avatar-recipe.test.ts
Test cases verify that state flags (disabled, loading, interactive, fullWidth) and forced-state flags (hovered, focused, active) generate expected classes with proper tokenization.
Avatar CSS contract validation
tests/css-contract.test.ts
CSS contract extended to validate avatar recipe selector coverage across size, shape, and state combinations; assertions confirm interaction states and size variant selectors in dist/components.css.
Avatar verification example
examples/avatar-verification.html
New HTML example demonstrating avatar states including interactive, hover, focus, active, disabled, loading, and full-width variations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • phcdevworks/spectre-ui#80: Both PRs update a component recipe to emit forced interaction state modifier classes (is-hover/is-focus/is-active, plus related state flags) and align the corresponding CSS selectors to consume those classes, so the changes are structurally analogous.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is missing required template sections: linked issue link format, explicit UI contract change type classification, and Type of Change checkboxes. Checklist items are not marked, and CHANGELOG/docs updates are not addressed. Complete the template by adding: linked issue reference, explicit UI contract change type (additive/semantic/breaking), check Type of Change boxes, verify checklist items, and address CHANGELOG/docs updates.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: adding standard interaction states and horizontal parity to the Avatar component.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/avatar-standard-states-9336953692732881863

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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@tests/alert-avatar-recipe.test.ts`:
- Around line 127-130: The test currently asserts multi-token className with
expect(result).toContain(className) which is fragile; update the loop over
states in the test to split className on whitespace (className.split(/\s+/)) and
assert each token individually against the result (for each token call
expect(result).toContain(token)), while still calling
expectTokenizedClassString(result); locate references to states, className,
getAvatarClasses and expectTokenizedClassString to make the change.
🪄 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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d0e5b4da-af5a-481f-8ec6-834067d9b09e

📥 Commits

Reviewing files that changed from the base of the PR and between 061437a and 95ba9ed.

📒 Files selected for processing (5)
  • examples/avatar-verification.html
  • src/recipes/avatar.ts
  • src/styles/components.css
  • tests/alert-avatar-recipe.test.ts
  • tests/css-contract.test.ts

Comment on lines +127 to +130
states.forEach(({ key, className }) => {
const result = getAvatarClasses({ [key]: true })
expect(result).toContain(className)
expectTokenizedClassString(result)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Consider splitting className for individual token assertions.

The test currently uses .toContain(className) where className is a multi-token string like 'sp-avatar--hover is-hover'. This works but assumes the classes appear adjacent and in the exact order. A more robust approach would split the expected classes and assert each token individually:

-    states.forEach(({ key, className }) => {
+    states.forEach(({ key, className }) => {
       const result = getAvatarClasses({ [key]: true })
-      expect(result).toContain(className)
+      className.split(/\s+/).forEach(cls => {
+        expect(result).toContain(cls)
+      })
       expectTokenizedClassString(result)
     })

This approach is resilient to class reordering and remains clear about which tokens are expected.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
states.forEach(({ key, className }) => {
const result = getAvatarClasses({ [key]: true })
expect(result).toContain(className)
expectTokenizedClassString(result)
states.forEach(({ key, className }) => {
const result = getAvatarClasses({ [key]: true })
className.split(/\s+/).forEach(cls => {
expect(result).toContain(cls)
})
expectTokenizedClassString(result)
})
🤖 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 `@tests/alert-avatar-recipe.test.ts` around lines 127 - 130, The test currently
asserts multi-token className with expect(result).toContain(className) which is
fragile; update the loop over states in the test to split className on
whitespace (className.split(/\s+/)) and assert each token individually against
the result (for each token call expect(result).toContain(token)), while still
calling expectTokenizedClassString(result); locate references to states,
className, getAvatarClasses and expectTokenizedClassString to make the change.

@bradpotts bradpotts merged commit 6061366 into main May 25, 2026
3 checks passed
@bradpotts bradpotts deleted the fix/avatar-standard-states-9336953692732881863 branch May 25, 2026 23:01
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.

1 participant