diff --git a/README.md b/README.md index cd44ff0..f41b4d7 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,14 @@ An accessible select box component for React. +Improvements: +* allow each Option to have a distinct style (using className) +* render each selected Option with a distinct style (using className) + +## Screenshots + +![screenshot](https://github.com/dungsaga/react-select-box/raw/gh-pages/screenshots/Notable-operating-systems.png) + ## Demo [http://instructure-react.github.io/react-select-box/](http://instructure-react.github.io/react-select-box/) diff --git a/lib/select-box.js b/lib/select-box.js index 70d1400..a727f7c 100644 --- a/lib/select-box.js +++ b/lib/select-box.js @@ -101,7 +101,7 @@ module.exports = React.createClass({displayName: 'exports', } else { this.updatePendingValue(val, cb) || this.props.onChange(val) this.handleClose() - this.refs.button.getDOMNode().focus() + this.refs.button.focus() } }.bind(this) }, @@ -141,7 +141,7 @@ module.exports = React.createClass({displayName: 'exports', handleOpen: function (event) { interceptEvent(event) this.setState({open: true}, function () { - this.refs.menu.getDOMNode().focus() + this.refs.menu.focus() }) }, @@ -209,10 +209,10 @@ module.exports = React.createClass({displayName: 'exports', .filter(function (option) { return this.isSelected(option.value) }.bind(this)) - .map(function (option) { - return option.label + .map(function (option, i) { + return label({ key: i, className: option.className }, option.label) }) - return selected.length > 0 ? selected.join(', ') : this.props.label + return selected.length > 0 ? selected : this.props.label }, isMultiple: function () { @@ -223,6 +223,7 @@ module.exports = React.createClass({displayName: 'exports', var options = [] React.Children.forEach(this.props.children, function (option) { options.push({ + className: option.props.className, value: option.props.value, label: option.props.children }) @@ -350,6 +351,9 @@ module.exports = React.createClass({displayName: 'exports', if (this.isSelected(option.value)) { className += ' react-select-box-option-selected' } + if (option.className) { + className += ' ' + option.className + } return a( { id: this.state.id + '-' + i,