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-datalist

v4.0.0

Published

A <datalist> polyfill for reactjs

Downloads

742

Readme

React-datalist

testling badge

React-datalist is an attempt at making a <datalist> polyfill as a reusable react module.

Feedback in the form of issues and pull-requests is very much appreciated!

Check out the DEMO

PS! For use with [email protected] or earlier, user [email protected]. 2.0.0 support [email protected] and newer.

Install

npm install react-datalist

Use

var React = require('react')
var ReactDatalist = require('react-datalist')

var options = ['apple','orange','pear','pineapple','melon']
React.render(<ReactDatalist list="fruit" options={options} />, document.body)

Props

list             * - <datalist id="list"> and <input list="list">
options          * - the available options
placeholder        - a placeholder for the input field
forcePoly          - always use the polyfill                     (default false)
blurTimeout        - timeout after blur before hinding opts      (default 200ms)
autoPosition       - automatically position the options list     (default true)
initialFilter      - set the initial input value                 (default '')
hideOptionsOnEsc   - hide options on esc                         (default true)
hideOptionsOnBlur  - hide options on input blur                  (default true)
includeLayoutStyle - include internal layout styling (style tag) (default true)
onOptionSelected   - callback triggered when option is considered selected
getController      - pass a function to collect a controller object (see below)

* = required

getController

The getController property is there to enable external control of the component's inner state - while keeping the state in sync. It takes a function that will return a controller object.

getController : function(controller) { /* ... */ }

The controller offers the following

controller.setFilter(string, callback)  - sets the value of the input
controller.toggleOptions(callback)      - toggle show/hide of options. shown bool passed to callback.
controller.getState()                   - gets the current inner state
controller.setState(newState, callback) - set a new inner state

!TLDR;

React-datalist includes both a input and a datalist element. In order to stay fairly simple to use, align with react and avoid native events and other trickery, this was necessary. The structure is as follows:

// Native

<div class="react-datalist-container">
	<input class="react-datalist-input">
	<datalist class="react-datalist">
		<option value="values">
	</datalist>
</div>

// Polyfill

<div class="react-datalist-container">
	<input class="react-datalist-input">
	<div class="react-datalist">
		<div class="react-datalist-option">values</div>
	</div>
</div>

If you need to interact with the input element, attach listeners like onInputChange, onInputBlur, etc. (Note to self: expose additional input events. Note to others: encourage by creating issues)

Styling

There is also some (quite useful) styling you can/should use. You can find it under node_modules/react-datalist/react-datalist.styl. If you don't use stylus it's pretty small and easy to copy. I might include it if I pack up a UMD module for React-datalist. Anyone want that? Create an issue :-)

(Note to self: Convert styling to plain css)
(Idea: Should I pack a commonjs module that include the styling?)

JSX

The module itself does not make us of JSX as not to impose restrictions on the user.

Features

For a full feature list check out the spec.

Changelog

4.0.0

  • Bumped React peerDependency major version to ^15.0.0 :tada: thanks to @dcousens

3.0.0

  • Support for React v0.14 :rocket:
  • Updated testdom which also updates jsdom wich in turn requires node 4+ :stuck_out_tongue_closed_eyes:

2.0.0

  • Support for React v0.13 :tada: :rocket:

1.3.1

  • Moved react to peerDependencies with >= instaed of ^

1.3.0

  • Added support for props.className to set extra classes (by @blackbing #11)
  • Added support for props.defaultValue to set default value (by @blackbing #11)

1.2.0

  • Added hideOptionsOnEsc for the ability to opt out of hiding options when user hits esc
  • Added controller.getState for a sneak peak at the inner state
  • Added controller.setState for improved external control

1.1.0

  • Bumped the blurTimeout up to 200ms (people were having issues)
  • Added the ability to specify blurTimeout via props
  • Added hideOptionsOnBlur for the ability to opt out of hide-options-on-blur

1.0.0

  • Removed setFilter support
  • Added a more generic getController prop that returns an object with functions for external control
  • Added setFilter to controller
  • Added toggleOptions to controller

0.2.0

  • Added support for externally controlling the filter state via the setFilter property.

0.1.2

  • Minor improvement to help testing (test are too fast for my timeouts :-P)

0.1.1

  • Increased hide-options timeout on blur (more time to make click register)
  • Supporting placeholder property for input

0.1.0

  • Added support for passing initial input value via the initialFilter property.

0.0.1

  • Initial release! YaY :-D

enjoy.