Skip to content

Commit

Permalink
feat(dropdown): Dropdown and DropdownItem pass through attributes
Browse files Browse the repository at this point in the history
Dropdown passes through className, id and style.
Dropdown merges buttonClassName when provided.
DropdownItem passes through className, id and style.
Updates documentation to include buttonClassName.

[Finishes #98913274]
  • Loading branch information
Caroline Taymor and Kenny Wang committed Jul 21, 2015
1 parent 2a78cda commit 87b40f7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
57 changes: 51 additions & 6 deletions spec/pivotal-ui-react/dropdown/dropdown_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require('../spec_helper');
import {itPropagatesAttributes} from '../support/shared_examples';
import {Dropdown, DropdownItem} from '../../../src/pivotal-ui-react/dropdowns/dropdowns';

describe('Dropdowns', function() {
function dropdownTestFor(dropdownComponentName, dropdownClassName) {
Expand All @@ -24,22 +26,65 @@ describe('Dropdowns', function() {
}

describe('Dropdown', function() {
var props = {
className: 'test-class',
id: 'test-id',
style: {
opacity: '1'
}
};

beforeEach(function() {
var Dropdown = require('../../../src/pivotal-ui-react/dropdowns/dropdowns').Dropdown;
React.render(<Dropdown title="Dropping"/>, root);
React.render(
<Dropdown title="Dropping" {...props} buttonClassName="test-btn-class">
<DropdownItem href="test">Item #1</DropdownItem>
</Dropdown>, root);
});

afterEach(function() {
React.unmountComponentAtNode(root);
});

it('creates a dropdown', function() {
expect('button.dropdown-toggle').toContainText('Dropping');
it('passes through className and style to the btn-group ', function() {
expect('#root .btn-group').toHaveClass('test-class');
expect('#root .btn-group').toHaveCss({opacity: '1'});
});

it('passes through id', function() {
expect('#root #test-id').toExist();
});

it('create a dropdown-toggle, merging buttonClassName with the provided one', () => {
expect('.dropdown-toggle').toContainText('Dropping');
expect('.dropdown-toggle').toHaveClass('btn-default');
expect('.dropdown-toggle').toHaveClass('test-btn-class');
});

it('renders all children DropdownItems', function() {
expect('#root .dropdown-menu li').toHaveLength(1);
expect('#root .dropdown-menu li').toHaveText('Item #1');
});
});

it('adds the appropriate button classes to the dropdown toggle', () => {
expect('button.dropdown-toggle').toHaveClass('btn-default');
describe('DropdownItem', function() {
var props = {
className: 'test-item-class',
id: 'test-item-id',
style: {
opacity: '1'
}
};
beforeEach(function() {
React.render(
<DropdownItem href='test' {...props}>Item</DropdownItem>,
root);
});

afterEach(function() {
React.unmountComponentAtNode(root);
});

itPropagatesAttributes('#root li', props);
});

dropdownTestFor('LinkDropdown', 'btn-link');
Expand Down
4 changes: 3 additions & 1 deletion src/pivotal-ui-react/dropdowns/dropdowns.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var React = require('react');
import {mergeProps} from '../../../src/pivotal-ui-react/helpers/helpers';

/**
* @component Dropdown
Expand Down Expand Up @@ -30,7 +31,8 @@ var Dropdown = require('react-bootstrap').DropdownButton;
function defDropdown(props) {
return React.createClass({
render() {
return <Dropdown {...props} {...this.props}/>;
var others = mergeProps(props, this.props);
return <Dropdown {...others}/>;
}
});
}
Expand Down

0 comments on commit 87b40f7

Please sign in to comment.