-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Feature request: search/filter in select #5697
Comments
@xuanshenbo, have you try a function to validate selection of the md-autocomplete at the |
This is something we do plan on supporting eventually (similar to the |
This would be really useful, because currently md-select is veery poorly usable for long lists (e.g. country list) when compared to regular , because with the latter, you can hit the letter and jump to the items beginning with that letter. In md-select this is not an option and many developers are not willing to accept this as good UX in their applications :( |
Hey guys. Thanks for this great library of Material Components. Could you please add this feature in your roadmap? I believe it is important functionality, as most have already mentioned, and a must have in a long list. Also, it would be great if the filtering function could be defined by us (return true or false). @crisbeto @devversion @amcdnl @mmalerba @andrewseguin @jelbourn |
I have implemented this capability as a wrapper around mat-autocomplete - and as a base class that can easily be reused to make visual variations. Repository and demo link below. https://github.com/OasisDigital/angular-material-obs-autocomplete https://oasisdigital.github.io/angular-material-obs-autocomplete/ I am very interested in ideas in how I could reshape this work, in to the form of a component or similar thing to offer as a PR. Maybe the pair-of-functions that my solution uses, could be reshaped to something more like a mat-grid's DataSource ? |
See https://github.com/bithost-gmbh/ngx-mat-select-search @jelbourn @crisbeto might this be worth filing as a PR once #2812 / #7835 is ready? |
@macjohnny this is great! However, it has a strange behavior when using the "multiple" attribute of the mat-select. When filtering and then selecting a value from the filtered list, it overrides and removes the previously selected values, which is not the desired behavior. Other then that it's great! |
@eyalhakim Thanks for your feedback. I added an example with
so now it should also work correctly with |
@macjohnny works perfectly! thank you. I would also suggest using Would appreciate if you release this as an npm package. |
@macjohnny Same here, I would be delighted to use your component if your release it as an NPM package while waiting for the official implementation by the Angular team. |
@macjohnny I am planning on using your mat-select-search component but I dont know how to use it to pre-select a value, for example, I already entered a value previously and when I try to show this component, I want to show the value preselected. I am able to filter the values, the dropdown shows only the filtered item but it doesnt show on the input unless I select the dropdown and select the value again. Any help would be much appreciated. |
@eyalhakim thanks for your feedback. I adapted the code to use @eyalhakim @kevin-anidjar I will try to publish it as an npm package this week. @speddi due to the use of the ngOnInit() {
// set initial selection
this.bankCtrl.setValue(this.banks[1]);
...
}
ngAfterViewInit() {
this.setInitialValue();
}
/**
* Sets the initial value after the filteredBanks are loaded initially
*/
private setInitialValue() {
this.filteredBanks
.pipe(take(1), takeUntil(this._onDestroy))
.subscribe(() => {
// setting the compareWith property to a comparison function
// triggers initializing the selection according to the initial value of
// the form control (i.e. _initializeSelection())
// this needs to be done after the filteredBanks are loaded initially
// and after the mat-option elements are available
this.singleSelect.compareWith = (a: Bank, b: Bank) => a.id === b.id;
});
} |
Thank you @macjohnny for your time. |
@macjohnny - would be useful to see this released formally with some sort of license. Can't really use it until then which is a shame as it's a solid looking implementation. |
@artparks @speddi @eyalhakim @kevin-anidjar
See https://github.com/bithost-gmbh/ngx-mat-select-search for docs and issues / improvements. See it in action at https://stackblitz.com/github/bithost-gmbh/ngx-mat-select-search-example |
@macjohnny thank for awesome code... it's helped me. |
@macjohnny Such an awesome work! An example is shown here: https://stackblitz.com/edit/github-g1zbuf?embed=1&file=src/app/app.component.html Could you please check that case? |
@joqkey thanks for your feedback. could you please move your issue to https://github.com/bithost-gmbh/ngx-mat-select-search/issues ? |
This feature will be added to angular material2 ? Or stay in ngx-mat-select-search ? |
Here is how i handled it. I used mat-autocomplete instead of mat-select https://stackblitz.com/edit/angular-v1b716 |
Very interested in this! |
Would be great to have this feature please add it. |
Recently needed this functionality as well. Here's how to hack around it using an autocomplete: https://stackblitz.com/edit/angular-mm8n12?file=src/app/autocomplete-filter-example.ts For a more full featured solution, check https://github.com/bithost-gmbh/ngx-mat-select-search |
Kinda strange this feature is not yet implemented officially in the world of this great framework. |
Agreed. This is a super helpful feature that I use a lot in an intranet application. I had originally gone with my own solution until I discovered that https://www.npmjs.com/package/ngx-mat-select-search https://github.com/bithost-gmbh/ngx-mat-select-search |
I have a usecase where i will select all in dropdown and i need to display only 3 options and rest it should show "4 More.." |
I created a reusable SelectSearchDropdown component that utilizes Angular Material's select. |
I have made a reusable component 'MatSelectSearch' to select/filter the mat-options. It's easy to use. https://www.npmjs.com/package/mat-select-search See it in action here: https://stackblitz.com/github/shafi-sahal/MatSelectSearch |
Nice but what for, if we have |
Thanks for your feedback!! And the scrolling is not meant to be a bug. It's useful sometimes, especially for mobile devices. If the input never scrolls up and if a user prefers scrolling, it's just a waste of space I think. Anyway, the input never loses focus and if you just hit a key the input reappears and searches. Anyway, what I am thinking is to make an Input to the component to specify whether you want the input to be scrolled or not. Feel free to tell me about any suggestions, problems, or feedback. |
Thanks for this, it comes in handy when you have many dropdowns in a form ( individual handling of each dropdown becomes a lot of boilerplate). However, if you could include "select All" in the multiple selection that would bring it to perfection. Also , when using multiple, the checkbox and the labels do not align |
Thank you so much for the feedback!!! |
A new version of MatSelectSearch is published with the requirements you have suggested. MatSelectSearch 1.0.2 link: https://www.npmjs.com/package/mat-select-search |
Is there any 3rd party lib that uses By blackbox, I mean, that you can just specify it in the template, without the need to maintain the I know I can wrap Something like this:
And that would be it. Similar to a normal I guess, internally it would need to:
My point is, I don't want to repeatedly do the My actual use case is much more complex. I'm writing a wrapped lib that can dynamically switch out different UI libs (Angular Material, Ionic, ngPrime... whatever), with a combination of dynamic components and template outlets. So I need a clean "meta" interface, that doesn't rely on having lists and subjects in the ts files backing up the template. There are alternatives, of course, like doing the steps above myself. But if there is something already out there, it would save me a lot of time, Also, it would need to support multiple selection and option groups. |
@zolakt I would like to consider that but I don't know about the concepts you mentioned in detail to implement them. Could you help with it :) ? |
@shafi-sahal I've implemented my approach, but my use case is complex. I don't have time right now to streamline it out into something simpler. I'll try to do it and post it when I have some time. But in general, it's the approach I mentioned above: It's a little messy since I can't get the text of the mat-option cleanly. Instead I need to parse it from nativeElement. But it works. |
..... 6 years...... just saying |
Since no one has lifted a finger regarding this for a few years now, it will be at least 6 more... They have removed the "under consideration" tag. That is the max effort they are willing to put in. As far as they are concerned they are safe for the next 5 years. Common pattern on way too many issue reports... @cjsase and the gang, downvote away.... If you would spend half the time on fixing bugs as you spend on downvoting people, maybe you would actually fix a bug every once in a while |
Any update on this since 2018? This is such a fundamental feature I'm very surprised Angular has not taken care of this as it is an otherwise great framework. I will be using ngx-mat-select-search for the time being. |
Any movement or plans to move this forward? |
Same, will be using ngx-mat-select-search for the time being. |
7 years... for a basic function. It's not hard to see why angular is so bad these days |
Bug, feature request, or proposal:
Feature request
What is the expected behavior?
User able to search/filter the options in a select
What is the current behavior?
User must scroll the select to find the desired option
What is the use-case or motivation for changing an existing behavior?
When there is a long list of options, it's not easy to find an option
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Latest Angular Material as of 12 July 2017
Is there anything else we should know?
This is different from autocomplete, autocomplete is a free-text input field.
I haven't found anything in Material Design related to this, but this could be an important feature
The text was updated successfully, but these errors were encountered: