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

Select Component display wrong option after the option List related to it being changed #675

Open
YuAnWu0000 opened this issue Apr 29, 2024 · 0 comments

Comments

@YuAnWu0000
Copy link

YuAnWu0000 commented Apr 29, 2024

Here is my demo code for the issue:

import { Select, Option, Button } from '@material-tailwind/react'
import { useState } from 'react'

const Test = () => {
  const [val, setVal] = useState('option1')
  const [options, setOptions] = useState(['option1', 'option2', 'option3'])

  const changeOptions = () => {
    setOptions(['option2', 'option3'])
  }
  return (
    <>
      <Select
        label="test"
        variant="outlined"
        size="lg"
        value={val}
        onChange={(val) => setVal(val)}
      >
        {options.map((opt, index) => (
          <Option key={`opt${index}`} value={opt}>
            {opt}
          </Option>
        ))}
      </Select>
      <Button variant="filled" onClick={changeOptions} className="h-12 ml-2">
        Click me
      </Button>
    </>
  )
}
export default Test

I simply deleted option1 in the list after button clicked. Seems like Select component is not mapping the Option with the value but index now.

Can take a look at my demo video:
https://github.com/creativetimofficial/material-tailwind/assets/31946145/3e4f525e-ef75-493d-ab79-7631d3ed6b75

@YuAnWu0000 YuAnWu0000 changed the title Select Component display wrong when the Option List related to it changed Select Component display wrong option after the Option List related to it being changed Apr 29, 2024
@YuAnWu0000 YuAnWu0000 changed the title Select Component display wrong option after the Option List related to it being changed Select Component display wrong option after the option List related to it being changed Apr 29, 2024
dongsheng2014 added a commit to roadwaysmart/material-tailwind that referenced this issue Sep 8, 2024
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