Skip to content

Commit

Permalink
fix(dropdowns): buttonClassName is propagted properly
Browse files Browse the repository at this point in the history
buttonClassName is merged and applied to the button

[Finishes #98913274]
  • Loading branch information
Caroline Taymor and Geoff Pleiss committed Jul 21, 2015
1 parent 87b40f7 commit 4e88e37
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
7 changes: 4 additions & 3 deletions spec/pivotal-ui-react/dropdown/dropdown_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('Dropdowns', function() {
describe(dropdownComponentName, function() {
beforeEach(function() {
var DropdownClass = require('../../../src/pivotal-ui-react/dropdowns/dropdowns')[dropdownComponentName];
React.render(<DropdownClass title="Dropping"/>, root);
React.render(<DropdownClass title="Dropping" buttonClassName="test-btn-class"/>, root);
});

afterEach(function() {
Expand All @@ -18,9 +18,10 @@ describe('Dropdowns', function() {
expect('button.dropdown-toggle').toContainText('Dropping');
});

it('adds the appropriate button classes to the dropdown toggle', () => {
it('adds the appropriate button classes (merging in buttonClassName) to the dropdown toggle', () => {
expect('button.dropdown-toggle').toHaveClass(dropdownClassName);
expect('button.dropdown-toggle').not.toHaveClass('btn-default');
expect('.dropdown-toggle').toHaveClass('test-btn-class');
});
});
}
Expand Down Expand Up @@ -54,7 +55,7 @@ describe('Dropdowns', function() {
expect('#root #test-id').toExist();
});

it('create a dropdown-toggle, merging buttonClassName with the provided one', () => {
it('creates a dropdown-toggle', () => {
expect('.dropdown-toggle').toContainText('Dropping');
expect('.dropdown-toggle').toHaveClass('btn-default');
expect('.dropdown-toggle').toHaveClass('test-btn-class');
Expand Down
11 changes: 8 additions & 3 deletions src/pivotal-ui-react/dropdowns/dropdowns.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var React = require('react');
import {mergeProps} from '../../../src/pivotal-ui-react/helpers/helpers';
import classnames from 'classnames';

/**
* @component Dropdown
Expand Down Expand Up @@ -31,11 +31,16 @@ var Dropdown = require('react-bootstrap').DropdownButton;
function defDropdown(props) {
return React.createClass({
render() {
var others = mergeProps(props, this.props);
return <Dropdown {...others}/>;
const {buttonClassName, ...others} = this.props;
const {buttonClassName: defaultBtnClassName, bsStyle} = props;

const btnClass = classnames(buttonClassName, defaultBtnClassName);

return <Dropdown buttonClassName={btnClass} bsStyle={bsStyle} {...others}/>;
}
});
}

module.exports = {
Dropdown,

Expand Down
3 changes: 2 additions & 1 deletion src/pivotal-ui-react/dropdowns/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"react-bootstrap": "0.23.3",
"pui-css-dropdowns": "1.10.0",
"pui-css-iconography": "1.10.0",
"pui-css-buttons": "1.10.0"
"pui-css-buttons": "1.10.0",
"classnames": "^2.1.2"
}
}
4 changes: 2 additions & 2 deletions src/pivotal-ui/components/dropdowns/dropdowns.scss
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ If you want to customize the dropdown button, you can add modifier classes to it
using the `buttonClassName` property:
```react_example
<UI.Dropdown title='DropDown' buttonClassName='type-neutral-1 em-alt type-sm'>
<UI.DefaultAltDropdown title='DropDown' buttonClassName='btn-lg'>
<UI.DropdownItem href="http://media.giphy.com/media/13py6c5BSnBkic/giphy.gif">Booyeah</UI.DropdownItem>
<UI.DropdownItem divider />
<UI.DropdownItem href="http://media.giphy.com/media/TlK63EQERmiAVzMEgO4/giphy.gif">Adorable</UI.DropdownItem>
</UI.Dropdown>
</UI.DefaultAltDropdown>
```
*/
Expand Down

0 comments on commit 4e88e37

Please sign in to comment.