Skip to content

fix(types): allow TanStack Form onChange/onBlur to target textarea elements#186

Merged
eduardoborges merged 1 commit into
mainfrom
claude/github-pr-review-qd9n9q
Jul 2, 2026
Merged

fix(types): allow TanStack Form onChange/onBlur to target textarea elements#186
eduardoborges merged 1 commit into
mainfrom
claude/github-pr-review-qd9n9q

Conversation

@eduardoborges

@eduardoborges eduardoborges commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Summary

Follow-up to #184. That PR fixed #183 (implicit any on the TanStack Form onChange event) by pinning TanStackFormInputProps.onChange/onBlur to ChangeEvent<HTMLInputElement>/FocusEvent<HTMLInputElement>.

use-mask-input also supports masking <textarea> elements (see maskHelpers.ts, which handles HTMLInputElement | HTMLTextAreaElement throughout). Pinning the event type to HTMLInputElement only mistyped the inline event parameter for anyone masking a <textarea> field, and broke consumers who explicitly annotate their handler for either element type.

Fix

onChange/onBlur are now declared with method shorthand syntax and widened to ChangeEvent<HTMLInputElement | HTMLTextAreaElement> / FocusEvent<HTMLInputElement | HTMLTextAreaElement>. Method shorthand makes the parameter checked bivariantly, so:

  • the common inline, unannotated handler (onChange: (event) => field.handleChange(event.target.value)) infers correctly for both input and textarea fields,
  • a handler explicitly annotated ChangeEvent<HTMLInputElement> (e.g. reading event.target.files) stays assignable, and
  • a handler explicitly annotated ChangeEvent<HTMLTextAreaElement> (e.g. reading event.target.cols) also stays assignable.

(An earlier revision of this PR used a plain union type instead of method shorthand, which broke the input-only case — thanks to @chatgpt-codex-connector for catching that in review.)

Tests

  • New useTanStackFormMask tests covering: a masked <textarea> field with an inline handler, and a handler explicitly typed for HTMLInputElement-only members (.files).

Verification

  • tsc --noEmit: clean
  • Tests: 167 passing (was 165 on main)
  • Lint + build: green
  • Verified in a standalone project outside the monorepo (packed the built package with npm pack, installed via file:) that the original e is type any on tanstack form #183 repro, a masked textarea field, and an explicitly-typed input-only handler all type-check correctly.

A changeset (patch) is included.

@changeset-bot

changeset-bot Bot commented Jul 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 63a7712

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
use-mask-input Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Bundle Report

Changes will increase total bundle size by 36 bytes (0.03%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
use-mask-input-esm 133.36kB 36 bytes (0.03%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: use-mask-input-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
index-Do9euvWK.d.mts (New) 31.72kB 31.72kB 100.0% 🚀
index-8uxCFRY6.d.mts (Deleted) -31.68kB 0 bytes -100.0% 🗑️

@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.47%. Comparing base (f20a510) to head (63a7712).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #186   +/-   ##
=======================================
  Coverage   98.47%   98.47%           
=======================================
  Files          15       15           
  Lines         262      262           
  Branches       68       71    +3     
=======================================
  Hits          258      258           
  Misses          4        4           
Flag Coverage Δ
unit 98.47% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
core 98.07% <ø> (ø)
react-hook-form 100.00% <ø> (ø)
tanstack-form 100.00% <ø> (ø)
antd 97.61% <ø> (ø)
utils 97.72% <ø> (ø)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f20a510...63a7712. Read the comment docs.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6e36db8e45

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +50 to +51
onChange?: (event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
onBlur?: (event: FocusEvent<HTMLInputElement | HTMLTextAreaElement>) => void;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve input-only TanStack handlers

With strictFunctionTypes enabled (including consumers using strict), this union makes the callback type require a handler that can accept both input and textarea events. Existing masked <input> usage that annotates onChange as ChangeEvent<HTMLInputElement> or reads input-only fields such as event.target.files now fails with TS2322 even though it never renders a textarea; the previous signature accepted those handlers. Please model the element type generically/with overloads or a bivariant handler instead of replacing the input event parameter with a union.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Good catch. Fixed by switching onChange/onBlur to method-shorthand signatures instead of a plain union, so both HTMLInputElement-only and HTMLTextAreaElement-only annotated handlers stay assignable (bivariant parameter checking), alongside the inline unannotated case. Added a test covering the HTMLInputElement-only (event.target.files) scenario. See the latest commit.


Generated by Claude Code

…ements

PR #184 pinned TanStackFormInputProps' onChange/onBlur to
ChangeEvent<HTMLInputElement>/FocusEvent<HTMLInputElement>, but use-mask-input
also masks <textarea> elements. Widen both to
ChangeEvent<HTMLInputElement | HTMLTextAreaElement> /
FocusEvent<HTMLInputElement | HTMLTextAreaElement>, declared with method
shorthand so the parameter is checked bivariantly: handlers explicitly typed
for just HTMLInputElement (e.g. reading event.target.files) or just
HTMLTextAreaElement (e.g. event.target.cols) both stay assignable, alongside
the common inline unannotated handler.
@eduardoborges
eduardoborges force-pushed the claude/github-pr-review-qd9n9q branch from 6e36db8 to 63a7712 Compare July 1, 2026 13:28
@eduardoborges
eduardoborges merged commit 6b38852 into main Jul 2, 2026
17 checks passed
@eduardoborges
eduardoborges deleted the claude/github-pr-review-qd9n9q branch July 2, 2026 00:26
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.

e is type any on tanstack form

1 participant