GithubHelp home page GithubHelp logo

Comments (4)

jquense avatar jquense commented on July 19, 2024

I'm not quite sure what you mean by externally. Could you expand or maybe illustrate what you have in mind? which is to say, i might very well be open to it once i understand it!

from react-widgets.

dwick avatar dwick commented on July 19, 2024

Sure.. styles a bit out of whack, but here's a quick example:

screen shot 2015-03-03 at 11 11 49 pm

Basically what i'd like to be able to do is set a container for the taglist that isn't the multiselect itself.

from react-widgets.

jquense avatar jquense commented on July 19, 2024

gotcha. I have actually had this need also. I think it would be tough to structure a PR that would work well in this case, and I don't think that this sort of thing makes a lot of sense in the library proper. But I do want to make sure the widgets are flexible and extensible enough that stuff like this is easy enough to do yourself. In this case I think we are already there, provided you feel comfortable using a technically private component.

This is a bit of an oversimplification, you may have to cover some edge cases (like figure out how you'd want keyboard navigation of tags to work here), but you can easily wrap this pattern up into a few components in your own code to reduce some of the wiring needed to get it working.

var Multiselect = require('react-widgets/lib/Multiselect');
var TagList = require('react-widgets/lib/MultiselectTagList');

var App = React.createClass({

  getInitialState(){
    return {
      data: list,
      values: [],
    }
  },

  render(){
    var self = this;

    function onChange([value]){
      self.setState({
        values: self.state.values.concat(value), 
         // remove the value from the data list so it can't be re-selected
        data:   self.state.data.filter( v => v !== value)
      })
    }

    function onDelete(val){
      self.setState({
        values: self.state.values.filter( v => v !== val),
        data:   self.state.data.concat(val)
      })
    }

    return (<div>
            <Multiselect data={this.state.data} value={[]} onChange={onChange} />
            <TagList value={this.state.values} onDelete={onDelete} />
      </div>)
  }
})

The above is written in es6 you can look here to see the compiled es5 version

from react-widgets.

dwick avatar dwick commented on July 19, 2024

that works perfectly, thanks for the quick response!

from react-widgets.

Related Issues (20)

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.