1.7.3 • Published 2 years ago

@myfarms/mf-select v1.7.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@myfarms/mf-select

Playground: https://stackblitz.com/edit/mf-select

Getting started

Step 1: Install @myfarms/mf-select

$ npm install @myfarms/mf-select --save

Step 2: Import the MfSelectModule

import { NgModule } from '@angular/core';

import { MfSelectModule } from '@myfarms/mf-select';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    MfSelectModule,
  ],
  bootstrap: [ AppComponent ]
})
export class AppModule { }

Step3: Use the component in your template

<mf-select
  [items]='items'
></mf-select>

API

Inputs

InputTypeDefaultDescription
itemsstring[] | object[]| Observable<string[] \| object[]>[]Items array or Observable results in an array
itemLabelstring'name'Object property to use for label
categoryLabelstring'category'Grouping based on category, with category header rows
appendTostringnullAppend dropdown to body or any other element using css selector
dropdownPosition'bottom' | 'top' | 'auto''auto'Set the dropdown position on open
dropdownWidthnumber-Static width of the dropdown in pixels
placeholderstring'Select...'Placeholder text
placeholderLoadingstring'Loading...'Placeholder text while loading
allowClearbooleantrueAllow dropdown selection to be cleared via 'X' button
loadingbooleanfalseFlag for manually setting loading spinner
floatingLabelstring | undefinedundefinedFloating label that shows when item is selected
backgroundColorstring'white'Background color for the select box and dropdown
floatingLabelColorstring'white'Background color for the floating label
searchTemplateLeftTemplateRef<any>-Template for content left of search
searchTemplateRightTemplateRef<any>-Template for content right of search
selectedTemplateTemplateRef<any>-Template for content of selected item
optionTemplateTemplateRef<any>-Template for content of each item in the dropdown
optionCategoryTemplateTemplateRef<any>-Template for content of each category header in the dropdown

Outputs

OutputDescription
(update)Fired on selected value change

Methods and Properties

NameDescription
selectedItemThe selected item
toggle()Opens/closes the select dropdown panel, whichever is appropriate
open()Opens the select dropdown panel
close()Closes the select dropdown panel
selectItem(item)Selects the passed item

Other

NameTypeDescription
mfOptionHighlightdirectiveHighlights search term in option. Accepts search term. Should be used on option element when customizing template

Change Detection

Ng-select component implements OnPush change detection which means the dirty checking checks for immutable data types. That means if you do object mutations like:

this.items.push({id: 1, name: 'New item'})

Component will not detect a change. Instead you need to do:

this.items = [...this.items, { id: 1, name: 'New item' }];

This will cause the component to detect the change and update. Some might have concerns that this is a pricey operation, however, it is much more performant than running ngDoCheck and constantly diffing the array.

Development

To generate all *.js, *.d.ts and *.metadata.json files:

$ npm run build

To lint all *.ts files:

$ npm run lint

License

MIT © MyFarms

1.7.3

2 years ago

1.7.2

2 years ago

1.7.1

2 years ago

1.7.0

2 years ago

1.6.4

3 years ago

1.6.3

3 years ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.5

3 years ago

1.5.4

3 years ago

1.5.3

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.0

4 years ago

1.4.1

4 years ago

1.3.1

4 years ago

1.4.0

4 years ago

1.3.0

5 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.4.7

6 years ago

0.4.6

6 years ago

0.4.5

6 years ago

0.4.4

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.5

6 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago