Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue3-simple-typeahead

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue3-simple-typeahead

Simple Vue3 typeahead component that show a suggested list of elements while the user types in.

  • 0.3.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.7K
increased by5.34%
Maintainers
1
Weekly downloads
 
Created
Source

vue3-simple-typeahead

A Vue3 component for a simple typeahead component. It will show a list of suggested items based on the user input.

The component includes it's own input and when the user types on it the suggested options appear.

Demo

Demo

//Pending

Installation

NPM

npm install vue3-simple-typeahead

Browser

You can also use the browser bundle in a script tag.

<script src="https://unpkg.com/vue3-simple-typeahead"></script>

Add installed component to your app

Import the vue3-simple-typeahead component and register it globally in your Vue app. Import the CSS as well if you wish to use the default styling.

import { createApp } from 'vue';
import App from './App.vue';
import SimpleTypeahead from 'vue3-simple-typeahead';
import 'vue3-simple-typeahead/dist/vue3-simple-typeahead.css'; //Optional default CSS

let app = createApp(App);
app.use(SimpleTypeahead);
app.mount('#app');

You can also import vue3-simple-typeahead locally in your component if you prefer.

import SimpleTypeahead from 'vue3-simple-typeahead'
import 'vue3-simple-typeahead/dist/vue3-simple-typeahead.css' //Optional default CSS

export default {
  name: 'my-vue-component',
  ...
  components: {
    SimpleTypeahead
  }
  ...
}

Usage

Use the component on your own app components

<vue3-simple-typeahead
	id="typeahead_id"
	placeholder="Start writing..."
	:items="['One','Two','Three',...]"
	:minInputLength="1"
	:itemProjection="itemProjectionFunction"
	@selectItem="selectItemEventHandler"
	@onInput="onInputEventHandler"
	@onFocus="onFocusEventHandler"
	@onBlur="onBlurEventHandler"
>
</vue3-simple-typeahead>

User interaction

When the user types on the typeahead input and the minimum input length is meeted a suggestion list appears below the input with the items that match the user input. You can continue to type further to filter the selection, but you could use keyboard or mouse input to make your selection.abnf

When the suggestion list show up, you can continue to type to filter the selection or you use the Arrow Up or Arrow Down keys to navigate the list of suggestions. When you have selected the desired element press Enter or TAB to select the current element.

ControlEffect
Navigate up on the suggestion list, selecting the previous element
Navigate down on the suggestion list, selecting the next element
EnterChoose the current element selection
TABChoose the current element selection

You can use the mouse instead, simply hover you cursor over the desire element and click on it.

User controls

Props

PropTypeDefaultDescription
idStringRandom id generationThe id for the input control. Can be useful to link with a label for=""
placeholderString''Placeholder text for the input
itemsArray (Required)List of objects or strings with the elements for suggestions
minInputLengthNumber2Minimum input length for the suggestion length to appear, the prop value has to be >= 0
itemProjectionFunction: String(item) => {return item;}Projection function to map the items to a string value for search and display

Remember you can always use lower-kebap-case for camelCase props like min-input-length

Events

EventSignatureDescription
selectItemfunction (item: String): voidEmitted when the user selects an item from the suggestion list
onInputfunction (event: Object { input: String, items: Array }): voidEmitted when the user types anything
onFocusfunction (event: Object { input: String, items: Array }): voidEmitted when the input control get the focus
onBlurfunction (event: Object { input: String, items: Array }): voidEmitted when the input control lost the focus [When the user select an item, the focus is lost too]

Keywords

FAQs

Package last updated on 11 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc