Skip to content

Commit

Permalink
feat: Add htmlAttributes to indexSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelastic committed Sep 8, 2015
1 parent 6d88dd0 commit ceed8ae
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
11 changes: 8 additions & 3 deletions components/IndexSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ class IndexSelector extends React.Component {
render() {
var currentIndex = this.props.currentIndex;
var indices = this.props.indices;
var cssClass = this.props.cssClass;
var htmlAttributes = this.props.htmlAttributes;
// React needs `className` in place of `class`
if (htmlAttributes.class) {
htmlAttributes.className = htmlAttributes.class;
htmlAttributes.class = null;
}

return (
<select
className={cssClass}
{...htmlAttributes}
onChange={this.handleChange.bind(this)}
value={currentIndex}
>
Expand All @@ -25,8 +30,8 @@ class IndexSelector extends React.Component {
}

IndexSelector.propTypes = {
cssClass: React.PropTypes.string,
currentIndex: React.PropTypes.string,
htmlAttributes: React.PropTypes.object,
indices: React.PropTypes.array,
setIndex: React.PropTypes.func
};
Expand Down
5 changes: 4 additions & 1 deletion example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ search.addWidget(
{'name': 'instant_search_price_asc', 'label': 'Lowest price'},
{'name': 'instant_search_price_desc', 'label': 'Highest price'}
],
cssClass: 'form-control'
htmlAttributes: {
id: 'indexSelectorDropdown',
class: 'form-control'
}
})
);

Expand Down
7 changes: 3 additions & 4 deletions widgets/index-selector.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
var React = require('react');
var cx = require('classnames');

var findIndex = require('lodash/array/findIndex');
var utils = require('../lib/widget-utils.js');

function indexSelector({
container = null,
cssClass = null,
htmlAttributes = {},
indices = null
}) {
var IndexSelector = require('../components/IndexSelector');
var containerNode = utils.getContainerNode(container);

var usage = 'Usage: indexSelector({container, indices[, cssClass]})';
var usage = 'Usage: indexSelector({container, indices[, htmlAttributes]})';
if (container === null || indices === null) {
throw new Error(usage);
}
Expand All @@ -29,7 +28,7 @@ function indexSelector({
render: function(results, state, helper) {
React.render(
<IndexSelector
cssClass={cx(cssClass)}
htmlAttributes={htmlAttributes}
currentIndex={helper.getIndex()}
indices={indices}
setIndex={helper.setIndex.bind(helper)}
Expand Down

0 comments on commit ceed8ae

Please sign in to comment.