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

@ng-zi/extensions-autocomplete

v0.0.1

Published

Angular Material Extensions for autocomplete

Downloads

2

Readme

MtxAutocomplete Component Overview

The MtxAutocomplete Component is a custom Angular component that extends and encapsulates the Angular Material autocomplete component. It provides enhanced features like custom item templates, flexible client/server filtering, and compatibility with Angular forms API. This component is designed to improve the user experience by offering infinite scroll, keyboard navigation, debounce input for server requests, and more.

Features

| Feature | Description | |------------------------------|-----------------------------------------------------------------------------| | Custom Item and 'Not Found' Templates | Easily customize the display of items and the 'not found' message. | | Flexible Filtering | Supports both client-side and server-side filtering. | | Form Compatibility | Works seamlessly with both Reactive and Template-driven forms. | | Infinite Scroll | Load more items as the user scrolls down the list. | | Keyboard Navigation | Navigate through the options using the keyboard. | | Debounce Input | Reduce the number of server requests with input debouncing. | | Clear Selection Button | Allow users to clear their current selection with a button. | | Custom Error Handling | Handle errors gracefully with custom error handling. | | Styling Enhancements | Style the component to match your application's look and feel. |

Usage

Installation

  1. Import the MtxAutocompleteModule into your Angular module:

    import { MtxAutocompleteModule } from '@ng-zi/extensions/autocomplete';
    
    @NgModule({
      declarations: [
        // your components
      ],
      imports: [
        // other modules
        MtxAutocompleteModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }

Example

Component TypeScript
import { Component } from '@angular/core';

@Component({
  selector: 'app-autocomplete-demo',
  templateUrl: './autocomplete-demo.component.html'
})
export class AutocompleteDemoComponent {
  filteredItems: string[] = ['One', 'Two', 'Three'];

  autocompleteconfig = {
    options: this.filteredItems,
    placeholder: 'Search items',
    displayWith: (value: string) => value,
    debounceTime: 300,
    infiniteScrollThreshold: 0.8,
    serverFiltering: false,
    clearButton: true
  };

  onOptionSelected(value: string) {
    console.log('Option selected:', value);
  }

  onSearchChange(value: string) {
    console.log('Search changed:', value);
  }

  onErrorHandling(error: any) {
    console.error('Error occurred:', error);
  }
}
Component HTML
<mtx-autocomplete 
  [autocompleteconfig]="autocompleteconfig" 
  (optionSelected)="onOptionSelected($event)" 
  (searchChange)="onSearchChange($event)" 
  (errorHandling)="onErrorHandling($event)">
</mtx-autocomplete>

Configuration Options

| Option | Description | |-------------------------|--------------------------------------------------------------------------------------------------| | options | The list of options to display in the autocomplete dropdown. | | displayWith | A function to control how the options are displayed in the input field. | | placeholder | Placeholder text for the input field. | | debounceTime | Time in milliseconds to debounce input changes. | | infiniteScrollThreshold| Threshold for triggering infinite scroll, as a decimal fraction of the viewport height. | | serverFiltering | Whether to use server-side filtering for options. | | clearButton | Whether to display a clear button to clear the selection. |

Events

| Event | Description | |-----------------|----------------------------------------------------------------| | optionSelected| Event emitted when an option is selected. | | searchChange | Event emitted when the search input changes. | | errorHandling | Event emitted when an error occurs. |

Templates

| Template | Description | |---------------------|------------------------------------------------------------------| | notFoundTemplate | Template to display when no options are found. | | customItemTemplate| Template to customize how options are displayed in the dropdown. |

Custom Templates

You can customize the look and feel of the items and the 'not found' message using Angular's ng-template syntax.

Custom Item Template

<ng-template #customItemTemplate let-item>
  <div class="custom-item">
    {{ item }}
  </div>
</ng-template>

Not Found Template

<ng-template #notFoundTemplate>
  <div class="not-found">
    No items found.
  </div>
</ng-template>

Using Custom Templates

Pass the custom templates to the MtxAutocompleteComponent using the autocompleteconfig object:

autocompleteconfig = {
  options: this.filteredItems,
  placeholder: 'Search items',
  customItemTemplate: this.customItemTemplate,
  notFoundTemplate: this.notFoundTemplate,
  debounceTime: 300,
  infiniteScrollThreshold: 0.8,
  serverFiltering: false,
  clearButton: true
};
<mtx-autocomplete 
  [autocompleteconfig]="autocompleteconfig" 
  (optionSelected)="onOptionSelected($event)" 
  (searchChange)="onSearchChange($event)" 
  (errorHandling)="onErrorHandling($event)">
</mtx-autocomplete>

<ng-template #customItemTemplate let-item>
  <div class="custom-item">
    {{ item }}
  </div>
</ng-template>

<ng-template #notFoundTemplate>
  <div class="not-found">
    No items found.
  </div>
</ng-template>

Summary

The MtxAutocomplete Component provides a powerful and flexible way to implement autocomplete functionality in your Angular applications. With its customizable templates, filtering options, and seamless integration with Angular forms, it offers a rich user experience tailored to your needs.