Skip to content

Conversation

@kotAPI
Copy link
Collaborator

@kotAPI kotAPI commented Sep 4, 2025

Summary

  • refactor BlockQuote to forward refs and use typed props
  • test ref forwarding and data attributes for BlockQuote

Testing

  • npm test src/components/ui/BlockQuote/tests/BlockQuote.test.tsx

Summary by CodeRabbit

  • New Features

    • BlockQuote now supports ref forwarding.
    • Consistent data attributes for variant/size/color; accepts standard blockquote attributes.
  • Refactor

    • Simplified props by extending native blockquote props.
    • Added customRootClass; removed legacy miscellaneous props.
    • Switched to a default export; className handled via native props.
  • Tests

    • Added tests for ref forwarding and data-attribute rendering.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 4, 2025

Walkthrough

The BlockQuote component is refactored to use React.forwardRef with updated props based on blockquote’s native props plus custom fields. Data-attribute construction is reorganized, a new customRootClass prop is added, and default export is introduced. Tests are added for ref forwarding and data-attribute assertions.

Changes

Cohort / File(s) Summary of edits
BlockQuote component refactor
src/components/ui/BlockQuote/BlockQuote.tsx
Converted to React.forwardRef; props type switched to React.ComponentPropsWithoutRef<'blockquote'> with customRootClass, color, variant, size; removed explicit children/className declarations and props? field; reorganized data-* attributes; added default export.
BlockQuote tests update
src/components/ui/BlockQuote/tests/BlockQuote.test.tsx
Added tests for ref forwarding and for data attributes (variant, size).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev
  participant App as App Component
  participant BlockQuote as BlockQuote (forwardRef)
  participant DOM as <blockquote>

  Dev->>App: Render <BlockQuote ref={qRef} variant size ...>
  App->>BlockQuote: Props + ref
  rect rgba(213,232,253,0.45)
    note right of BlockQuote: Build className/customRootClass and data-* (variant/size/color)
    BlockQuote->>DOM: Render blockquote {...props} data-* ref
  end
  DOM-->>BlockQuote: element handle
  BlockQuote-->>App: forwarded ref current = HTMLQuoteElement
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

Poem

I nudge a quote with gentle care,
Forward my ref through autumn air.
New props hop in, old ones hop out—
data-* carrots sprinkled about.
Default export, ears up high—
A tidy blockquote, whiskers spry. 🥕✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kotapi/refactor-blockquote-component-for-forwardref

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
🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@kotAPI kotAPI merged commit e2a420e into main Sep 4, 2025
8 checks passed
@kotAPI kotAPI deleted the kotapi/refactor-blockquote-component-for-forwardref branch September 4, 2025 12:56
Copy link
Contributor

@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

🧹 Nitpick comments (3)
src/components/ui/BlockQuote/BlockQuote.tsx (1)

16-16: Drop unnecessary defaulting to empty strings.

Optional props don’t need =''; clsx and conditionals handle undefined fine. Slightly cleaner and avoids accidental truthiness bugs.

-    ({ children, customRootClass = '', className = '', color = '', variant = '', size = '', ...props }, ref) => {
+    ({ children, customRootClass = '', className, color, variant, size, ...props }, ref) => {
src/components/ui/BlockQuote/tests/BlockQuote.test.tsx (2)

35-39: Strengthen the ref test with an instance check.

         const ref = React.createRef<HTMLQuoteElement>();
         render(<BlockQuote ref={ref}>BlockQuote</BlockQuote>);
         expect(ref.current).not.toBeNull();
+        expect(ref.current).toBeInstanceOf(HTMLQuoteElement);

41-46: Add a negative case for absent data attributes.

Guard against regressions by asserting variant/size attrs are not rendered when props are omitted.

Proposed test (new block):

test('does not render variant/size data attributes when not provided', () => {
  render(<BlockQuote>BlockQuote</BlockQuote>);
  const el = screen.getByText('BlockQuote');
  expect(el).not.toHaveAttribute('data-block-quote-variant');
  expect(el).not.toHaveAttribute('data-block-quote-size');
});
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 41c6ec0 and 55161b2.

📒 Files selected for processing (2)
  • src/components/ui/BlockQuote/BlockQuote.tsx (1 hunks)
  • src/components/ui/BlockQuote/tests/BlockQuote.test.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (4)
src/components/ui/BlockQuote/BlockQuote.tsx (3)

15-39: ForwardRef conversion and prop typing look solid.

Ref is correctly forwarded to the blockquote; prop surface aligns with native props + custom fields.


34-37: Confirm precedence: internal data-attrs vs consumer-supplied ones.

You spread ...props before ...data_attributes, so library-generated attributes overwrite any user-provided data-*. If that’s intentional, keep it. If you prefer consumer override, flip the order.


34-37: Verify clsx import style.

You’re calling clsx(...) but the package exposes a default export. Ensure the import matches your bundler/TS config; default import is the safe choice.

Recommended import (outside this hunk):

import clsx from 'clsx';
src/components/ui/BlockQuote/tests/BlockQuote.test.tsx (1)

35-39: Ref forwarding test reads well.

Comment on lines +19 to +31
const data_attributes: Record<string, string> = {};

if (size) {
data_attributes['data-block-quote-size'] = size;
}
if (variant) {
data_attributes['data-block-quote-variant'] = variant;
}

if (color) {
data_attributes['data-rad-ui-accent-color'] = color;
}
if (size) {
data_attributes['data-block-quote-size'] = size;
}

return <blockquote className={clsx(rootClass, className)} {...props} {...data_attributes}> {children}</blockquote>;
};
if (color) {
data_attributes['data-rad-ui-accent-color'] = color;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Tighten type for data attributes to avoid TS JSX spread errors.

Spreading Record<string, string> into JSX can fail under strict React types because it allows non-data-* keys. Constrain to data-* keys.

-        const data_attributes: Record<string, string> = {};
+        const data_attributes: Partial<Record<`data-${string}`, string | number | boolean | undefined>> = {};
📝 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
const data_attributes: Record<string, string> = {};
if (size) {
data_attributes['data-block-quote-size'] = size;
}
if (variant) {
data_attributes['data-block-quote-variant'] = variant;
}
if (color) {
data_attributes['data-rad-ui-accent-color'] = color;
}
if (size) {
data_attributes['data-block-quote-size'] = size;
}
return <blockquote className={clsx(rootClass, className)} {...props} {...data_attributes}> {children}</blockquote>;
};
if (color) {
data_attributes['data-rad-ui-accent-color'] = color;
}
const data_attributes: Partial<Record<`data-${string}`, string | number | boolean | undefined>> = {};
if (variant) {
data_attributes['data-block-quote-variant'] = variant;
}
if (size) {
data_attributes['data-block-quote-size'] = size;
}
if (color) {
data_attributes['data-rad-ui-accent-color'] = color;
}
🤖 Prompt for AI Agents
In src/components/ui/BlockQuote/BlockQuote.tsx around lines 19 to 31, the
data_attributes variable is typed as Record<string, string>, which is too broad
for JSX spread; replace its type with Partial<Record<`data-${string}`, string>>
(or {[k: `data-${string}`]: string} | undefined) so only data-* keys are
allowed, keep the existing conditional assignments (data-block-quote-variant,
data-block-quote-size, data-rad-ui-accent-color) and then spread data_attributes
into the JSX; this tightens the type and prevents TS JSX spread errors.

@kotAPI kotAPI linked an issue Sep 4, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BlockQuote [forwardRef refactor]

2 participants