Skip to content

[Switch] Add use client directive, forward form props, and fix ref type #641

@ravisuhag

Description

@ravisuhag

Summary

Switch wraps Base UI's Switch primitive. Missing 'use client' directive, form-related props, and has an incorrect ref type.

Improvements

1. Add 'use client' directive

Missing for Next.js App Router compatibility. Checkbox has it; Switch doesn't.

2. Forward value and name props for form integration

Switch doesn't support value or name props, breaking native HTML form submission. Base UI supports these.

3. Fix ref type signature

Currently wraps the component with the deprecated forwardRef API. Should accept ref as a regular prop with the proper element type matching Base UI's SwitchPrimitive.Root.

4. Forward readOnly prop

Documented in props.ts but not exposed in the component's TypeScript interface.

5. Replace hardcoded pixel values in CSS

Transform values (16px, 12px) and thumb dimensions are hardcoded instead of using design tokens.

Props Not Forwarded from Base UI

Base UI Prop Status Notes
value Missing Required for form submission
name Missing Required for form identification
readOnly Missing Documented but not exposed
render Missing Custom rendering support

Files

  • packages/raystack/raystack/components/switch/

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions