@devlukaszmichalak/mat-select-filter

中文文档
22.0.0发布于 2026/06/10MITTypeScriptES Module近 30 天下载 5708

A filter for mat-select

原始使用文档
文档目录13 节
  1. Demo
  2. Installation
  3. Usage
  4. NgModule
  5. Standalone Component (since library version 17.1.0)
  6. Basic Example
  7. Filtering Objects
  8. Option Groups
  9. Inputs
  10. Output
  11. Features
  12. Custom Styling
  13. License

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

InputTypeDefaultDescription
arrayany[]—Array to filter (required).
placeholderstring'Search...'Placeholder text for the search input.
colorstring'white'Background color for the filter bar.
displayMemberstring—Property name to filter/display (for array of objects).
showSpinnerbooleantrueShow a spinner while filtering.
noResultsMessagestring'No results'Message to display when no results are found.
hasGroupany—Enable option group filtering (set to truthy value).
groupArrayNamestring—Property name for the group array (used with hasGroup).
filterDebounceTimenumber0Debounce time (ms) for the filter input.

Output

OutputDescription
filteredReturnEmits 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

版本与发布记录

@devlukaszmichalak/mat-select-filter 共发布 16 个版本,首次发布于 2024/04/10;过去 12 个月发布了 3 个版本。

版本发布日期距今
22.0.0latest2026/06/105 个月前
21.2.02026/06/105 个月前
21.0.02025/11/2911 个月前
20.1.22025/07/111.3 年前
20.1.12025/07/111.3 年前
20.1.02025/07/111.3 年前

关于 @devlukaszmichalak/mat-select-filter 的常见问题

@devlukaszmichalak/mat-select-filter 是什么?

A filter for mat-select

如何安装 @devlukaszmichalak/mat-select-filter?

在项目目录运行 npm install @devlukaszmichalak/mat-select-filter,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@angular/common(^22)、@angular/core(^22)、@angular/material(^22)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@devlukaszmichalak/mat-select-filter 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@devlukaszmichalak/mat-select-filter 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@devlukaszmichalak/mat-select-filter 可以商用吗?

@devlukaszmichalak/mat-select-filter 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@devlukaszmichalak/mat-select-filter 的下载量有多少?

根据 npm 官方下载统计,@devlukaszmichalak/mat-select-filter 在 2026/10/12 – 2026/11/10 这 30 天内被下载 5,708 次,日均约 190 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@devlukaszmichalak/mat-select-filter 还在维护吗?

最新版本 22.0.0 发布于 2026/06/10(5 个月前);至今共发布 16 个版本,其中过去 12 个月发布了 3 个;首次发布于 2024/04/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。