Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Slider] value type should narrow onValueChange value type #1230

Open
aarongarciah opened this issue Dec 25, 2024 · 0 comments
Open

[Slider] value type should narrow onValueChange value type #1230

aarongarciah opened this issue Dec 25, 2024 · 0 comments
Labels
component: slider This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature

Comments

@aarongarciah
Copy link
Member

aarongarciah commented Dec 25, 2024

Feature request

Summary

The Slider accepts values of type Array<number> | number but the onValueChange and onValueCommitted callbacks don't narrow the type of the value parameter to number or Array<number> and users need to type cast it manually.

Example of code throwing a TS error:

//  ❌ Argument of type 'number | number[]' is not assignable to parameter of type 'SetStateAction<number>'.
//    Type 'number[]' is not assignable to type 'SetStateAction<number>'.

const [value, setValue] = React.useState(25);
<Slider.Root value={value} onValueChange={(value) => setValue(value}>

Example of type casting needed to overcome the TS error:

const [value, setValue] = React.useState(25);
<Slider.Root value={value} onValueChange={(value) => setValue(value as number}>

Motivation

Avoid users needing to do manual type casting.

@aarongarciah aarongarciah added component: slider This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature labels Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: slider This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature
Projects
None yet
Development

No branches or pull requests

1 participant