Skip to content

fix(TextArea): correct data.value type in onChange and onInput callbacks - #4546

Open
geeknishantkyeus wants to merge 1 commit into
Semantic-Org:masterfrom
geeknishantkyeus:fix/textarea-callback-value-type
Open

geeknishantkyeus wants to merge 1 commit into
Semantic-Org:masterfrom
geeknishantkyeus:fix/textarea-callback-value-type

Conversation

@geeknishantkyeus

Copy link
Copy Markdown

What

TextArea's onChange and onInput callbacks declared data.value as number | string | undefined, but the actual runtime value is always a string.

This PR types the callback data parameter accurately, without touching the public value prop.


Why

Runtime reality

In TextArea.js, look at handleChange:

const handleChange = (e) => {
  const newValue = _.get(e, 'target.value')
  _.invoke(props, 'onChange', e, { ...props, value: newValue })
}

e.target is a native <textarea> element. Per the HTML spec, <textarea>.value is always a string — regardless of whether the user typed a number or anything else.

So in the callback, data.value can never be a number or undefined. It is always a string.

What the type declaration said

In TextArea.d.ts:

value?: number | string

And since TextAreaProps extends StrictTextAreaProps, the callback's data.value type effectively becomes:

number | string | undefined

Impact

TypeScript users have to do unnecessary type narrowing:

<TextArea onChange={(e, data) => {
  // data.value is number | string | undefined
  // but it is always a string
  if (typeof data.value === 'string') {
    // actual code
  }
}} />

This is misleading and hurts developer experience.


How

Used an intersection type on the data parameter for onChange and onInput:

onChange?: (event: React.ChangeEvent<HTMLTextAreaElement>, data: TextAreaProps & { value: string }) => void
onInput?: (event: React.FormEvent<HTMLTextAreaElement>, data: TextAreaProps & { value: string }) => void

Why intersection (&) and why value?: number | string was not changed

  • value is an input prop — users can pass a number or a string. Changing it would be a breaking change.
  • The callback's data.value is an output — it comes from inside the component. It should be typed accurately.
  • The intersection type ensures all other TextAreaProps properties remain intact while only value is overridden.

Verification

Type-check is clean:

npx tsc --noEmit src/addons/TextArea/TextArea.d.ts

Existing tests already expect a string:

const e = { target: { value: 'name' } }  // string
onChange.should.have.been.calledWithMatch(e, { ...props, value: e.target.value })

So this change is consistent with them — no tests break.


Breaking changes

None. The value?: number | string prop is unchanged, and the callback signature is only more accurate.

@vercel

vercel Bot commented Sep 20, 2026

Copy link
Copy Markdown

@geeknishantkyeus is attempting to deploy a commit to the Semantic UI Team on Vercel.

A member of the Team first needs to authorize it.

@codecov

codecov Bot commented Sep 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.53%. Comparing base (e0a42b5) to head (b081c6d).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4546   +/-   ##
=======================================
  Coverage   99.53%   99.53%           
=======================================
  Files         186      186           
  Lines        3463     3463           
=======================================
  Hits         3447     3447           
  Misses         16       16           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
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.

1 participant