GithubHelp home page GithubHelp logo

quantalytix / react-dropdownbox Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 392 KB

A lightweight react select box that allows for searching and displaying of nested and grouped results.

License: MIT License

JavaScript 86.56% CSS 13.44%
react dropdown-input select selectbox dropdown combobox grouping nesting

react-dropdownbox's Introduction

react-dropdownbox

NPM JavaScript Style Guide

Install

npm i @quantalytix/react-dropdownbox

Demo Screenshot

ScreenShot

Usage

import React, { Component } from 'react'

import ReactDropdown from '@quantalytix/react-dropdownbox'
import '@quantalytix/react-dropdownbox/dist/index.es.css'

class Example extends Component {
  render () {
    const sampleList = [
      {
        key: 1, text: 'Fictional Characters', value: 'Fictional Characters', children: [
          { key: 1, text:'Joker', value: 'Joker' },
          { key: 2, text:'Batman', value: 'Batman' },
          { key: 3, text:'Robin', value: 'Robin' },
          { key: 4, text:'Two-Face', value: 'Two-Face' },
          {
            key: 5, text:'Not a Superhero', value: 'Not a Superhero', children: [
              { key: 1, text:'Koolaid Man', value: 'Koolaid Man' },
              { key: 1, text:'Koolaid Woman', value: 'Koolaid Woman' },
              { key: 1, text:'Koolaid Woman Twin', value: 'Koolaid Woman Twin' },
              { key: 2, text:'Joe Dirt', value: 'Joe Dirt' },
            ]
          },
        ]
      },
      {
        key: 2, text:'Real People', value: 'Real People', children: [
          { key: 2, text:'Jenn', value: 'Jenn' },
          { key: 3, text:'Will', value: 'Will' },
          { key: 3, text:'Chris', value: 'Chris' },
          { key: 3, text:'Bradley', value: 'Bradley' },
          { key: 3, text:'Ben', value: 'Ben' },
          { key: 3, text:'Min', value: 'Min' },
          { key: 3, text:'Luke', value: 'Luke' }          
        ]
      }
    ]

    return (
      <ReactDropdown data={sampleList} placeholder='search or select' initialValue='Fictional Characters' onSelect={()=>{}}/>
    )
  }
}

License

MIT © quantalytix

react-dropdownbox's People

Contributors

chrisaliotta avatar jennianelson avatar

Stargazers

 avatar

Watchers

 avatar

react-dropdownbox's Issues

Investigate and replace the document.click event logic

@jennianelson When the component loses focus through a tab or other element focus event there is a routine that is run on our documentClick event. My concern is that if there are more than one dropdown boxes and a second one is selected that the first dropdown box will remain open based on the logic below.

handleClick = (e) => {   
    // if there are multiple dropdowns rendered on a single page
    // will this logic create a problem?
    let found = e.path.find(el => el.className === "react-dropdown")
    if (!!!found) {
      this.closeDropdown();
      this.resetSelection();
    }
  }

I started hacking together a different process but I still think it might have the same problem (and at the moment this does not work):

handleClick = (e) => {
    // we can use a forwardRef to potentially solve this...
    console.log(ReactDOM.findDOMNode(this.refs.dropdownbox)); // <div class="react-dropdown">...</div>
    console.log(document.activeElement); // <input class="input-box" placeholder="" ...>
    if (document.activeElement !== ReactDOM.findDOMNode(this.refs.dropdownbox)) {
      this.closeDropdown();
      this.resetSelection();
    }
}

Thoughts?

Default styles need to be cleaned up

The default style of the drop down box needs to be cleaned up and made more easy to update. The SASS file should be provided in the distribution files.

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.