Skip to content

Roll out attrs passthrough to Select, Textarea, FormField #76

Closed

Description

@fsecada01

Background

Button got attrs passthrough via #72 (spike) → #73 (implementation), and #70 tracks the remaining rollout to the rest of the interactive primitives. This issue narrows to the next three: Select, Textarea, FormField.

Current state

None of the three declare attrs on either engine — RESERVED_ATTRS in primitives.py has exactly one key ("button").

Wrapper-vs-control ambiguity (the design question #70 flagged)

All three render more than one element, and a caller's attribute almost always means the control, not the outer wrapper:

  • Select.jinja / select.html: outer <div class="field"> wrapper, inner <div class="select">, and the actual <select> control
  • Textarea.jinja / textarea.html: outer <div class="field"> wrapper, inner <div class="control">, and the actual <textarea> control
  • FormField.jinja / form-field.html: same wrapper/control split

hx-*, x-*, @click, data-*, aria-* etc. belong on the control element (<select>/<textarea>/the field's input) in every real-world case identified in #70 — not on the <div class="field"> wrapper.

Suggested approach

Follow #73's precedent for Button:

  • Add attrs={} / attrs="{}" as a prop on each Jinja {#def} and each cotton <c-vars>
  • Add a RESERVED_ATTRS entry per primitive, listing the attributes it already renders itself (so attrs can't silently duplicate/override id, name, class, etc.)
  • Route through the existing render_attrs() / cf_ui_render_attrs machinery — no new escaping or validation logic needed, it's engine-agnostic already
  • Place the rendered attrs on the control element identified above, not the wrapper

Suggested tests

Per component, per engine (mirroring #73's test_cf_ui_class_tag.py / attrs tests for Button):

  • An undeclared attribute reaches the control element, not the wrapper
  • A declared prop (class, name, id) passed through attrs is rejected with a clear error, not silently duplicated
  • Attribute values containing quotes/< are escaped
  • Verified through the real compiler on the cotton side (render_to_string on a theme partial bypasses <c-vars> — see repo CLAUDE.md), not just unit tests

Scope

This issue is select + textarea + form-field only. checkbox-group, icon, badge, box remain tracked under #70's broader scope for a later pass.

Related: #70, #73

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions