Skip to content

Commit 59a0bc5

Browse files
committed
fix: Remove htmlAttribute in favor of cssClass
1 parent 874fdca commit 59a0bc5

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

Diff for: components/IndexSelector.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@ class IndexSelector extends React.Component {
88
render() {
99
var currentIndex = this.props.currentIndex;
1010
var indices = this.props.indices;
11-
var htmlAttributes = this.props.htmlAttributes;
12-
// React needs `className` in place of `class`
13-
if (htmlAttributes.class) {
14-
htmlAttributes.className = htmlAttributes.class;
15-
htmlAttributes.class = null;
16-
}
11+
var cssClass = this.props.cssClass;
12+
var selectId = this.props.containerId + '-select';
1713

1814
return (
1915
<select
20-
{...htmlAttributes}
16+
id={selectId}
17+
className={cssClass}
2118
onChange={this.handleChange.bind(this)}
2219
value={currentIndex}
2320
>
@@ -30,8 +27,9 @@ class IndexSelector extends React.Component {
3027
}
3128

3229
IndexSelector.propTypes = {
30+
containerId: React.PropTypes.string,
31+
cssClass: React.PropTypes.string,
3332
currentIndex: React.PropTypes.string,
34-
htmlAttributes: React.PropTypes.object,
3533
indices: React.PropTypes.array,
3634
setIndex: React.PropTypes.func
3735
};

Diff for: example/app.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ search.addWidget(
3030
{name: 'instant_search_price_asc', label: 'Lowest price'},
3131
{name: 'instant_search_price_desc', label: 'Highest price'}
3232
],
33-
htmlAttributes: {
34-
id: 'indexSelectorDropdown',
35-
class: 'form-control'
36-
}
33+
cssClass: 'form-control'
3734
})
3835
);
3936

Diff for: example/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ <h1>Instant search demo <small>using instantsearch.js</small></h1>
4646
<div class="col-md-4 text-right">
4747
<div class="form-inline">
4848
<div class="form-group">
49-
<label>Sort by:</label>
49+
<label for="index-selector-select">Sort by:</label>
5050
<span id="index-selector"></span>
5151
</div>
5252
</div>

Diff for: widgets/index-selector.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ var utils = require('../lib/widget-utils.js');
77
* Instantiate a dropdown element to choose the current targeted index
88
* @param {String|DOMElement} options.container Valid CSS Selector as a string or DOMElement
99
* @param {Array} options.indices Array of objects defining the different indices to choose from. Each object must contain a `name` and `label` key.
10-
* @param {String} [options.htmlAttributes] Object of html attributes to be passed to the generated `select` element
10+
* @param {String} options.cssClass Class name(s) to be added to the generated select element
1111
* @return {Object}
1212
*/
1313
function indexSelector({
1414
container = null,
15-
htmlAttributes = {},
15+
cssClass = {},
1616
indices = null
1717
}) {
1818
var IndexSelector = require('../components/IndexSelector');
@@ -33,9 +33,11 @@ function indexSelector({
3333
},
3434

3535
render: function(results, state, helper) {
36+
var containerId = containerNode.id;
3637
React.render(
3738
<IndexSelector
38-
htmlAttributes={htmlAttributes}
39+
containerId={containerId}
40+
cssClass={cssClass}
3941
currentIndex={helper.getIndex()}
4042
indices={indices}
4143
setIndex={helper.setIndex.bind(helper)}

0 commit comments

Comments
 (0)