Skip to content

Conversation

@cheshtagupta284
Copy link

@cheshtagupta284 cheshtagupta284 commented Jun 24, 2025

Closes #

📝 Description

Add a brief description

Affected component:
Copyable variant of Tag

Issue:
The content inside ::before persisted after copy icon was clicked. For tag with long text, this ::before content overflowed the container even though the original text was ellipsed.

RCA:
isCopied state wrongly controlled animation state.

Fix:
Separated the animation state which triggers on first copy only.

Screenshots

Please provide screenshots for any visual changes

After fix:

Screen.Recording.2025-06-24.at.5.21.24.PM.mov

Before fix:

Screen.Recording.2025-06-25.at.9.16.47.AM.mov

Merge checklist

  • Added/updated tests
  • Added changeset

@changeset-bot
Copy link

changeset-bot bot commented Jun 24, 2025

🦋 Changeset detected

Latest commit: f4a8878

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@project44-manifest/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Jun 24, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved the animation behavior for the copyable tag component.
    • Updated accessibility labels in tag stories to better reflect copy functionality.
  • Tests

    • Added a new test to verify the copy-to-clipboard feature of the tag component.

Walkthrough

The changes update the copy animation behavior for the copyable Tag component in the @project44-manifest/react package. The animation state logic is refactored, accessibility labels in stories are corrected, and a new test is added to verify the copy-to-clipboard functionality. A changeset file documents the patch.

Changes

File(s) Change Summary
.changeset/silver-kiwis-attend.md Added changeset documenting a patch for fixing copyable tag animation.
packages/react/src/components/Tag/Tag.styles.ts Renamed animation variant from isCopied to showCopiedAnimation in styles.
packages/react/src/components/Tag/Tag.tsx Introduced showCopiedAnimation state and effect to control animation timing based on isCopied.
packages/react/src/components/Tag/story/Tag.stories.tsx Updated aria-label values in Copyable story to accurately reflect copy action for accessibility.
packages/react/src/components/Tag/tests/Tag.test.tsx Added a test to verify clipboard copy functionality for the Tag component.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TagComponent
    participant ClipboardAPI

    User->>TagComponent: Clicks copyable tag
    TagComponent->>ClipboardAPI: Calls writeText(label)
    ClipboardAPI-->>TagComponent: Confirms text copied
    TagComponent->>TagComponent: Sets showCopiedAnimation = true
    Note over TagComponent: Animation plays
    TagComponent->>TagComponent: After 600ms, sets showCopiedAnimation = false
Loading

Assessment against linked issues

Objective Addressed Explanation
Fix copy animation and clipboard behavior for tenant UUID copy (MI-779)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes were found.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch MI-779-fix-tag

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@cheshtagupta284 cheshtagupta284 self-assigned this Jun 25, 2025
@cheshtagupta284 cheshtagupta284 marked this pull request as ready for review June 25, 2025 03:45
@cheshtagupta284 cheshtagupta284 requested a review from a team as a code owner June 25, 2025 03:45
Copy link

@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: 0

🧹 Nitpick comments (3)
.changeset/silver-kiwis-attend.md (1)

5-5: Consider a more descriptive changeset message.

While the current message is clear, consider providing more specific details about the fix for better changelog documentation.

-fixes animation for copyable tag component
+fix copyable Tag animation persistence causing text overflow
packages/react/src/components/Tag/tests/Tag.test.tsx (1)

24-46: Comprehensive test for copy functionality.

The test properly mocks the clipboard API and verifies the core copy behavior. Good use of the label prop for clipboard content verification.

Consider adding a test to verify the animation timing behavior:

it('should show and hide animation state correctly', async () => {
  jest.useFakeTimers();
  const mockClipboard = { writeText: jest.fn().mockResolvedValue(undefined) };
  Object.defineProperty(global.navigator, 'clipboard', {
    value: mockClipboard,
    writable: true,
  });

  render(<Tag isCopyable label="test">Test</Tag>);
  
  const tag = screen.getByText('Test').closest('.manifest-tag');
  fireEvent.click(tag!);
  
  // Animation should be active initially
  expect(tag).toHaveClass('showCopiedAnimation');
  
  // Fast-forward past the timeout
  jest.advanceTimersByTime(700);
  
  // Animation should be cleared
  expect(tag).not.toHaveClass('showCopiedAnimation');
  
  jest.useRealTimers();
});
packages/react/src/components/Tag/Tag.tsx (1)

121-132: Solid animation timing implementation with proper cleanup.

The useEffect correctly manages the animation lifecycle - triggering on copy and clearing after 600ms. The cleanup function prevents memory leaks.

Consider extracting the timeout duration as a constant for better maintainability:

+const ANIMATION_DURATION = 600; // slightly less than 0.7s CSS animation

 React.useEffect(() => {
   let timeoutId: ReturnType<typeof setTimeout> | undefined;
   if (isCopied) {
     setShowCopiedAnimation(true);
-    timeoutId = setTimeout(() => void setShowCopiedAnimation(false), 600); // slightly less than animation duration
+    timeoutId = setTimeout(() => void setShowCopiedAnimation(false), ANIMATION_DURATION);
   }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a2d787c and f4a8878.

📒 Files selected for processing (5)
  • .changeset/silver-kiwis-attend.md (1 hunks)
  • packages/react/src/components/Tag/Tag.styles.ts (1 hunks)
  • packages/react/src/components/Tag/Tag.tsx (2 hunks)
  • packages/react/src/components/Tag/story/Tag.stories.tsx (1 hunks)
  • packages/react/src/components/Tag/tests/Tag.test.tsx (1 hunks)
🔇 Additional comments (5)
packages/react/src/components/Tag/Tag.styles.ts (1)

68-68: LGTM: Variant name correctly reflects its purpose.

The rename from isCopied to showCopiedAnimation better separates the animation state from the copy state, which addresses the core issue of the persistent ::before content.

packages/react/src/components/Tag/story/Tag.stories.tsx (2)

76-76: Excellent accessibility improvements.

The updated aria-labels correctly reflect the copyable functionality instead of removal, significantly improving accessibility for screen reader users.

Also applies to: 84-84, 92-92


83-86: Good addition for testing the overflow fix.

The "Tag with long text" example effectively demonstrates the scenario where the animation overflow issue would occur, making it easier to verify the fix visually.

packages/react/src/components/Tag/Tag.tsx (2)

67-67: Good separation of animation state.

The new showCopiedAnimation state properly separates animation control from the copy state, addressing the core issue of persistent animation content.


113-113: Correct integration with styling system.

The showCopiedAnimation state is properly passed to the useStyles hook, enabling the CSS variant to control the animation display.

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.

2 participants