Skip to content

Commit

Permalink
fix: Remove htmlAttribute in favor of cssClass
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelastic committed Sep 8, 2015
1 parent 874fdca commit 59a0bc5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
14 changes: 6 additions & 8 deletions components/IndexSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ class IndexSelector extends React.Component {
render() {
var currentIndex = this.props.currentIndex;
var indices = this.props.indices;
var htmlAttributes = this.props.htmlAttributes;
// React needs `className` in place of `class`
if (htmlAttributes.class) {
htmlAttributes.className = htmlAttributes.class;
htmlAttributes.class = null;
}
var cssClass = this.props.cssClass;
var selectId = this.props.containerId + '-select';

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

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

Expand Down
2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ <h1>Instant search demo <small>using instantsearch.js</small></h1>
<div class="col-md-4 text-right">
<div class="form-inline">
<div class="form-group">
<label>Sort by:</label>
<label for="index-selector-select">Sort by:</label>
<span id="index-selector"></span>
</div>
</div>
Expand Down
8 changes: 5 additions & 3 deletions widgets/index-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ var utils = require('../lib/widget-utils.js');
* Instantiate a dropdown element to choose the current targeted index
* @param {String|DOMElement} options.container Valid CSS Selector as a string or DOMElement
* @param {Array} options.indices Array of objects defining the different indices to choose from. Each object must contain a `name` and `label` key.
* @param {String} [options.htmlAttributes] Object of html attributes to be passed to the generated `select` element
* @param {String} options.cssClass Class name(s) to be added to the generated select element
* @return {Object}
*/
function indexSelector({
container = null,
htmlAttributes = {},
cssClass = {},
indices = null
}) {
var IndexSelector = require('../components/IndexSelector');
Expand All @@ -33,9 +33,11 @@ function indexSelector({
},

render: function(results, state, helper) {
var containerId = containerNode.id;
React.render(
<IndexSelector
htmlAttributes={htmlAttributes}
containerId={containerId}
cssClass={cssClass}
currentIndex={helper.getIndex()}
indices={indices}
setIndex={helper.setIndex.bind(helper)}
Expand Down

0 comments on commit 59a0bc5

Please sign in to comment.