0.3.0 • Published 3 years ago

ngx-sand-typeahead v0.3.0

Weekly downloads
21
License
MIT
Repository
github
Last release
3 years ago

Demo

npm.io

Table of contents

Features

  • Type and search at the same time
  • Limit number of items displayed in dropdown
  • Option to choose default template for ui or fully end user customization
  • Optional second and third parameter to display
  • Angular form support
  • Built in filter functionality
  • Easy to customize
  • Plug and play feature

Goto Top

Getting Started

Step 1 : Install the package

NPM

npm install ngx-sand-typeahead

Step 2 : After installation import SelectDropDownModule into your root or feature module

import { SandTypeaheadModule } from 'sand-typeahead';

Step 3 : Add SandTypeaheadModule to the imports of your NgModule

@NgModule({
  imports: [
    ...,
    SandTypeaheadModule
  ],
  ...
})
class YourModule { ... }

Usage

  • Use <ngx-sand-typeahead></ngx-sand-typeahead> in your templates to add the default dropdown in your view like below
  <ngx-sand-typeahead 
   (searchChange)="onSearch($event)" 
   (valueSelect)="onSelect($event)" 
   (blurInput)="onBlur($event)"
   (clickInput)="onClick($event)" 
   [disabled]="disabled" 
   [options]="dropdowndata" 
   [settings]="settings">
  </ngx-sand-typeahead>
  • For custom dropdown in your view pass [itemTemplate]="yourDropdownTemplate" and [notFoundTemplate]="yourNotFoundTemplate" as inputs

    <ngx-sand-typeahead 
     (searchChange)="onSearch($event)"
     (valueSelect)="onSelect($event)"
     (blurInput)="onBlur($event)" 
     (clickInput)="onClick($event)"
     [disabled]="disabled" 
     [options]="dropdowndata" 
     [settings]="settings"   
     [itemTemplate]="yourDropdownTemplate" 
     [notFoundTemplate]="yourNotFoundTemplate">
    </ngx-sand-typeahead>
    
    <ng-template #yourDropdownTemplate let-item let-i="index">
      <a [innerHTML]="item.name"></a>
    </ng-template>
    
    <ng-template #yourNotFoundTemplate let-noDataText >
      <a [innerHTML]="noDataText"></a>
    </ng-template>

    Goto Top

API

Input

  • options:Array - Array of objects that are to be the dropdown options.
  • settings:Object - Settings object to change the default configurations.
  • formControlName - Tracks the FormControl instance bound to the directive. Used with Reactive forms
  • [(ngModel)] - Tracks the value bound to this directive. Used with Template-driven forms
  settings = {
      inputDirection: 'ltr',
      displayKey: 'name',
      placeholder: 'Input here',
      height: 300,
      limit: 0,
      subtitleEnabled: false,
      subTitleKey: '',
      minorTitleEnabled: false,
      minorTitleKey: '',
      heading: '',
      noDataText:'No data found'
  };
PropertyPurposeTypeDefault valueMandatory
displayKeyThe objectname of the array to be taken to display in the dropdownstringnameYes
placeholderPlaceholder for the input fieldstringInput hereNo
Max heightHeight of the dropdown (px)number300No
InputdirectionThe direction of the search input. Can be rtl or ltr ( default )stringltrNo
headingThe header text of the dropdown to be displayedstringnoneNo
subtitleEnabledThe optional sub heading beneath the main titlebooleanfalseNo
subTitleKeyThe objectname of the array to be taken to display in the subtitle fieldstringnoneNo
minorTitleEnabledThe optional minor heading at the very right of the main titlestringfalseNo
minorTitleKeyThe objectname of the array to be taken to display in the minortitle fieldstringnoneNo
limitNumber thats limits the number of options displayed in the UI (if zero, options will not be limited)number0No
noDataTextThe placeholder when there is no value matching with the word enteredstringNo data foundNo

Output

NameTypedescription
searchChangeEventChange event when typing in the input field
valueSelectEventSelect event when a value is selected from dropdown
blurInputEventEvent once the input field is blurred
clickInputEventClick event upon clicking on the input field

Goto Top

Help Improve

Found a bug or an issue with this? Open a new issue here on GitHub.

Contribute

Please check the Contributing Guidelines before contributing.

This project was generated with Angular CLI version 10.0.5.