Skip to content

fix(filter): setValue prop type#1888

Open
viniciuslagedo wants to merge 3 commits intomainfrom
fix/filter-set-value
Open

fix(filter): setValue prop type#1888
viniciuslagedo wants to merge 3 commits intomainfrom
fix/filter-set-value

Conversation

@viniciuslagedo
Copy link
Copy Markdown
Contributor

Summary

Resolves #1504

Examples

We have made a significant improvement in terms of consistency for those using the component. The types can be assumed based on props if you are using a multi- or single-value filter. So, if you pass a callback using an array of strings, it infers the value prop and the default value with the same type. Besides that, it is now possible to use custom handles on the setValue prop.

type Props = {
  onFilterChange: (value: string[]) => void
  filterValue: string[]
  defaultFilterValue: string[]
}

const MyFilter = (props: Props) => {
  const { onFilterChange, defaultFilterValue, filterValue } = props

  return (
    <Filter
        value={filterValue} // Based on setValue prop it infers the string[] type here
        setValue={onFilterChange} // No more type errors here
        label="Multiple status"
        defaultValue={defaultFilterValue} // Based on setValue prop it infers the string[] type here
      >
      <FilterItem value="Stable">Stable</FilterItem>
      <FilterItem value="Experimental">Experimental</FilterItem>
      <FilterItem value="Deprecated">Deprecated</FilterItem>
    </Filter>
  )
}

Change component to generic typed Value, defaulting to string. Infers type from value, setValue,
defaultValue.
We need to use the same behavior from filter provider here because of most part of props came from
it.
@viniciuslagedo viniciuslagedo requested a review from a team as a code owner August 26, 2024 18:24
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Aug 26, 2024

Deployment failed with the following error:

You don't have permission to create a Preview Deployment for this project.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Filter: setValue prop

1 participant