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

v1.3.4

Published

Simple vue search component with autocomplete capabilities

Downloads

258

Readme

Vue-Suggest

Simple autocomplete search component for Vue

This is a simple autocomplete search component for Vue.

Why yet another autocomplete component?

Well, because I needed it in my own projects. The existing awesome autocomplete components didn't quite fit my needs.

So, what makes it different?

This autocomplete component will be the component you need if you want:

  • no styling
  • no functionality for getting options from an endpoint.
  • simple interface
  • a customizable render/template for the options through scoped slots
  • enables and requires use of the v-model binding for custom input components

Installation

As a npm module

npm install vue-suggest --save-dev

Then just include it in your project

import VueSuggest from 'vue-suggest'

Browser

Use the minified browser plugin version in vue-suggest.plugin.js. This plugin auto-installs once it is loaded in the browser - making the vue-suggest component available right away.

Just do

<script src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/vue-suggest/dist/vue-suggest.plugin.js"></script>

Usage

See the basic example Allways use v-model attribute.

Events

The search element emits three events.

| Event | Attributes | Description | | :--- | :--- | :--- | | input | keyword | This is triggered every time the input changes, and the keyword contains what is currently in the search field. | | search | keyword | If the user searches (press enter) while in the search field. Keyword is the current search phrase. | | select | option | If the user picks from the suggestion list, the full option item is emitted in the select event |

Props

| Prop | Type | Description | Default | | :--- | :--- | :--- | :--- | | options | Array | Array of current suggestions. This should be a filtered list based on the keyword emitted in the autocomplete event. Should be an array of strings or objects | - | | value | String | The value used in v-model binding | - | | wrapper-classes | String | Used to customize appearance. Adds classnames to the wrapper div. | suggest-search | | input-classes | String | Used to customize appearance. Adds classnames to the input element. | suggest-input | | list-classes | String | Used to customize appearance. Adds classnames to the unordered options list. | suggest-list | | item-classes | String | Used to customize appearance. Adds classnames to the option list items. | suggest-item | | placeholder | String | Used to customize appearance. Adds placeholder text in search box. | Search.. | | required | Boolean | Used to customize the required attribute of the input element. | false | | autofocus | Boolean | Used to customize the autofocus attribute of the input element. | false |

Customizing the template for each option in the list.

This is acieved through scoped slots

A slot named item is available in the component. The option data is passed in the prop data. A sample customized item would for example be:

<vue-suggest
    :options="options"
    v-model="value"
    @select="logSelect"
    @search="logSearch">

    <!--
        Adding a template for the scoped slot.
        Notice that the slot-scope attribute can be name anything you like,
        and that the data prop is available within that scope.
    -->
    <template slot="item" slot-scope="myslotscope">
        <div class="my-scoped-slot-class">
            <strong>{{ myslotscope.data }}</strong>
        </div>
    </template>

</vue-suggest>

Rendered HTML

The rendered HTML is pretty simple:

<div class="suggest-wrap">
    <input placeholder="Search.." autocomplete="off" class="suggest-input">
    <ul class="suggest-list" style="display: none;">
        <li class="suggest-item">Item</li>
        <li class="suggest-item highlighted">Highlighted item</li>
    </ul>
</div>

Kudos