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

vue-suggest-input

v0.1.4

Published

## Introduction

Downloads

581

Readme

[Vue.js] Component that performs suggestion / auto save (autocomplete)

Introduction

In Vue.js, I created an input component that displays a suggestion list, such as a leading search engine. It's published on npm, so please use it if you like.

What function

It is a text box component of Vue.js that has a function to suggest suggestions (automatic storage) if you enter characters halfway into the text box. You can often find it on search engine sites etc.

Simple sample

Anyway, it is sample code. This is a simple example of displaying an array specified by data () in a suggestion list.

<template>
  <div>
    <vue-suggest-input :items="items" />
  </div>
</template>
<script>
import VueSuggestInput from 'vue-suggest-input'
import 'vue-suggest-input/dist/vue-suggest-input.css'

export default {
  components: {
    VueSuggestInput
  },
  data () {
    return {
      items: ['apple', 'cocoa', 'coffee', 'cola']
    }
  }
}
</script>
`` `

In actual operation, I think that the contents to be displayed in the suggestion list from the outside will be loaded by the REST API etc, but the method will be described later.

## Installation

It can be installed with npm.

npm i vue-suggest-input --save


## Keyboard shortcut

Shortcut keys can be used to display a suggestion list or to move or select a list.

### When the suggestion list is hidden

| Key | Description |
|:-|:-|
Up arrow (↑), down arrow (↓) | Display suggestion list |
Raises the `search` event. |

### When the suggestion list is displayed

| Key | Description |
|:-|:-|
| Escape (ESC) | Close the suggestion list. |
Up arrow (↑) | Moves the candidate selection up. |
Down arrow (↓) | Moves the candidate selection down. |
| Enter | Sets the candidate selected in the suggestion list in the input area and raises the `search` event. |

## Property (Props)

### items

** Type: ** Array or Function or Promise
** Default value: ** null
#### Overview

Specify an array of content to be displayed in the suggestion. Specify an array, function, or promise type. When specifying with a function or promise, the return value from the function must be an array.

-Example of specifying by array

```html
<vue-suggest-input: items = "['item1', 'item2']" />

-Example of specifying promise

<suggest-input: items = "getItems" />
export default {
  methods: {
    async getItems () {
      const {data} = await this. $ axios.get ("url")
      return data
    }
  }
}

filter-func

** Type: ** Function ** Default value: ** null

Overview

You can specify a custom function to filter the content of the suggestion. The custom function is passed two arguments. The first argument is the content of the suggestion to be filtered, and the second is the content of the input area.

Custom functions should return a return value of type bool. If true is returned, the suggestion of the first argument is displayed as a candidate. It will not be displayed if you return false.

The sample code below is designed to display only suggestions that contain the 11 string in the suggestion in the list of candidates.

<suggest-input
  : item = "['item011', 'item012', 'item111']"
  : filter-func = "myFilter" />
export default {
  methods: {
    myFilter (suggestItem, inputValue) {
      return suggestItem.indexOf ("11")> = 0
    }
  }
}

max-suggest

** Type: ** Number ** Default value: ** 10

Overview

Specifies the maximum number of suggestions to display.

<suggest-input: max-suggest = "5" />

query-interval

** Type: ** Number ** Default value: ** 100

Overview

Sets the interval in milliseconds for re-searching the suggestion list. For example, if 1000 is specified, search for suggestions is performed from the array or function specified in the items property in a one-second fashion.

Conversely, if you want to search for a candidate immediately after each input, specify 0.

<suggest-input: query-interval = "1000" />

loading-show-delay

** Type: ** Number ** Default value: ** 500

Overview

While searching for a suggestion, specify the time in milliseconds until displaying "Loading ...". For example, if 500 is specified, if reading for the suggestion takes more than 500 ms," Reading ... "will be displayed below the input field.

This property is useful when it takes time to search for a suggestion.

Event

search

This is an event that occurs when you select a candidate from the suggestion list or confirm your input with the Enter key. It is mainly used when the main search processing is performed based on the search condition entered in this component.

<suggest-input @ search = "doSearch ()" />

input

It is an event that occurs at each input. This is equivalent to the inpput event of HTMLElement.

<suggest-input @ input = "doInput ()" />

Customize Icon

You can replace the icon on the right of the input area with your own icon. By default, a magnifying glass SVG icon is displayed, as shown in the image below.

Icon on the right of the input area

Use the slot to customize the icon. The following is sample code.

<vue-suggest-input>
  <div slot = "add-on-icon">
    <i class = "fa fa-rocket" aria-hidden = "true"> </ i>
  </ div>
</ vue-suggest-input>

In the case of the code above, the icon replaces the one specified in slot as in the following image.

Screen image after icon customization

finally

If you have a bug, please let me know in the comments.