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

react-autocompleter

v1.0.10

Published

A simple, configurable, styleable ReactJS component which completes your phrase with keyboard navigation support.

Downloads

8

Readme

React AutoCompleter

A React component which filters on phrases and returns similar results, with a simple API, keyboard navigation and no style hijacking.

npm install react-autocompleter --save

http://invertase.github.io/react-autocompleter/example

Basic Usage

import React, { Component } from 'react';
import AutoCompleter from 'react-autocompleter';

const data = [
    'phrase one',
    'phrase two'
];

class MyComponent extends Component {

    render() {
        return (
            <AutoCompleter
                data={ data }
                placeholder='Search...'
                limit={ 10 }
            />
        );
    }

}

Styling

By default this component does not provide any styling, however it gives you the ability to easily style the specific component yourself:

CSS Classes

Pass in an object of class names to the component, and style with your own CSS/LESS/SASS like any other HTML element:

classes={ {
    root: 'autocomplete',
    input: 'autocomplete-input',
    listContainer: 'autocomplete-container',
    listItems: 'autocomplete-items'
} }

Inline Styles

Pass an object on inline styles directly into the component:

styles={ {
    root: {
        padding: '10px'
    },
	input: {
		fontSize: '14px'
	},
	listContainer: {
		listStyleType: 'none',
		background: '#ffffff',
		padding: '20px'
	},
	listItems: {
		padding: '15px',

		'.active': {
			fontSize: '30px'
		}
	}
} }

Component API

placeholder (string)

A string which is injected into the input box as a placeholder.

placeholder='Search...'

data (array|required)

A single dimension array of phrases which are filtered on user input.

data={ [
    'phrase one',
    'phrase two'
] }

limit (number|default:20)

Limit the amount of filtered results returned.

Set to 0 for no limit.

limit={ 10 }

value (string)

The initial/default value on the input.

value='keyword'

keyboard (bool|default:true)

If set to false, keyboard navigation will be disabled.

keyboard={ false }

onSelect (function)

Triggered on item select, either via keyboard navigation (ENTER), or by clicking an item.

onSelect={ (item) => { console.log('selected item ', item) } }

onFocus (function)

Triggered on input box focus.

onFocus={ () => { console.log('input focused') } }

onBlur (function)

Triggered on input box blur.

onBlur={ () => { console.log('input blurred') } }

onChange (function)

Triggered on input change, including the navigated value.

onChange={ (value) => { console.log('input changed to', value) } }

inputProps (object)

An object of properties which will be passed to the input element as attributes:

inputProps={ {
    type: 'password',
    name: 'bon'
} }

Misc

Handling onChange & onSelect

Since clicking a filtered item does not trigger onChange, the item is passed as the callback on the onSelect function. There might be a case where your onSelect function needs to handle both the state value and the callback value:

selected = (value) => {
    const input = !value ? this.state.url : value;
}

Browser Autofill

Browsers like Chrome sometimes autofill input elements if you've added the name attribute something common, like "name" or "url", which overrides this components functionality (annoyingly!). To disabled this, add the following:

inputProps={ {
    autoComplete='off'
} }

Development

Whilst developing, this repository makes use of webpack & webpack hot reloading.

The playground directory is the place to test changes to the component, or play around with the component API. Any changes you make, to either playground or src will be hot reloaded.

Run the script npm run playground, and open http://localhost:3000 in your browser.

Contributing

Please ensure any pull requests have been tested, and follow the linting configuration.

Run npm run lint to spot any linting issues.