Skip to content

How can i reset a Select field? #638

Answered by schmoli
gmcamposano asked this question in Q&A
Discussion options

You must be logged in to vote

I did this by adding a button at the end of the list, making sure to change the key assigned to the select so that when I change the value I can force it to re render... here's a simple example:

export const SelectDemo = () => {
  const [key, setKey] = React.useState(+new Date())
  const [value, setValue] = React.useState<string | undefined>(undefined)
  return (
    <>
      <Select key={key} value={value}>
        <SelectTrigger>
          <SelectValue placeholder="Select a Theme" />
        </SelectTrigger>
        <SelectContent>
          <SelectGroup>
            <SelectLabel className="-ml-2 text-xs">Category 1</SelectLabel>
            <SelectItem value="light">Light</SelectItem>

Replies: 2 comments 9 replies

Comment options

You must be logged in to vote
7 replies
@thiagoleite92
Comment options

@Raul-digimob
Comment options

@anis-dr
Comment options

@AroyewonTemitope
Comment options

@space-symbol
Comment options

Answer selected by gmcamposano
Comment options

You must be logged in to vote
2 replies
@coderlzw-cn
Comment options

@Thanhthien94
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
10 participants