Skip to content

Conversation

@kotAPI
Copy link
Collaborator

@kotAPI kotAPI commented Sep 4, 2025

Summary

  • refactor Button primitive and component to forward refs with proper typing
  • convert VisuallyHidden to React.forwardRef and type using Primitive element
  • verify ref forwarding and accessibility behavior with new tests

Testing

  • npm test

Summary by CodeRabbit

  • Breaking Changes
    • Removed the VisuallyHidden component and its examples.
  • New Features
    • Button now forwards refs to the underlying element for improved integration.
  • Documentation
    • Removed the Visually Hidden docs page and SEO entry; navigation no longer lists it.
  • Tests
    • Added a test to verify Button’s ref forwarding.
  • Chores
    • Updated released components registry and documentation navigation.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 4, 2025

Warning

Rate limit exceeded

@kotAPI has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 56 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 8518adf and 780bb37.

📒 Files selected for processing (5)
  • docs/app/docs/components/visually-hidden/docs/codeUsage.js (1 hunks)
  • docs/app/docs/components/visually-hidden/page.mdx (1 hunks)
  • docs/app/docs/components/visually-hidden/seo.ts (1 hunks)
  • src/components/ui/VisuallyHidden/VisuallyHidden.tsx (2 hunks)
  • src/components/ui/VisuallyHidden/tests/VisuallyHidden.test.js (1 hunks)

Walkthrough

This PR removes the VisuallyHidden component and all related docs, stories, tests, and navigation/SEO entries, updates the released components list, and refactors the Button to forward refs to ButtonPrimitive with refined typings. It also strengthens ButtonPrimitive’s TypeScript types and adds a ref-forwarding test for Button.

Changes

Cohort / File(s) Summary
Docs removal (VisuallyHidden)
docs/app/docs/components/visually-hidden/page.mdx, docs/app/docs/components/visually-hidden/docs/codeUsage.js, docs/app/docs/components/visually-hidden/seo.ts
Deleted VisuallyHidden docs page, code samples, and SEO metadata.
Docs navigation update
docs/app/docs/docsNavigationSections.tsx
Removed VisuallyHidden entry from Components navigation.
Release listing update
scripts/RELEASED_COMPONENTS.cjs
Removed 'VisuallyHidden' from released components array.
Component removal (VisuallyHidden)
src/components/ui/VisuallyHidden/VisuallyHidden.tsx, src/components/ui/VisuallyHidden/stories/VisuallyHidden.stories.tsx, src/components/ui/VisuallyHidden/tests/VisuallyHidden.test.js
Deleted VisuallyHidden implementation, Storybook stories, and tests.
Button refactor (UI)
src/components/ui/Button/Button.tsx, src/components/ui/Button/tests/Button.test.tsx
Converted Button to React.forwardRef delegating to ButtonPrimitive; adjusted props typing; added ref-forwarding test.
Button primitive typing
src/core/primitives/Button/index.tsx
Introduced typed element/props aliases; updated forwardRef signature and ARIA-related prop typing.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User as Consumer Component
  participant Btn as Button (UI)
  participant Prim as ButtonPrimitive
  participant DOM as <button>

  User->>Btn: render(<Button ref={r} .../>)
  Note over Btn: compute data/accent attrs
  Btn->>Prim: render props + ref
  Prim->>DOM: render <button type, aria-*>
  Btn-->>User: ref forwarded to DOM
Loading
sequenceDiagram
  autonumber
  participant Prim as ButtonPrimitive
  participant DOM as <button>

  Prim->>DOM: apply type="button" (default)
  alt has label
    Prim->>DOM: set aria-label
  end
  alt disabled && no description
    Prim->>DOM: set aria-description="Disabled Button"
  else disabled && description
    Prim->>DOM: set aria-description=description
  end
  alt disabled
    Prim->>DOM: set aria-disabled=true
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • GoldGroove06

Poem

I thump my paws—a tidy sweep,
The Hidden’s gone to burrow deep.
A Button hops with refs in tow,
Through prim fields where typings grow.
Docs dewdrops fade at morning’s sun—
Ship it quick—our sprint is done! 🐇✨

✨ 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-button-component-for-forwardref-usage

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.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

Codex Review: Here are some suggestions.

Reply with @codex fix comments to fix any unresolved comments.

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

Comment on lines 9 to 12
type VisuallyHiddenElement = React.ElementRef<typeof Primitive.div>;
type VisuallyHiddenProps = React.ComponentPropsWithoutRef<typeof Primitive.div> & {
customRootClass?: string;
className?: string;
asChild?: boolean;
style?: CSSProperties;

Choose a reason for hiding this comment

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

[P1] Restore VisuallyHiddenProps export

The refactor changes VisuallyHiddenProps to a local type and drops the export keyword. VisuallyHiddenProps is still imported from this module in the Storybook file (VisuallyHidden/stories/VisuallyHidden.stories.tsx), so the module will no longer compile because the named export is missing. Please keep the type exported so downstream code and the stories can continue to import it.

Useful? React with 👍 / 👎.

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

🧹 Nitpick comments (6)
src/components/ui/Button/tests/Button.test.tsx (1)

46-51: Good ref-forwarding assertion; consider adding a callback-ref case and stronger identity check.

  • Add a callback-ref test to cover both ref patterns.
  • Optionally assert identity against the rendered node via getByRole for extra confidence.
+    test('supports callback ref', () => {
+        let node: HTMLButtonElement | null = null;
+        render(<Button ref={(el) => { node = el; }}>cb ref</Button>);
+        expect(node).toBeInstanceOf(HTMLButtonElement);
+        expect(node?.tagName).toBe('BUTTON');
+    });
+
+    test('ref points to the rendered element', () => {
+        const ref = React.createRef<HTMLButtonElement>();
+        render(<Button ref={ref}>ref identity</Button>);
+        const btn = screen.getByRole('button', { name: 'ref identity' });
+        expect(ref.current).toBe(btn);
+    });
src/core/primitives/Button/index.tsx (3)

29-30: Avoid defaulting role='button' on a native button.

Role is already implicit; defaulting it adds noise and can mask misuse. Let consumers opt-in if they truly need a non-default role.

-const ButtonPrimitive = React.forwardRef<ButtonPrimitiveElement, ButtonPrimitiveProps>(({ role = 'button', type = 'button', label = '', description = '', disabled = false, children, ...props }, ref) => {
+const ButtonPrimitive = React.forwardRef<ButtonPrimitiveElement, ButtonPrimitiveProps>(({ role, type = 'button', label = '', description = '', disabled = false, children, ...props }, ref) => {

43-49: Skip redundant aria-disabled on native buttons (or at least use boolean).

For a native , the disabled attribute suffices; aria-disabled is redundant and may trigger a11y linters. If you keep it for polymorphic cases, set it as a boolean.

Option A (recommended): remove the block

-    if (disabled) {
-        // If the button is disabled, we should set the aria-disabled attribute
-        props['aria-disabled'] = 'true';
-        if (!description) { // If description isn't set, we set a default description
-            props['aria-description'] = 'Disabled Button';
-        }
-    }

Option B (minimal): boolean value and no auto-description

-    if (disabled) {
-        props['aria-disabled'] = 'true';
-        if (!description) {
-            props['aria-description'] = 'Disabled Button';
-        }
-    }
+    if (disabled && props['aria-disabled'] === undefined) {
+        props['aria-disabled'] = true;
+    }

37-42: Optional: Prefer aria-describedby over aria-description for broader AT support.

aria-description has varying support; aria-describedby pointing to hidden helper text is still the most interoperable path.

src/components/ui/Button/Button.tsx (2)

19-19: Nit: avoid duplicating default type at both layers.

ButtonPrimitive already defaults type='button'. You can drop the wrapper default to reduce duplication.

-const Button = React.forwardRef<ButtonElement, ButtonProps>(({ children, type = 'button', customRootClass = '', className = '', variant = '', size = '', color = '', ...props }, ref) => {
+const Button = React.forwardRef<ButtonElement, ButtonProps>(({ children, type, customRootClass = '', className = '', variant = '', size = '', color = '', ...props }, ref) => {

11-17: Consider exporting ButtonProps and narrowing variant/size/color to unions.

If consumers type against Button, exporting ButtonProps helps. Constraining variant/size/color to known unions improves DX and prevents invalid attributes.

Would any external code import ButtonProps today? If yes, I can generate a follow-up PR to export it and introduce unions like 'variant: "solid" | "outline" | "ghost"' and 'size: "small" | "medium" | "large"'.

📜 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 8518adf.

📒 Files selected for processing (11)
  • docs/app/docs/components/visually-hidden/docs/codeUsage.js (0 hunks)
  • docs/app/docs/components/visually-hidden/page.mdx (0 hunks)
  • docs/app/docs/components/visually-hidden/seo.ts (0 hunks)
  • docs/app/docs/docsNavigationSections.tsx (0 hunks)
  • scripts/RELEASED_COMPONENTS.cjs (0 hunks)
  • src/components/ui/Button/Button.tsx (4 hunks)
  • src/components/ui/Button/tests/Button.test.tsx (1 hunks)
  • src/components/ui/VisuallyHidden/VisuallyHidden.tsx (0 hunks)
  • src/components/ui/VisuallyHidden/stories/VisuallyHidden.stories.tsx (0 hunks)
  • src/components/ui/VisuallyHidden/tests/VisuallyHidden.test.js (0 hunks)
  • src/core/primitives/Button/index.tsx (2 hunks)
💤 Files with no reviewable changes (8)
  • src/components/ui/VisuallyHidden/tests/VisuallyHidden.test.js
  • docs/app/docs/components/visually-hidden/page.mdx
  • scripts/RELEASED_COMPONENTS.cjs
  • docs/app/docs/components/visually-hidden/docs/codeUsage.js
  • docs/app/docs/components/visually-hidden/seo.ts
  • src/components/ui/VisuallyHidden/VisuallyHidden.tsx
  • src/components/ui/VisuallyHidden/stories/VisuallyHidden.stories.tsx
  • docs/app/docs/docsNavigationSections.tsx
🧰 Additional context used
🧬 Code graph analysis (1)
src/components/ui/Button/Button.tsx (1)
src/core/primitives/Primitive/Primitive.stories.tsx (1)
  • Button (20-25)
🔇 Additional comments (2)
src/core/primitives/Button/index.tsx (1)

20-27: Type aliases and prop surface look solid.

Deriving the element and props from Primitive.button and reintroducing a narrowed type prop is correct and future-proof.

src/components/ui/Button/Button.tsx (1)

19-37: Ref forwarding and composed data-attributes look good.

Ref is correctly forwarded to ButtonPrimitive; attribute composition is clean and isolated.

@kotAPI kotAPI closed this Sep 5, 2025
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.

2 participants