Skip to content

Conversation

@kotAPI
Copy link
Collaborator

@kotAPI kotAPI commented Sep 10, 2025

Summary

  • add forwardRef Label component with htmlFor support
  • theme integration and documentation with form pairing best practices
  • test label association and focus behavior

Testing

  • npm test

Summary by CodeRabbit

  • New Features
    • Introduced an accessible Label component for pairing text with form inputs, supporting custom styling.
  • Styles
    • Added default label styles for consistent appearance across themes.
  • Documentation
    • Published a Label component page with usage examples, feature highlights, and API details.
    • Added Label to the documentation navigation.
    • Included SEO metadata for improved discoverability.
  • Tests
    • Added tests covering label-to-input association and focus behavior.
  • Chores
    • Marked Label as a released component.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 10, 2025

Walkthrough

Adds a new Label UI component with tests, styles, and theme integration. Introduces documentation pages, API metadata, usage examples, and SEO for Label. Updates docs navigation and release list to include Label. No changes to existing components beyond imports and navigation entries.

Changes

Cohort / File(s) Summary
Label Component Implementation
src/components/ui/Label/Label.tsx, src/components/ui/Label/tests/Label.test.tsx
New React forwardRef Label component with optional customRootClass and clsx-based class merging; unit tests validate association via htmlFor/id and focus-on-click behavior.
Label Styles & Theme
styles/themes/components/label.scss, styles/themes/default.scss
Adds .rad-ui-label base styles; registers label styles in default theme via @use import.
Docs: Label Page, API, Usage, SEO
docs/app/docs/components/label/page.mdx, docs/app/docs/components/label/docs/codeUsage.js, docs/app/docs/components/label/docs/component_api/label.tsx, docs/app/docs/components/label/seo.ts
New docs page with component hero, features, and API table; provides usage code snippets, static API data, and SEO metadata; exports metadata and documentation assets.
Navigation & Release Registry
docs/app/docs/docsNavigationSections.tsx, scripts/RELEASED_COMPONENTS.cjs
Adds "Label" to docs navigation and to RELEASED_COMPONENTS list between Kbd and Progress.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant L as Label (UI)
  participant B as Browser
  participant I as Input

  U->>L: Click label (htmlFor="fieldId")
  L->>B: Default label click behavior
  B->>I: Focus element with id="fieldId"
  Note right of I: Input receives focus
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • GoldGroove06

Poem

I ink a tag with gentle care,
A label whispers, “Focus there!”
Click—the field looks back at me,
Forms now dance in harmony.
Thump-thump goes my rabbit heart,
Shipping docs and styles—carrot art! 🥕🐇

Pre-merge checks (3 passed)

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly and accurately describes the primary change by indicating the addition of the Label component along with its documentation and tests, using clear and concise phrasing that aligns with conventional commit norms without including irrelevant details.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ 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/add-label-component-with-tests-and-documentation

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.

@github-actions
Copy link
Contributor

Coverage

This report compares the PR with the base branch. “Δ” shows how the PR affects each metric.

Metric PR Δ
Statements 89.69% +0.02%
Branches 66.03% +0.00%
Functions 73.11% +0.05%
Lines 88.57% +0.02%

Coverage improved or stayed the same. Great job!

Run npm run coverage locally for detailed reports and target untested areas to raise these numbers.

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

🧹 Nitpick comments (10)
styles/themes/components/label.scss (1)

1-5: Baseline label styles look good; consider tokens/logical props.

If spacing tokens exist, prefer them (e.g., var(--rad-ui-space-1)) and consider margin-block-end over margin-bottom for writing-mode friendliness.

docs/app/docs/docsNavigationSections.tsx (1)

100-103: Nav entry LGTM; optionally flag as new.

If you want to surface “Label” as newly added like others here, add is_new: true.

docs/app/docs/components/label/seo.ts (1)

3-6: SEO metadata is fine; consider canonical/OG fields.

If generateSeoMetadata supports it, set canonical path (/docs/components/label) and basic openGraph for richer previews.

docs/app/docs/components/label/docs/component_api/label.tsx (1)

1-45: Tighten typings and defaults in API table.

  • Use literal types to prevent accidental mutation in consumers.
  • Consider using "—" for undefined defaults for consistency (htmlFor).
  • Verify the key name info_tooltips matches the table renderer.

Apply this minimal typing tweak:

-const data = {
+const data = {
   name: "Label",
   ...
-};
+} as const;
src/components/ui/Label/Label.tsx (1)

6-6: Export COMPONENT_NAME for consistency (optional).

Other components (e.g., Progress) export this; doing the same helps tooling/tests reuse it.

-const COMPONENT_NAME = 'Label';
+export const COMPONENT_NAME = 'Label';
src/components/ui/Label/tests/Label.test.tsx (1)

21-33: Focus behavior test LGTM; consider adding a ref test (optional).

Add a small test to assert ref is forwarded to HTMLLabelElement.

+    test('forwards ref to HTMLLabelElement', () => {
+        const ref = React.createRef<HTMLLabelElement>();
+        render(<Label ref={ref}>X</Label>);
+        expect(ref.current).toBeInstanceOf(HTMLLabelElement);
+    });
docs/app/docs/components/label/page.mdx (2)

26-33: Defensive rendering when API data is missing.

If api_documentation.label ever fails to load, the page will crash. Render the table conditionally.

-  <Documentation.Table
-    title="Label"
-    description={api_documentation.label.description}
-    columns={api_documentation.label.columns}
-    data={api_documentation.label.data}
-  />
+  {api_documentation?.label && (
+    <Documentation.Table
+      title="Label"
+      description={api_documentation.label.description}
+      columns={api_documentation.label.columns}
+      data={api_documentation.label.data}
+    />
+  )}

14-19: Optional: Include nested-label example for completeness.

Add a second snippet showing the “wrap input with label” pattern, which is also valid a11y-wise.

docs/app/docs/components/label/docs/codeUsage.js (2)

8-10: Confirm base class alignment with component markup.

The CSS targets .rad-ui-label. Verify the Label component renders this class by default; otherwise the example won’t style anything. If not default, show className="rad-ui-label" in the JS snippet or adjust the selector to the actual base class.

-        code: `import Label from "@radui/ui/Label"\n\nconst LabelExample = () => (\n    <div>\n        <Label htmlFor="email">Email</Label>\n        <input id="email" type="email" />\n    </div>\n)`,
+        code: `import Label from "@radui/ui/Label"\n\nconst LabelExample = () => (\n    <div>\n        <Label className="rad-ui-label" htmlFor="email">Email</Label>\n        <input id="email" type="email" />\n    </div>\n)`,

18-24: Optional: Expand features with keyboard and nesting behavior.

Consider adding bullets for “associates via nesting without htmlFor/id” and “supports focusing via keyboard (Space/Enter)” to set correct expectations.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d1d3f15 and 88a4cbf.

📒 Files selected for processing (10)
  • docs/app/docs/components/label/docs/codeUsage.js (1 hunks)
  • docs/app/docs/components/label/docs/component_api/label.tsx (1 hunks)
  • docs/app/docs/components/label/page.mdx (1 hunks)
  • docs/app/docs/components/label/seo.ts (1 hunks)
  • docs/app/docs/docsNavigationSections.tsx (1 hunks)
  • scripts/RELEASED_COMPONENTS.cjs (1 hunks)
  • src/components/ui/Label/Label.tsx (1 hunks)
  • src/components/ui/Label/tests/Label.test.tsx (1 hunks)
  • styles/themes/components/label.scss (1 hunks)
  • styles/themes/default.scss (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
docs/**/*.{ts,tsx}

📄 CodeRabbit inference engine (docs/.cursor/rules/posthog-integration.mdc)

In TypeScript, store feature flag names in an enum

Files:

  • docs/app/docs/components/label/seo.ts
  • docs/app/docs/docsNavigationSections.tsx
  • docs/app/docs/components/label/docs/component_api/label.tsx
docs/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (docs/.cursor/rules/posthog-integration.mdc)

docs/**/*.{ts,tsx,js,jsx}: Write enum/const object members for feature flag names in UPPERCASE_WITH_UNDERSCORE
Gate flag-dependent code with a check that verifies the flag’s values are valid and expected before use
If a custom person/event property is referenced in two or more places, define it in a central enum (TS) or const object (JS) and reuse that reference

Files:

  • docs/app/docs/components/label/seo.ts
  • docs/app/docs/docsNavigationSections.tsx
  • docs/app/docs/components/label/docs/component_api/label.tsx
  • docs/app/docs/components/label/docs/codeUsage.js
docs/**/*.{js,jsx}

📄 CodeRabbit inference engine (docs/.cursor/rules/posthog-integration.mdc)

In JavaScript, store feature flag names as strings in a constant object to simulate an enum, and use a consistent naming convention

Files:

  • docs/app/docs/components/label/docs/codeUsage.js
🧬 Code graph analysis (1)
src/components/ui/Label/Label.tsx (1)
src/components/ui/Progress/Progress.tsx (1)
  • COMPONENT_NAME (8-8)
⏰ 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). (2)
  • GitHub Check: coverage
  • GitHub Check: build
🔇 Additional comments (5)
styles/themes/default.scss (1)

19-19: Theme import placement LGTM.

The new @use aligns with existing components and should make .rad-ui-label available.

scripts/RELEASED_COMPONENTS.cjs (1)

19-20: Release listing update LGTM.

Placement between Kbd and Progress matches the docs/nav order.

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

19-25: Confirm theme class mapping.

Ensure customClassSwitcher(customRootClass, 'Label') resolves to the .rad-ui-label class so theme styles apply.

src/components/ui/Label/tests/Label.test.tsx (1)

10-19: Association test LGTM.

Covers htmlFor linkage correctly.

docs/app/docs/components/label/page.mdx (1)

3-3: @radui/ui/Label import is consistent with all other component imports; no change needed.

@@ -0,0 +1,26 @@
// Import API documentation
import label_api_SourceCode from './component_api/label.tsx';
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

Avoid importing TSX with explicit extension from JS.

Explicit “.tsx” in JS imports can fail depending on module resolution. Prefer extensionless import.

-import label_api_SourceCode from './component_api/label.tsx';
+import label_api_SourceCode from './component_api/label';
📝 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
import label_api_SourceCode from './component_api/label.tsx';
import label_api_SourceCode from './component_api/label';
🤖 Prompt for AI Agents
In docs/app/docs/components/label/docs/codeUsage.js around line 2, the import
uses an explicit “.tsx” extension (import label_api_SourceCode from
'./component_api/label.tsx';) which can break in JS module resolution; change it
to an extensionless import (import label_api_SourceCode from
'./component_api/label';) and ensure the build/tsconfig supports resolving
.tsx/.ts via index or appropriate resolver so the same module is found without
the explicit extension.

Comment on lines +6 to +7
code: `import Label from "@radui/ui/Label"\n\nconst LabelExample = () => (\n <div>\n <Label htmlFor="email">Email</Label>\n <input id="email" type="email" />\n </div>\n)`,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Keep docs import path consistent with package scope.

Ensure the usage snippet’s @radui/ui/Label path matches the actual published entry point (scope and subpath). Update if your repo standard is different.


🏁 Script executed:

#!/bin/bash
# Inspect package.json exports to confirm Label entry
fd package.json | xargs -I{} jq -r '.name, .exports' {} 2>/dev/null | sed -n '1,120p'

Length of output: 24


🏁 Script executed:

#!/bin/bash
# List all package.json files to locate @radui/ui package.json
find . -type f -name package.json

Length of output: 34


🏁 Script executed:

#!/bin/bash
# Show main and exports in root package.json
jq '{main: .main, exports: .exports}' package.json

Length of output: 37


Use package root import for Label

In docs/app/docs/components/label/docs/codeUsage.js (lines 6–7), replace

import Label from "@radui/ui/Label"

with

import Label from "@radui/ui"

to match the package’s published entry point.

🤖 Prompt for AI Agents
In docs/app/docs/components/label/docs/codeUsage.js around lines 6 to 7, the
import uses the internal path "@radui/ui/Label" instead of the package root;
change the import to use the published entry point by replacing the named path
with the package root import "@radui/ui" so the example aligns with the
package's public API.

@@ -0,0 +1,34 @@
'use client';
import React, { ElementRef, ComponentPropsWithoutRef } from 'react';
import { clsx } from 'clsx';
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Incorrect clsx import will break build.

clsx has a default export; named import { clsx } is undefined in typical setups.

Apply this fix:

-import { clsx } from 'clsx';
+import clsx from 'clsx';
🤖 Prompt for AI Agents
In src/components/ui/Label/Label.tsx around line 3, the import uses a named
import "import { clsx } from 'clsx';" which will be undefined; replace it with
the default import "import clsx from 'clsx';" so the module resolves correctly
and the build won't fail.

@kotAPI kotAPI removed the codex label Nov 18, 2025
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