npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@devlukaszmichalak/mat-select-filter

v21.0.0

Published

A filter for mat-select

Readme

mat-select-filter

Note: This is a fork of the original library that maintains compatibility with the latest Angular versions. The versioning follows Angular's versioning scheme (e.g., use library version 13.x.x for Angular 13.x.x projects).

A filter component for Angular Material <mat-select> drop-downs. Supports filtering arrays of strings or objects, option groups, and is compatible with both NgModule and standalone component usage.

Demo

StackBlitz Demo

Installation

npm install @devlukaszmichalak/mat-select-filter

Usage

NgModule

In module-based app import the MatSelectFilterModule

import {MatSelectFilterModule} from '@devlukaszmichalak/mat-select-filter';

@NgModule({
    ...
    imports: [MatSelectFilterModule],
    ...
})

export class AppModule { ... }

Standalone Component (since library version 17.1.0)

In standalone components import the MatSelectFilterComponent in the component's 'imports' array

import {MatSelectFilterComponent} from '@devlukaszmichalak/mat-select-filter';

@Component({
    ...
    standalone: true, // this flag is ommited in newer angular versions 
    imports: [MatSelectFilterComponent],
    ...
})

export class Component { ... }

Basic Example

<mat-form-field>
    <mat-select>
        <mat-select-filter [array]="variables" (filteredReturn)="filteredVariables = $event"></mat-select-filter>
        <mat-option *ngFor="let variable of filteredVariables">
            {{ variable }}
        </mat-option>
    </mat-select>
</mat-form-field>

or using new control flow syntax

<mat-form-field>
    <mat-select>
        <mat-select-filter [array]="variables" (filteredReturn)="filteredVariables = $event"></mat-select-filter>
        @for (variable of filteredVariables; track variable) {
            <mat-option>
                {{ variable }}
            </mat-option>
        }
    </mat-select>
</mat-form-field>

Filtering Objects

Bind a filtered array with [array] . It now accepts an array objects thanks to Sen Alexandru. If your array contains objects, specify the property to filter with [displayMember]:

variables = [
    {id: 1, name: 'Alpha'},
    {id: 2, name: 'Beta'}
];
<mat-form-field>
    <mat-select>
        <mat-select-filter [array]="variables"
                           [displayMember]="'name'"
                           (filteredReturn)="filteredVariables = $event"></mat-select-filter>
        @for (variable of filteredVariables; track variable) {
            <mat-option>
                {{ variable }}
            </mat-option>
        }
    </mat-select>
</mat-form-field>

Option Groups

mat-select-filter now supports option group support thanks to jenniferarce! Just input the [hasGroup] boolean to true and add you [groupArrayName] string!

To filter grouped options, use additionally [hasGroup] and [groupArrayName]:

<mat-select-filter
        [array]="groups"
        [hasGroup]="true"
        [groupArrayName]="'options'"
        [displayMember]="'name'"
        (filteredReturn)="filteredGroups = $event">
</mat-select-filter>

Inputs

| Input | Type | Default | Description | |----------------------|---------|--------------|-----------------------------------------------------------| | array | any[] | — | Array to filter (required). | | placeholder | string | 'Search...' | Placeholder text for the search input. | | color | string | 'white' | Background color for the filter bar. | | displayMember | string | — | Property name to filter/display (for array of objects). | | showSpinner | boolean | true | Show a spinner while filtering. | | noResultsMessage | string | 'No results' | Message to display when no results are found. | | hasGroup | any | — | Enable option group filtering (set to truthy value). | | groupArrayName | string | — | Property name for the group array (used with hasGroup). | | filterDebounceTime | number | 0 | Debounce time (ms) for the filter input. |

Output

| Output | Description | |------------------|----------------------------------------------------| | filteredReturn | Emits the filtered array after each filter action. |

Features

  • Works with arrays of strings or objects
  • Option group support
  • Customizable placeholder, color, spinner, and no-results message
  • Debounced filtering
  • Focuses the input on open
  • Prevents propagation of alphanumeric key events to avoid selection issues

Custom Styling

You can override styles using the following CSS classes in a global css/scss file:

.mat-filter {
  // Styles the filter bar
}

.mat-filter-input {
  // Styles the input field
}

.spinner {
  // Styles the spinner
}

.no-results-message {
  // Styles the no-results message
}

Example:

.mat-filter {
  background-color: purple !important;
}

.mat-filter-input {
  border: 1px solid black !important;
}

License

MIT