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

[Tabs] Somewhat lacking types for Tabs #3239

Open
mochetts opened this issue Nov 20, 2024 · 0 comments
Open

[Tabs] Somewhat lacking types for Tabs #3239

mochetts opened this issue Nov 20, 2024 · 0 comments

Comments

@mochetts
Copy link

mochetts commented Nov 20, 2024

Feature request

Overview

The tabs component takes a value prop and a onValueChange callback with these types:

Screenshot 2024-11-20 at 3 10 10 PM

It would be ideal to use generic types to infer the type of the onValueChange value prop.

Imagine we have the following:

type Tab = "someTab" | "someOtherTab"

const [tab, setTab] = useState<Tab>("someTab")

When declaring the Tabs component this is needed to be done in order to be type compliant:

<Tabs value={tab} onValueChange={(value) => setTab(value as Tab)}>
...
</Tabs>

An improvement could be to use generic types so that this piece of code gets shorthanded:

<Tabs value={tab} onValueChange={setTab}>

Proposed type declaration

export interface TabsProps<T> extends PrimitiveDivProps {
    /** The value for the selected tab, if controlled */
    value?: T;
    /** The value of the tab to select by default, if uncontrolled */
    defaultValue?: T;
    /** A function called when a new tab is selected */
    onValueChange?: (value: T) => void;
    ...
}

Examples in other libraries

n/a

Who does this impact? Who is this for?

Folks using typescript

Additional context

n/a

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

No branches or pull requests

1 participant