-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Autocomplete with multiple selection (MdAutocompleteTrigger customization) #5053
Comments
@jelbourn Is someone planning to work on a multiple autocomplete? Or would you be open to me creating a new |
No plans to work on this, would need some discussion to determine if we want to add it to the library. The a11y would be problematic since an autocomplete is a |
@jelbourn Don't know much about a11y, but |
A listbox doesn't have a text input like autocomplete does. See https://www.w3.org/TR/wai-aria/roles#combobox Looks like combobox theoretically supports being associated with a listbox with multiple selection, but it would need some testing; screen-readers are often "best effort" on certain boundary cases in the spec |
I am also in need of this function. Either a customization or a new component "multi-search-select" will work. I would imagine something close to this, https://semantic-ui.com/modules/dropdown.html#multiple-search-selection |
It is good to have functionality especially in corporate application where there is always a need of this component |
I want this :) I created own component, but good to see native implementation :) |
@PawelOwczarekFalcon is your component open sourced? :) |
@Aaron-Zhao The Semantic UI example is functionally more like chips with an autocomplete. However, if you want it to look more like Semantic UI you'll need to do some re-styling with CSS. IMO, the advantage of Chips + Autocomplete is that you clearly see all selected values. However, it takes much more space. The advantage of the Autocomplete+multiple hack I created is that it takes less space. However, it's a bit confusing to users. The fundamental problem is that the input text is your search AND the display of selected values (after blur), which is confusing. And there's also the accessibility issues that @jelbourn mentioned. So I think going with Chips+Autocomplete is probably better. @jelbourn I'm tempted to close this issue unless someone has a design for multiple+Autocomplete that isn't equivalent to Chips+Autocomplete. |
@arlowhite What about extending the mat-select to be searchable/filterable while multiple selection is enabled. Does that accomplish the same purpose? There's a pr open for a mat-select-header #7835 where you could add a search input to filter the options. The author of the pull requests is waiting for feedback because I think he want's to make sure @jelbourn's a11y concerns are addressed. |
@jrood |
Here is how i handled it https://stackblitz.com/edit/angular-v1b716 |
This is how i implemented https://stackblitz.com/edit/angular-xgtey4 using mat-chips, mat-autocomplete. |
i took a reference from your solution. could you let us know how to bind the selected values as in mat select like for e.g. i tried ([value])="somearray" |
Feature proposal:
It would be nice if
MdAutocomplete
andMdAutocompleteTrigger
supported themultiple
attribute similar toMdSelect
, or at least configuration options that make creating your own easier.What is the expected behavior?
It should be possible to create an Autocomplete with multiple selection.
What is the current behavior?
MdAutocompleteTrigger
is coded to assume single selection and is not easily customized, which makes a custom multi-autocomplete difficult to develop. Currently, you must "monkey-patch" private methods inMdAutocompleteTrigger
.Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Is there anything else we should know?
Here are my notes on the major issues I encountered in developing my own multiple Autocomplete.
In
ngAfterContentInit
, I "monkey-patch"MdAutocompleteTrigger
. You cannot extendMdAutocompleteTrigger
because these methods are private.The objective here is to:
MdOption
s on selectionEDIT updated for beta12
Also, while working on this, I noticed that the code I was writing was very similar to
MdSelect
and most of the logic is inMdAutocompleteTrigger
. So maybe what's needed is a newMdMultiAutocompleteTrigger
, which uses the sameSelectionModel
system thatMdSelect
uses.The one other issue is that even with
ngFor trackBy
sometimesMdOption
instances lose their selected state. So every time the options are filtered, I double-checkMdOption.selected
and select() deselect() as necessary.Also, the way
MdSelect
setsMdOption.multiple
seems awkward, but I basically do the same thing as theMdSelect
code.FYI, my solution for displaying multiple values is just to clear the input, floatPlaceholder='never' and set placeholder to the
displayWith()
of each selected value separated by commas. This works fairly well. I also added a tooltip with the same content in case the entire text is not visible.The text was updated successfully, but these errors were encountered: