Skip to content

feat(ratio-ui): type the Input family props — typed InputProps, deprecated index signature - #105

Merged
losolio merged 1 commit into
mainfrom
feat/typed-input-family-props
Aug 5, 2026
Merged

feat(ratio-ui): type the Input family props — typed InputProps, deprecated index signature#105
losolio merged 1 commit into
mainfrom
feat/typed-input-family-props

Conversation

@losolio

@losolio losolio commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

What

InputProps/InputFieldProps now extend InputHTMLAttributes<HTMLInputElement | HTMLTextAreaElement>, so every DOM prop — including onChange — is declared, autocompletes, and infers under strict without hand annotations. Requested by Ignis (only TextField was still affected; Input/Checkbox/PhoneInput were already typed).

  • The [x: string]: any escape hatch stays in 2.x for backwards compatibility, but is @deprecated for removal in the next major (that's when prop typos stop compiling).
  • Handlers annotated with the narrower element types (e.g. ChangeEvent<HTMLTextAreaElement>) remain assignable — no new errors for existing consumers.
  • TextField moves from forwardRef to a React 19 ref prop. This is load-bearing, not cosmetic: forwardRef's PropsWithoutRef collapses named props into the index signature, degrading every prop to any. Public contract unchanged (ref?: Ref<HTMLElement>).
  • Fixes the WithError story's errors shape — a real bug surfaced by the new types.

Verification

  • tsc clean for the package, plus a consumer-style type test: unannotated onChange infers (no TS7006), narrow annotations still compile, undeclared props still compile in 2.x.
  • Build + emitted .d.ts verified; changeset included (minor).

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings August 1, 2026 16:47
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Storybook preview: https://preview-105.ratio-ui.pages.dev

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR improves TypeScript ergonomics for the Input component family by making InputProps / InputFieldProps inherit standard DOM input attributes (enabling better inference/autocomplete under strict), while keeping the index-signature escape hatch for 2.x compatibility and updating TextField to React 19 “ref as a prop”.

Changes:

  • Update InputProps / InputFieldProps to extend InputHTMLAttributes<HTMLInputElement | HTMLTextAreaElement> and deprecate the [x: string]: any index signature.
  • Refactor TextField from forwardRef to a plain function component that accepts ref as a normal prop (React 19).
  • Fix Storybook WithError story errors shape to match the typed contract.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
packages/ratio-ui/src/forms/Input/TextField.tsx Refactors TextField implementation to accept ref as a prop and preserve typing across the index signature.
packages/ratio-ui/src/forms/Input/TextField.stories.tsx Aligns story errors prop shape with the typed InputFieldProps.errors contract.
packages/ratio-ui/src/forms/Input/InputProps.ts Introduces typed DOM attribute inheritance for the input family and deprecates the index signature.
.changeset/typed-input-family-props.md Documents the minor-version release notes for the typing/ref changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +102 to +106
} else if (forwardedRef && 'current' in forwardedRef) {
(forwardedRef as React.RefObject<
HTMLInputElement | HTMLTextAreaElement | null
>).current = element;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@copilot isnt MutableRefObject deprecated?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correct — MutableRefObject is deprecated in React 19. Fixed by casting to a plain writable object type { current: HTMLInputElement | HTMLTextAreaElement | null } instead. This avoids both the deprecated MutableRefObject and the readonly current on React.RefObject. Committed in 4e6cc7e.

…cated index signature

InputProps/InputFieldProps now extend InputHTMLAttributes<HTMLInputElement |
HTMLTextAreaElement>, so every DOM prop (incl. onChange) is declared,
autocompletes, and infers under strict. The [x: string]: any escape hatch
stays for 2.x but is @deprecated for removal in the next major.

TextField moves from forwardRef to a React 19 ref prop — forwardRef's
PropsWithoutRef collapses named props into the index signature, degrading
every prop to any. Public contract unchanged (ref?: Ref<HTMLElement>).

Also fixes the WithError story's errors shape, surfaced by the new types.
@losolio
losolio force-pushed the feat/typed-input-family-props branch from a8a119b to 64dccf9 Compare August 1, 2026 21:47
@losolio
losolio merged commit 95558d3 into main Aug 5, 2026
3 checks passed
@losolio
losolio deleted the feat/typed-input-family-props branch August 5, 2026 19:18
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.

3 participants