Giter VIP home page Giter VIP logo

algolia-react-autocomplete's Introduction

Usage

$ npm i algoliasearch algolia-react-autocomplete"
import algoliasearch from "algoliasearch";

import Autocomplete from "algolia-react-autocomplete";
import "algolia-react-autocomplete/build/css/index.css";


// init algoliasearch sdk and indexes
const client = algoliasearch('myApplicationID', 'myApiKey');
const indexes = [
      {
        source: this.client.initIndex("players"),
        displayKey: 'name',
        templates: {
          header: () => <h2 className="aa-suggestions-category"> Players</h2>
          suggestion: (suggestion, isSelected) => <div data-selected={isSelected}> {suggestion.name} </div>
        }
      },
]


// in your render method
<Autocomplete indexes={indexes} onSelectionChange={selectedSuggestion => console.log(selectedSuggestion)>
    <input key="input" type="search" className="aa-input-search" autocomplete="off" />
</Autocomplete>

Run demo

$ git clone https://github.com/tkrugg/algolia-react-autocomplete.git
$ cd algolia-react-autocomplete
$ npm i
$ npm start

There is a demo hosted here: https://codesandbox.io/s/kk4v5nqrz5

FAQ

why do I have to install algoliasearch myself, can't I just pass in my credentials inside the component

You're right. This component makes assumptions on the algolia sdk it's being passed, embedding the lib is safer. But I'm suspecting the user might be using this same sdk as a data source for other components. This is more flexible.

CSS is for dummies, why not inline styles?

CSS classes are easier and faster to override. With inline styles we'd have to expose every style attribute under that piece of DOM. Plus, I just hate inline styles ๐ŸงŒ. Please try to change my mind, don't give up on me.

Credits

This component was started off this boilerplate: https://github.com/DimiMikadze/create-react-library

algolia-react-autocomplete's People

Contributors

tkrugg avatar

Stargazers

 avatar

Watchers

 avatar

algolia-react-autocomplete's Issues

Results are not hidden when clicking outside of search box or when removing text from search box.

Current behavior
When I type in the search box the results appear under it but they do not go away unless you press the ESC key.

Minimal example
codesandbox.io/s/peaceful-chebyshev-1g1oj

Expected behavior
I expect the results to go away whenever I click outside of the search box and to re-appear when I click back inside of it. I also expect the results to go away if I remove what was typed into the search box but that just makes all possible results appear. The only way to currently make the results go away is to press ESC which I doubt many of my visitors will know about.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.