Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(selector): root classname is applied twice #2423

Merged
merged 10 commits into from
Oct 3, 2017
3 changes: 3 additions & 0 deletions functional-tests/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ search.addWidget(
{ label: 'Top 100', value: 9901 },
{ label: 'Top 500', value: 9501 },
],
cssClasses: {
select: 'form-control',
},
})
);

Expand Down
6 changes: 5 additions & 1 deletion src/components/Selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class RawSelector extends React.Component {

return (
<select
className={this.props.cssClasses.root}
className={this.props.cssClasses.select}
onChange={this.handleChange}
value={currentValue}
>
Expand All @@ -42,6 +42,10 @@ RawSelector.propTypes = {
PropTypes.string,
PropTypes.arrayOf(PropTypes.string),
]),
select: PropTypes.oneOfType([
PropTypes.string,
PropTypes.arrayOf(PropTypes.string),
]),
item: PropTypes.oneOfType([
PropTypes.string,
PropTypes.arrayOf(PropTypes.string),
Expand Down
4 changes: 2 additions & 2 deletions src/components/__tests__/__snapshots__/Selector-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`Selector should render <Selector/> with numbers 1`] = `
<select
className="custom-root"
className={undefined}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we update this test to not have undefined inside it? And check if select css class is actually read?

onChange={[Function]}
value={10}
>
Expand All @@ -23,7 +23,7 @@ exports[`Selector should render <Selector/> with numbers 1`] = `

exports[`Selector should render <Selector/> with strings 1`] = `
<select
className="custom-root"
className={undefined}
onChange={[Function]}
value="index-a"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ exports[`hitsPerPageSelector() calls twice ReactDOM.render(<Selector props />, c
Object {
"item": "ais-hits-per-page-selector--item custom-item",
"root": "ais-hits-per-page-selector custom-root cx",
"select": "ais-hits-per-page-selector",
}
}
currentValue={10}
Expand Down
8 changes: 6 additions & 2 deletions src/widgets/hits-per-page-selector/hits-per-page-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ const usage = `Usage:
hitsPerPageSelector({
container,
items,
[ cssClasses.{root,item}={} ],
[ cssClasses.{root,select,item}={} ],
[ autoHideContainer=false ]
})`;

/**
* @typedef {Object} HitsPerPageSelectorCSSClasses
* @property {string|string[]} [root] CSS classes added to the parent `<select>`.
* @property {string|string[]} [root] CSS classes added to the outer `<div>`.
* @property {string|string[]} [select] CSS classes added to the parent `<select>`.
* @property {string|string[]} [item] CSS classes added to each `<option>`.
*/

Expand Down Expand Up @@ -94,6 +95,9 @@ export default function hitsPerPageSelector(

const cssClasses = {
root: cx(bem(null), userCssClasses.root),
// We use the same class to avoid regression on existing website. It needs to be replaced
// eventually by `bem('select')
select: cx(bem(null), userCssClasses.select),
item: cx(bem('item'), userCssClasses.item),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('numericSelector()', () => {
shouldAutoHideContainer: false,
cssClasses: {
root: 'ais-numeric-selector custom-root cx',
select: 'ais-numeric-selector',
item: 'ais-numeric-selector--item custom-item',
},
currentValue: 1,
Expand Down
8 changes: 6 additions & 2 deletions src/widgets/numeric-selector/numeric-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const usage = `Usage: numericSelector({
container,
attributeName,
options,
cssClasses.{root,item},
cssClasses.{root,select,item},
autoHideContainer
})`;

Expand All @@ -42,7 +42,8 @@ const usage = `Usage: numericSelector({

/**
* @typedef {Object} NumericSelectorCSSClasses
* @property {string|string[]} [root] CSS classes added to the parent `<select>`.
* @property {string|string[]} [root] CSS classes added to the outer `<div>`.
* @property {string|string[]} [select] CSS classes added to the parent `<select>`.
* @property {string|string[]} [item] CSS classes added to each `<option>`.
*/

Expand Down Expand Up @@ -98,6 +99,9 @@ export default function numericSelector({

const cssClasses = {
root: cx(bem(null), userCssClasses.root),
// We use the same class to avoid regression on existing website. It needs to be replaced
// eventually by `bem('select')
select: cx(bem(null), userCssClasses.select),
item: cx(bem('item'), userCssClasses.item),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ describe('sortBySelector()', () => {
shouldAutoHideContainer: false,
cssClasses: {
root: 'ais-sort-by-selector custom-root cx',
select: 'ais-sort-by-selector',
item: 'ais-sort-by-selector--item custom-item',
},
currentValue: 'index-a',
Expand Down
8 changes: 6 additions & 2 deletions src/widgets/sort-by-selector/sort-by-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ const usage = `Usage:
sortBySelector({
container,
indices,
[cssClasses.{root,item}={}],
[cssClasses.{root,select,item}={}],
[autoHideContainer=false]
})`;

/**
* @typedef {Object} SortByWidgetCssClasses
* @property {string|string[]} [root] CSS classes added to the parent `<select>`.
* @property {string|string[]} [root] CSS classes added to the outer `<div>`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

* @property {string|string[]} [select] CSS classes added to the parent `<select>`.
* @property {string|string[]} [item] CSS classes added to each `<option>`.
*/

Expand Down Expand Up @@ -92,6 +93,9 @@ export default function sortBySelector(

const cssClasses = {
root: cx(bem(null), userCssClasses.root),
// We use the same class to avoid regression on existing website. It needs to be replaced
// eventually by `bem('select')
select: cx(bem(null), userCssClasses.select),
item: cx(bem('item'), userCssClasses.item),
};

Expand Down