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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@devlukaszmichalak/mat-select-filter

v19.0.0

Published

A filter for mat-select

Downloads

1,043

Readme

IMPORTANT

This is a fork that will bring the library up to the latest angular version.

The versioning of this fork follows the angular versions, so for example, for any angular 13.x.x project use library version 13.x.x

https://github.com/devLukaszMichalak/mat-select-filter

mat-select-filter

Original Github

https://github.com/mdlivingston/mat-select-filter

Description

The mat-select-filter is a filterer for the material select drop-downs. They currently do not support this, so I decided to make my own.

Demo

https://stackblitz.com/edit/mat-select-filter

Install

npm

$ npm install @devlukaszmichalak/mat-select-filter

How to set up

NgModule

In module based app import the MatSelectFilterModule

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

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

Standalone (since library version 17.1.0)

In standalone components import the MatSelectFilterComponent in the imports array

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


@Component({
  ...
  standalone: true,
  imports: [
    ...
    MatSelectFilterComponent,
    ...
  ],
  ...
})
export class Component {

How to use

Add component to the desired material select:

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

Send your desired filtered array using the [array]="variables" or [array]="['one', 'two', 'three']". It now accepts an array objects thanks to Sen Alexandru. To use an array of objects, specify the objects key value you want to filter using the [displayMember] input. For example:

var variables = [
  {
    id: 0,
    name: 'test1'
  },
  {
    id: 0,
    name: 'test1'
  }
]
<mat-form-field>
    <mat-select>
        <mat-select-filter [array]="variables" [displayMember]="'name'" (filteredReturn)="filteredVariables = $event"></mat-select-filter>
        <mat-option *ngFor="let variable of filteredVariables">
            {{variable}}
        </mat-option>
    </mat-select>
</mat-form-field>

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

The (filteredReturn) method returns the filtered results after every keyboard action while searching...

The [noResultsMessage] is the string you would like to display when you filter no results.

The [showSpinner] allows you to turn off whether you would like to show a loading spinner while filtering.

The [filterDebounceTime] allows you to set the debounceTime value on a filter input. Default is 0.

The placeholder text for the search box is accessed by [placeholder]. Default is 'Search...';

<mat-select-filter [placeholder]="'Search..'" [array]="variables" (filteredReturn)="filteredVariables = $event"></mat-select-filter>

To focus the search input on every click, you can do something like this:

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

otherwise, it will only focus once.

To add a colored background, do something like this:

 <mat-select-filter [color]="'purple'" [array]="variables" (filteredReturn)="filteredVariables = $event"></mat-select-filter>

You can also change the classes from a global css/scss file in your project by adding:

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

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

Options

  • [array]
  • [color]
  • [placeholder]
  • [displayMember]
  • [noResultsMessage]
  • [showSpinner]
  • [hasGroup]
  • [groupArrayName]
  • [showSpinner]
  • [filterDebounceTime]
  • (filteredReturn)

Hope you enjoy!