material-components / material-components-web-catalog

Catalog of Material Components for the web (MDC Web)
https://material-components.github.io/material-components-web-catalog/
Apache License 2.0
116 stars 42 forks source link

[Chips] Choice chips not working #284

Open joyzhong opened 4 years ago

joyzhong commented 4 years ago

(Copying over from issue that was originally filed as https://github.com/material-components/material-components-web/issues/5715)

Bug report

Choice chips simply don't work. If you set a chip to be selected at first, you see it, but as soon as you interact with it or others, nothing works anymore.

Steps to reproduce

  1. Go to https://material-components.github.io/material-components-web-catalog/#/component/chips
  2. Try the Choice Chips demo

Actual behavior

You can't select any chip

Expected behavior

You should be able to change the selected chip by clicking another one.

Screenshots


See this gifv

Your Environment:

Software Version(s)
MDC Web v5.1.0
Browser Chrome v80.0.3987.132
Operating System Windows 10
hljanelam commented 4 years ago

I have experienced this also and I have found out where my mistake was.

To initialize tag (e.g. int tag = 0;) for the selected choice, you need to initialize it outside the ChipsChoice widget and somewhere inside the class. My mistake was that I initialized it inside ChipsChoice widget and variable tag will always stay on the same Chip cuz unchanged, leading to the buttons not working.

Maybe you can check if you share the same problem as well. It's working fine now for me.