Skip to content

Commit 935171f

Browse files
author
Mathieu M-Gosselin
committed
[added] Now accepting a block property on the ButtonGroup component.
Closes react-bootstrap#240.
1 parent 353b4f0 commit 935171f

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

docs/examples/ButtonGroupBlock.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const buttonGroupInstance = (
2+
<ButtonGroup vertical block>
3+
<Button>Full width button</Button>
4+
<Button>Full width button</Button>
5+
</ButtonGroup>
6+
);
7+
8+
React.render(buttonGroupInstance, mountNode);

docs/src/ComponentsPage.js

+3
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ const ComponentsPage = React.createClass({
127127
className='text-danger'>Split button dropdowns are not supported here.</strong></p>
128128
<p>Just add <code>vertical</code> to the <code>{'<ButtonGroup />'}</code>.</p>
129129
<ReactPlayground codeText={Samples.ButtonGroupVertical} />
130+
<br />
131+
<p>Moreover, you can have buttons be block level elements so they take the full width of their container, just add <code>block</code> to the <code>{'<ButtonGroup />'}</code>, in addition to the <code>vertical</code> you just added.</p>
132+
<ReactPlayground codeText={Samples.ButtonGroupBlock} />
130133

131134
<h3 id='btn-groups-justified'>Justified button groups</h3>
132135
<p>Make a group of buttons stretch at equal sizes to span the entire width of its parent. Also works with button dropdowns within the button group.</p>

docs/src/Samples.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default {
1414
ButtonGroupNested: require('fs').readFileSync(__dirname + '/../examples/ButtonGroupNested.js', 'utf8'),
1515
ButtonGroupVertical: require('fs').readFileSync(__dirname + '/../examples/ButtonGroupVertical.js', 'utf8'),
1616
ButtonGroupJustified: require('fs').readFileSync(__dirname + '/../examples/ButtonGroupJustified.js', 'utf8'),
17+
ButtonGroupBlock: require('fs').readFileSync(__dirname + '/../examples/ButtonGroupBlock.js', 'utf8'),
1718
DropdownButtonBasic: require('fs').readFileSync(__dirname + '/../examples/DropdownButtonBasic.js', 'utf8'),
1819
SplitButtonBasic: require('fs').readFileSync(__dirname + '/../examples/SplitButtonBasic.js', 'utf8'),
1920
DropdownButtonSizes: require('fs').readFileSync(__dirname + '/../examples/DropdownButtonSizes.js', 'utf8'),

src/ButtonGroup.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
import React from 'react';
22
import classNames from 'classnames';
33
import BootstrapMixin from './BootstrapMixin';
4+
import CustomPropTypes from './utils/CustomPropTypes';
45

56
const ButtonGroup = React.createClass({
67
mixins: [BootstrapMixin],
78

89
propTypes: {
910
vertical: React.PropTypes.bool,
10-
justified: React.PropTypes.bool
11+
justified: React.PropTypes.bool,
12+
block: CustomPropTypes.all([
13+
React.PropTypes.bool,
14+
function(props, propName, componentName) {
15+
if (props.block && !props.vertical) {
16+
return new Error('The block property requires the vertical property to be set to have any effect');
17+
}
18+
}
19+
])
1120
},
1221

1322
getDefaultProps() {
@@ -21,6 +30,7 @@ const ButtonGroup = React.createClass({
2130
classes['btn-group'] = !this.props.vertical;
2231
classes['btn-group-vertical'] = this.props.vertical;
2332
classes['btn-group-justified'] = this.props.justified;
33+
classes['btn-block'] = this.props.block;
2434

2535
return (
2636
<div

test/ButtonGroupSpec.js

+23
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import ReactTestUtils from 'react/lib/ReactTestUtils';
33
import ButtonGroup from '../src/ButtonGroup';
44
import Button from '../src/Button';
5+
import { shouldWarn } from './helpers';
56

67
describe('ButtonGroup', function () {
78
it('Should output a button group', function () {
@@ -38,6 +39,28 @@ describe('ButtonGroup', function () {
3839
assert.equal(instance.getDOMNode().className.trim(), 'btn-group-vertical');
3940
});
4041

42+
it('Should add block variation', function () {
43+
let instance = ReactTestUtils.renderIntoDocument(
44+
<ButtonGroup vertical block>
45+
<Button>
46+
Title
47+
</Button>
48+
</ButtonGroup>
49+
);
50+
assert.ok(instance.getDOMNode().className.match(/\bbtn-block\b/));
51+
});
52+
53+
it('Should warn about block without vertical', function () {
54+
ReactTestUtils.renderIntoDocument(
55+
<ButtonGroup block>
56+
<Button>
57+
Title
58+
</Button>
59+
</ButtonGroup>
60+
);
61+
shouldWarn('The block property requires the vertical property to be set to have any effect');
62+
});
63+
4164
it('Should add justified variation', function () {
4265
let instance = ReactTestUtils.renderIntoDocument(
4366
<ButtonGroup justified>

0 commit comments

Comments
 (0)