Skip to content
Source
Sign inSign up
TanStack/cli

fix: id attribute to Input component in (React) demo.Formcomponents.tsx.ejs #444

ClosedKonijnebeer(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/444/headopened

Hello, I noticed a accessibility issue with the TanStack Form demo component, inputs where missing an id attribute while it did have a htmlFor on the label.

What I changed

  • I added an id attribute using the label parameter to match the htmlFor

Summary by CodeRabbit

  • Bug Fixes
    • Improved form label and input field association for better accessibility and usability. Labels can now properly focus their corresponding input fields when clicked.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      📝 Walkthrough

      Walkthrough

      A single line is added to the shadcn TextField demo component, assigning id={label} to the Input element to align with the existing Label htmlFor={label} binding for proper form accessibility.

      Changes

      Form Accessibility Alignment

      Layer / File(s)Summary
      Form Component Template
      packages/create/src/frameworks/react/add-ons/form/assets/src/components/demo.FormComponents.tsx.ejs
      Input element receives id={label} prop to establish label-input association via htmlFor binding.

      Estimated code review effort

      🎯 1 (Trivial) | ⏱️ ~2 minutes

      Poem

      A label seeks its input friend, With htmlFor to bind and blend, An id appears, and lo! Form fields now harmoniously glow. 🐰

      🚥 Pre-merge checks | ✅ 5
      ✅ Passed checks (5 passed)
      Check nameStatusExplanation
      Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
      Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Title check✅ PassedThe title accurately describes the main change: adding an id attribute to the Input component in the React demo form components file.
      ✏️ Tip: You can configure your own custom pre-merge checks in the settings.
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      Tip

      💬 Introducing Slack Agent: Turn conversations into code.

      Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

      • Generate code and open pull requests
      • Plan features and break down work
      • Investigate incidents and troubleshoot customer tickets together
      • Automate recurring tasks and respond to alerts with triggers
      • Summarize progress and report instantly

      Built for teams:

      • Shared memory across your entire org—no repeating context
      • Per-thread sandboxes to safely plan and execute work
      • Governance built-in—scoped access, auditability, and budget controls

      One agent for your entire SDLC. Right inside Slack.

      👉 Get your free trial and get 200 agent minutes per Slack user (a $50 value).


      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.
    2. Caution

      Some comments are outside the diff and can’t be posted inline due to platform limitations.

      ⚠️ Outside diff range comments (1)
      packages/create/src/frameworks/react/add-ons/form/assets/src/components/demo.FormComponents.tsx.ejs (1)

      285-288: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

      Add missing id attribute to select element for label association.

      The non-shadcn Select component has the same accessibility issue that this PR fixes for the shadcn TextField: the <label> on line 285 uses htmlFor={label}, but the <select> element on line 288 is missing the corresponding id attribute.

      ♿ Proposed fix
             </label>
             <select
      +        id={label}
               name={field.name}
               value={field.state.value}
      🤖 Prompt for AI Agents
      Verify each finding against the current code and only fix it if needed.
      
      In
      `@packages/create/src/frameworks/react/add-ons/form/assets/src/components/demo.FormComponents.tsx.ejs`
      around lines 285 - 288, The <label> uses htmlFor={label} but the corresponding
      <select> is missing an id; update the <select> element in demo.FormComponents
      (the select rendered where label is used) to include id={label} so the label
      correctly associates with the select (ensure you use the same unique identifier
      variable "label" as used in the <label>).
      🧹 Nitpick comments (1)
      packages/create/src/frameworks/react/add-ons/form/assets/src/components/demo.FormComponents.tsx.ejs (1)

      45-70: ⚡ Quick win

      Consider accepting explicit id prop or sanitizing label for ID generation.

      All form components (TextField, TextArea, Slider, Switch) use the label prop directly as the DOM id. While this works for simple cases, it could cause issues if:

      • Labels contain spaces or special characters (e.g., "First Name" → id="First Name")
      • Multiple fields share the same label text (would create duplicate IDs)

      Consider one of these approaches:

      1. Accept an optional id prop with label as fallback
      2. Sanitize the label (e.g., slugify: "First Name" → "first-name")
      💡 Example: accepting optional id prop
       export function TextField({
         label,
      +  id,
         placeholder,
       }: {
         label: string
      +  id?: string
         placeholder?: string
       }) {
         const field = useFieldContext<string>()
         const errors = useStore(field.store, (state) => state.meta.errors)
      +  const inputId = id ?? label
      
         return (
           <div>
      -      <Label htmlFor={label} className="mb-2 text-xl font-bold">
      +      <Label htmlFor={inputId} className="mb-2 text-xl font-bold">
               {label}
             </Label>
             <Input
      -        id={label}
      +        id={inputId}
               value={field.state.value}

      Apply similar changes to TextArea, Slider, and Switch components.

      Also applies to: 72-97, 141-159, 161-179

      🤖 Prompt for AI Agents
      Verify each finding against the current code and only fix it if needed.
      
      In
      `@packages/create/src/frameworks/react/add-ons/form/assets/src/components/demo.FormComponents.tsx.ejs`
      around lines 45 - 70, Update TextField (and similarly TextArea, Slider, Switch)
      to accept an optional id prop and use a sanitized fallback derived from label
      when id isn’t provided: add id?: string to the component props, compute const
      fieldId = id ?? slugified(label) (use a small sanitizer/slugify helper that
      lowercases, trims, replaces spaces/special chars with hyphens and deduplicates
      hyphens), then use fieldId for Label htmlFor and the control id to avoid
      spaces/special-chars and duplicate IDs; apply the same change and helper to the
      components named TextArea, Slider, and Switch so all label→id usage is
      consistent.
      🤖 Prompt for all review comments with AI agents
      Verify each finding against the current code and only fix it if needed.
      
      Outside diff comments:
      In
      `@packages/create/src/frameworks/react/add-ons/form/assets/src/components/demo.FormComponents.tsx.ejs`:
      - Around line 285-288: The <label> uses htmlFor={label} but the corresponding
      <select> is missing an id; update the <select> element in demo.FormComponents
      (the select rendered where label is used) to include id={label} so the label
      correctly associates with the select (ensure you use the same unique identifier
      variable "label" as used in the <label>).
      
      ---
      
      Nitpick comments:
      In
      `@packages/create/src/frameworks/react/add-ons/form/assets/src/components/demo.FormComponents.tsx.ejs`:
      - Around line 45-70: Update TextField (and similarly TextArea, Slider, Switch)
      to accept an optional id prop and use a sanitized fallback derived from label
      when id isn’t provided: add id?: string to the component props, compute const
      fieldId = id ?? slugified(label) (use a small sanitizer/slugify helper that
      lowercases, trims, replaces spaces/special chars with hyphens and deduplicates
      hyphens), then use fieldId for Label htmlFor and the control id to avoid
      spaces/special-chars and duplicate IDs; apply the same change and helper to the
      components named TextArea, Slider, and Switch so all label→id usage is
      consistent.

      ℹ️ Review info
      ⚙️ Run configuration

      Configuration used: defaults

      Review profile: CHILL

      Plan: Pro

      Run ID: 3c0601a5-1841-4235-891a-83d1adee9ac0

      📥 Commits

      Reviewing files that changed from the base of the PR and between 8425b8032523d419d6abef93dd0903052254789f and 40d711487cdd61acd09fa1642b5b0236692881d1.

      📒 Files selected for processing (1)
      • packages/create/src/frameworks/react/add-ons/form/assets/src/components/demo.FormComponents.tsx.ejs
    3. Thanks for catching the missing label association! This landed in #559 with your contribution credited. It also handles repeated labels and covers focus in the generated app smoke test.

    4. tannerlinsley closed this

Sign in to join this conversation.