https://github.com/bithost-gmbh/ngx-mat-select-search
Angular component providing an input field for searching / filtering MatSelect options of the Angular Material library.
https://github.com/bithost-gmbh/ngx-mat-select-search
angular filter hacktoberfest material material2 search select
Last synced: about 1 month ago
JSON representation
Angular component providing an input field for searching / filtering MatSelect options of the Angular Material library.
- Host: GitHub
- URL: https://github.com/bithost-gmbh/ngx-mat-select-search
- Owner: bithost-gmbh
- License: mit
- Created: 2018-02-28T17:00:06.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-10-11T11:46:58.000Z (6 months ago)
- Last Synced: 2024-10-15T07:31:59.506Z (6 months ago)
- Topics: angular, filter, hacktoberfest, material, material2, search, select
- Language: TypeScript
- Homepage:
- Size: 2.91 MB
- Stars: 648
- Watchers: 12
- Forks: 130
- Open Issues: 21
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-material-design - ngx-mat-select-search - Select search dropdown for Angular Material (Angular / Components)
README
# NgxMatSelectSearch
[https://github.com/bithost-gmbh/ngx-mat-select-search](https://github.com/bithost-gmbh/ngx-mat-select-search)[](https://www.npmjs.com/package/ngx-mat-select-search)
[](https://www.npmjs.com/package/ngx-mat-select-search)
[](https://www.npmjs.com/package/ngx-mat-select-search)
[](https://circleci.com/gh/bithost-gmbh/ngx-mat-select-search)
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=NAX558HVGAX8Q)## What does it do?
Angular component providing an input field for searching / filtering [MatSelect](https://material.angular.io/components/select/overview) options of the [Angular Material](https://material.angular.io) library.
## Try it
See it in action at* [https://stackblitz.com/github/bithost-gmbh/ngx-mat-select-search-example](https://stackblitz.com/github/bithost-gmbh/ngx-mat-select-search-example?file=src%2Fapp%2Fapp.component.html)
see example code, builds in browser, latest version, latest material version
* [https://bithost-gmbh.github.io/ngx-mat-select-search/](https://bithost-gmbh.github.io/ngx-mat-select-search/)pre-built, latest version, material 19, works on mobile
**Important Note**: This project is meant as a temporary implementation of [https://github.com/angular/material2/issues/5697](https://github.com/angular/material2/issues/5697).
The goal is to have an implementation in the official Angular Material repository, a new PR will be created.## Contributions
Contributions are welcome, please open an issue and preferably file a pull request.### Support Development
We aim at providing the best service possible by constantly improving `NgxMatSelectSearch` and responding fast to bug reports. We do this fully free of cost.
If you feel like this library was useful to you and saved you and your business some precious time, please consider making a donation to support its maintenance and further development.[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=NAX558HVGAX8Q)
### Financial Supporters
Thank you very much to our financial supporters!
### Collaborators
### Contributors
Thank you very much to all our community contributors!
![]()
Esteban Gehring
![]()
Markus Mächler
![]()
Sebastian Wierzbicki
![]()
Tristan
![]()
Sirh3e
![]()
Tony H
![]()
Michał Stawicki
![]()
Aleix Ferré
![]()
Null
![]()
Blaze Walker
![]()
Cristian Raducanu
![]()
Damian Miranda
![]()
Dane Vanderbilt
![]()
David Sansome
![]()
Edgar Scheiermann
![]()
Erendis
![]()
Null
![]()
Gustavo Miranda
![]()
Henno Lauinger
![]()
Null
![]()
Iblis Lin
![]()
Jean-Francois Cere
![]()
Joe DeCock
![]()
Jomal Johny
![]()
Jonathan Kolberg
![]()
Kristof Gilis
![]()
Melroy Van Den Berg
![]()
Muhammad Ahsan Ayaz
![]()
Ovidijus Stukas
![]()
Ray Suelzer
![]()
Robert Pattis
![]()
Roland Broekema
![]()
Null
![]()
Stas Amasev
![]()
Thierry Nischelwitzer
![]()
Vlad Ioffe
![]()
Null
![]()
Null
![]()
Joshua
![]()
Null
![]()
Null
## How to use it?
Install `ngx-mat-select-search` in your project:
```
npm install ngx-mat-select-search
```Import the `NgxMatSelectSearchModule` e.g. in your `app.module.ts`:
```typescript
import { MatSelectModule } from '@angular/material';
import { NgxMatSelectSearchModule } from 'ngx-mat-select-search';@NgModule({
imports: [
...
MatSelectModule,
NgxMatSelectSearchModule
],
})
export class AppModule {}
```Use the `ngx-mat-select-search` component inside a `mat-select` element by placing it inside a `` element:
```html
{{bank.name}}
```
See the examples in [https://github.com/bithost-gmbh/ngx-mat-select-search/tree/master/src/app/examples](https://github.com/bithost-gmbh/ngx-mat-select-search/tree/master/src/app/examples)
how to wire the `ngx-mat-select-search` and filter the options available.
Or have a look at [https://github.com/bithost-gmbh/ngx-mat-select-search-example](https://github.com/bithost-gmbh/ngx-mat-select-search-example) to see it in a standalone app.### Template driven forms
You can alternatively use it with template driven forms as follows:
```html```
### Labels
In order to change the labels, use the inputs specified in the [API](#api) section as follows:
```html```
To use the [i18n](https://angular.io/guide/i18n) API for translation of the labels, add the corresponding `i18n-...` attributes:
```html```
### Compatibility
#### Current release
* `@angular/core`: `^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0`
* `@angular/material`: `^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0` with `MatSelectModule` (`@angular/material/select`)#### Version [`7.0.10`](https://github.com/bithost-gmbh/ngx-mat-select-search/tree/7.0.10)
* `@angular/core`: `^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0`
* `@angular/material`: `^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0` with `MatSelectModule` (`@angular/material/select`)#### Version [`6.0.0`](https://github.com/bithost-gmbh/ngx-mat-select-search/tree/6.0.0)
* `@angular/core`: `^15.0.0`
* `@angular/material`: `^15.0.0` with `MatLegacySelectModule` (`@angular/material/legacy-select`)#### Version [`5.0.0`](https://github.com/bithost-gmbh/ngx-mat-select-search/tree/5.0.0)
* `@angular/core`: `^12.0.0 || ^13.0.0 || ^14.0.0`
* `@angular/material`: `^12.0.0 || ^13.0.0 || ^14.0.0`#### Version [`3.3.3`](https://github.com/bithost-gmbh/ngx-mat-select-search/tree/3.3.3)
* `@angular/core`: `^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0`
* `@angular/material`: `^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0`#### Version [`1.8.0`](https://github.com/bithost-gmbh/ngx-mat-select-search/tree/1.8.0)
* `@angular/core`: `^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0`
* `@angular/material`: `^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0`### API
The `MatSelectSearchComponent` implements the [ControlValueAccessor](https://angular.io/api/forms/ControlValueAccessor) interface.
Furthermore, it provides the following inputs:#### Inputs
```typescript
/** Label of the search placeholder */
@Input() placeholderLabel = 'Suche';/** Type of the search input field */
@Input() type = 'text';/** Font-based icon used for displaying Close-Icon */
@Input() closeIcon = 'close';/** SVG-based icon used for displaying Close-Icon. If set, closeIcon is overridden */
@Input() closeSvgIcon?: string;/** Label to be shown when no entries are found. Set to null if no message should be shown. */
@Input() noEntriesFoundLabel = 'Keine Optionen gefunden';/**
* Whether the search field should be cleared after the dropdown menu is closed.
* Useful for server-side filtering. See [#3](https://github.com/bithost-gmbh/ngx-mat-select-search/issues/3)
*/
@Input() clearSearchInput = true;/** Whether to show the search-in-progress indicator */
@Input() searching = false;/** Disables initial focusing of the input field */
@Input() disableInitialFocus = false;/** Enable clear input on escape pressed */
@Input() enableClearOnEscapePressed = false;/**
* Prevents home / end key being propagated to mat-select,
* allowing to move the cursor within the search input instead of navigating the options
*/
@Input() preventHomeEndKeyPropagation = false;/** Disables scrolling to active options when option list changes. Useful for server-side search */
@Input() disableScrollToActiveOnOptionsChanged = false;/** Adds 508 screen reader support for search box */
@Input() ariaLabel = 'dropdown search';/** Whether to show Select All Checkbox (for mat-select[multi=true]) */
@Input() showToggleAllCheckbox = false;/** Select all checkbox checked state */
@Input() toggleAllCheckboxChecked = false;/** select all checkbox indeterminate state */
@Input() toggleAllCheckboxIndeterminate = false;/** Display a message in a tooltip on the toggle-all checkbox */
@Input() toggleAllCheckboxTooltipMessage = '';/** Define the position of the tooltip on the toggle-all checkbox. */
@Input() toggleAllCheckboxTooltipPosition: 'left' | 'right' | 'above' | 'below' | 'before' | 'after' = 'below';/** Show/Hide the search clear button of the search input */
@Input() hideClearSearchButton = false;/**
* Always restore selected options on selectionChange for mode multi (e.g. for lazy loading/infinity scrolling).
* Defaults to false, so selected options are only restored while filtering is active.
*/
@Input() alwaysRestoreSelectedOptionsMulti = false;/**
* Recreate array of selected values for multi-selects.
*
* This is useful if the selected values are stored in an immutable data structure.
*/
@Input() recreateValuesArray = false;
/** Output emitter to send to parent component with the toggle all boolean */
@Output() toggleAll = new EventEmitter();```
#### Customize clear icon
In order to customize the search icon, add the `ngxMatSelectSearchClear` to your custom clear item (a `mat-icon` or any other element) and place it inside the `ngx-mat-select-search` component:
```htmldelete
```
If just the icon should be changed the inputs `closeIcon` and `closeSvgIcon` can be used.#### Customize no entries found element
In order to customize the no entries found element, add the `ngxMatSelectNoEntriesFound` to your custom item (a `mat-icon, span, button` or any other element) and place it inside the `ngx-mat-select-search` component:
```html
No entries found
Add add
```
#### Custom content
Custom content with the CSS class `mat-select-search-custom-header-content` can be transcluded as follows:
```html
something special```
#### Global default options
Providing the [`MAT_SELECTSEARCH_DEFAULT_OPTIONS`](src/app/mat-select-search/default-options.ts)
InjectionToken, the default values of several `@Input()` properties can be set globally.
See the documentation of the corresponding `@Input()` properties of `MatSelectSearchComponent`.Example:
```typescript
import { MAT_SELECTSEARCH_DEFAULT_OPTIONS, MatSelectSearchOptions } from 'ngx-mat-select-search';@NgModule({
...
providers: [
{
provide: MAT_SELECTSEARCH_DEFAULT_OPTIONS,
useValue: {
closeIcon: 'delete',
noEntriesFoundLabel: 'No options found',
}
}
]
})
class AppModule {}
```## Known Problems
* The currently selected option might be hidden under the search input field when opening the options panel
and the panel is at the screen border.## Development
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.7.1.
### Development server
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
### Build
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build.
### Library Build / NPM Package
Run `npm run build-lib` to build the library and generate an NPM package.
The build artifacts will be stored in the `dist-lib/` folder.To release, run `cd dist-lib/ && npm publish`.
### Running unit tests
Run `npm run test` to execute the unit tests via [Karma](https://karma-runner.github.io).