angular / angular/components

feat(autocomplete): Multiselect (chips input)

Open
#25,999 1 comment 5 reactions 0 assignees View on GitHub
area: material/autocomplete feature P4
Dominant language
TypeScript
Stars
25k
Forks
6.8k
Avg merge
1d 8h
Merged PRs (30d)
91

Description

### Feature Description

Ability to select multiple entries from autocomplete.
https://material.angular.io/components/autocomplete/overview

### Use Case

For example when using with chips.
![multi-chip-select](https://user-images.githubusercontent.com/60390085/202438855-1b2226ba-a050-489b-b4a1-bc3bc383bbb7.gif)

Btw. it would be also nice if the chip select does not wrap and scroll horizontal instead or truncate (overflow hidden) with annotation of count of additional chips like `(Chip 1) (Chip 2) +3` (means 5 chips, 2 visible, 3 hidden to prevent wrapping / changing height of input). Not tested but mabye the autocomplete select position may not updated when the input height is change while the overlay (list) is displayed.

Update: Ok this can be achieved by adding `mat-checkbox` to the options. So this feature request is maybe more about to add an example to the docs. Or what do you mean? It's maybe not that easy. The checkbox checked state must be synced with the selected chips. Also prevent closing autocomplete by click. preventDefault or stopPropagation doesn't work. etc.

https://material.angular.io/components/chips/examples

Update: Another quick solution would be to just keep the autocomplete list overlay open while click on items to add to the chip list.

Update: [Here](https://stackblitz.com/edit/angular-sx79hu-urvop3?file=app/multiselect-autocomplete-example.html) is an example. It's not from me, it's forked and might be polished. Just for inpriation. For example you need a div inside the option with click event to prevent close (stopPropagation/preventDefault). We can optimize this and add it to the examples. But since this is a little bit "hackish" we should consider to officially support this. Or give options to prevent close etc. I would not use a wrapper object for `selected` property. I would just bind checked to a method to check if value array includes item. And pointer-events none for the mat-checkbox (toggle only by option itself).

Contributor guide

Open the contributing guide

Research direction

Start with the Angular Material autocomplete and chips documentation linked in the issue, then review the referenced StackBlitz example. Establish whether the goal is an officially supported multiselect behavior, an option to keep the overlay open, or only a documentation example. Done should include an agreed scope and corresponding example or API behavior, with tests and documentation updated as needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.