material-components / material-components/material-components-android

[Chip] Request: add ability to set chip as checked/unchecked but not by the user

Open
#4,143 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request Widget: Chip
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**
In some cases, I want to be able to let the user press the Chip, but not to let it be toggled of being checked/unchecked due to it.
I want to decide when to have it be checked, and by which event (which might not be clicking on it, for example).

**Describe the solution you'd like**
Maybe have function "setCheckableByUser", and so in this case I would pass "false" to it.

**Describe alternatives you've considered**
I tried to use this:

```
chip.isCheckable=false
chip.isChecked = true
```

But it didn't let me check the chip.
And, using setOnClickListener when isCheckable is true means that the value I get is the new one, after it was toggled.

It could also be nice to be able to set a chip as checked/unchecked without triggering the setOnCheckedChangeListener.
Currently in order to do it, I will probably have to extend Chip and have the same thing I had to do here:
https://stackoverflow.com/a/27391245/878126

**Additional context**
https://developer.android.com/reference/com/google/android/material/chip/Chip

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Android Chip reference and trace the existing isCheckable, isChecked, click, and setOnCheckedChangeListener behavior. Define the API semantics for user-driven versus programmatic checking, including whether programmatic changes notify listeners, then add the corresponding behavior and tests before verifying the documented Chip use case.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.