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

@bbortt/ngx-autocomplete

v11.1.6

Published

> Angular V11 compatible autocomplete component to use with any style framework.

Downloads

20

Readme

@bbortt/ngx-autocomplete

Angular V11 compatible autocomplete component to use with any style framework.

Travis CI npm Version Blazing Fast License: Apache 2

Highlights:

  • Fully flexible for any autocomplete object through propertyAccessor function
  • Scales perfectly to every screen size, even when resizing
  • Navigable using the mouse or keyboard (see Navigation)
  • Create your own filter method which matches the case best
  • Fits into the @angular/forms / FormGroup setup
  • Customizable styling using css classes

>> Life Samples.

Contents

Getting Started

Add the NgxAutocompleteModule to your app.module.ts like this:

[...]

import { NgxAutocompleteModule } from '@bbortt/ngx-autocomplete';

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

That's it. You can head into the code at this point! The component selector is named <ngx-autocomplete />.

API Reference

Inputs

| Input | Type | Description | Default | | :----------------: | :---------------------------------: | :------------------------------------------------------------------------------------------------------ | :---------- | | id | string | The ID of the <input /> component. Mostly used to link any <label /> elements. | | | name | string | The <input /> element name. Makes the form accessible for screen readers. | | | placeholder | string | The typical default placeholder of the <input /> element. Displayed weak as long as no value present. | 'Search.' | | options | any[] | An array of options which could be selected. | [] | | propertyAccessor | string or (option: T) => string | The object autocomplete (and display) property name. Or an accessor function, given the option. | | | navigateInfinite | boolean | If true then the arrow key navigation will never end. Thus restart from the beginning / end. | false | | debounceTime | number | A debounce time in ms. This delays the filtering as long as the user types continuously. | 0 |

Outputs

| Input | Type | Description | | :-------------------: | :--------------------: | :------------------------------------------------------------------------------------------------------------------------------------------- | | autocompleteChanges | EventEmitter<string> | Event will be emitted whenever the filter value changes. The user is responsible for filtering his data and providing the updated options. |

Css Classes

ngx-autocomplete-input: The autocomplete text input.

ngx-autocomplete-container: <div /> with absolute position, holding the possible autocomplete options.

ngx-autocomplete-option: Every <option /> of the autocomplete dropdown.

ngx-autocomplete-option-active: A single active option (not yet selected).

Navigation

| Key | Meaning | | :-----------------------: | :---------------------------------------------------------------------: | | arrow up / arrow down | Navigate through the options. May be infinite using navigateInfinite. | | enter | Selects the current active option from the dropdown. | | escape | Cancel the selection - this does not use the current active option. |

Examples

All example autocompletes are deployed life: bbortt.github.io/ngx-autocomplete.

Simple

The easiest autocomplete is the pure string array.

autocomplete-sample.component.ts:

@Component({
  selector: 'app-autocomplete-sample',
  templateUrl: './autocomplete-sample.component.html'
})
export class AutocompleteSampleComponent implements OnInit {
  editForm = this.fb.group({
    country: ['', Validators.required]
  });

  private allOptions = ALL_COUNTRIES;
  options: string[] = [];

  constructor(private fb: FormBuilder) {}

  ngOnInit(): void {
    this.editForm
      .get('country')!
      .valueChanges.subscribe((value: string) => this.filter(value));
  }

  filter(value: string): void {
    this.options = this.allOptions.filter((option: string) =>
      option.startsWith(value)
    );
  }
}

autocomplete-sample.component.html

<ngx-autocomplete
  inputName="country"
  inputId="field-country"
  formControlName="country"
  [options]="options"
  (autocompleteChanges)="filter($event)"
></ngx-autocomplete>

Source.

Advanced

The advanced sample uses complex objects and the name property as an accessor. Take a look at the code in projects/bbortt/samples/src/app/sample-advanced.

Bootstrap

The bootstrap sample lives up to its name. Using a custom .scss styling, it extends the Bootstrap form styles. Take a look at the code in projects/bbortt/samples/src/app/sample-bootstrap.

License

This project is licensed under the terms of the Apache 2.0 License.