Skip to content

Commit c2ff9ad

Browse files
committed
[added] property disabled on MenuItem
1 parent 1b98730 commit c2ff9ad

File tree

6 files changed

+75
-3
lines changed

6 files changed

+75
-3
lines changed

docs/assets/docs.css

+9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* Responsive tests
3030
* Glyphicons
3131
* Customizer
32+
* MenuItem
3233
* Miscellaneous
3334
*/
3435

@@ -1127,6 +1128,14 @@ h1[id] {
11271128
overflow: auto;
11281129
}
11291130

1131+
/* MenuItem */
1132+
.bs-example .dropdown-menu.open {
1133+
position: static;
1134+
display: block;
1135+
margin-bottom: 5px;
1136+
clear: left;
1137+
}
1138+
11301139

11311140
/*
11321141
* Code snippets

docs/examples/MenuItem.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function onSelectAlert(eventKey, href, target) {
2+
alert('Alert from menu item.\neventKey: "' + eventKey + '"\nhref: "' + href + '"');
3+
}
4+
5+
function preventDefault() {}
6+
7+
const MenuItems = (
8+
<div className="clearfix">
9+
<ul className="dropdown-menu open">
10+
<MenuItem header>Header</MenuItem>
11+
<MenuItem onSelect={preventDefault}>link</MenuItem>
12+
<MenuItem divider/>
13+
<MenuItem header>Header</MenuItem>
14+
<MenuItem onSelect={preventDefault}>link</MenuItem>
15+
<MenuItem disabled>disabled</MenuItem>
16+
<MenuItem title="See? I have a title." onSelect={preventDefault}>
17+
link with title
18+
</MenuItem>
19+
<MenuItem eventKey={1} href="#someHref" onSelect={onSelectAlert}>
20+
link that alerts
21+
</MenuItem>
22+
</ul>
23+
</div>
24+
);
25+
26+
React.render(MenuItems, mountNode);

docs/src/ComponentsPage.js

+21
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,25 @@ const ComponentsPage = React.createClass({
170170
<ReactPlayground codeText={Samples.SplitButtonRight} />
171171
</div>
172172

173+
{/* Menu Item */}
174+
<div className='bs-docs-section'>
175+
<h1 id='menu-item' className='page-header'>Menu Item <small> MenudItem</small></h1>
176+
<p>This is a component used in other components (see <a href="buttons">Buttons</a>, <a href="#navbars">Navbars</a>).</p>
177+
<p>It supports the basic anchor properties <code>href</code>, <code>target</code>, <code>title</code>.</p>
178+
<p>It also supports different properties of the normal Bootstrap MenuItem.
179+
<ul>
180+
<li><code>header</code>: To add a header label to sections</li>
181+
<li><code>divider</code>: Adds an horizontal divider between sections</li>
182+
<li><code>disabled</code>: shows the item as disabled, and prevents the onclick</li>
183+
<li><code>eventKey</code>: passed to the callback</li>
184+
<li><code>onSelect</code>: a callback that is called when the user clicks the item.</li>
185+
</ul>
186+
<p>The callback is called with the following arguments: <code>eventKey</code>, <code>href</code> and <code>target</code></p>
187+
</p>
188+
<ReactPlayground codeText={Samples.MenuItem} />
189+
</div>
190+
191+
{/* Panels */}
173192
<div className='bs-docs-section'>
174193
<h1 id='panels' className='page-header'>Panels <small>Panel, PanelGroup, Accordion</small></h1>
175194

@@ -607,6 +626,7 @@ const ComponentsPage = React.createClass({
607626
<code>getValue()</code> will not work when used this way.</p>
608627
<ReactPlayground codeText={Samples.InputWrapper} />
609628
</div>
629+
610630
</div>
611631

612632
<div className='col-md-3'>
@@ -623,6 +643,7 @@ const ComponentsPage = React.createClass({
623643
<SubNav href='#buttons' key={1} text='Buttons'>
624644
<NavItem href='#btn-groups' key={2}>Button groups</NavItem>
625645
<NavItem href='#btn-dropdowns' key={3}>Button dropdowns</NavItem>
646+
<NavItem href='#menu-item' key={25}>Menu Item</NavItem>
626647
</SubNav>
627648
<NavItem href='#panels' key={4}>Panels</NavItem>
628649
<NavItem href='#modals' key={5}>Modals</NavItem>

docs/src/Samples.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,6 @@ export default {
9696
InputSizes: require('fs').readFileSync(__dirname + '/../examples/InputSizes.js', 'utf8'),
9797
InputValidation: require('fs').readFileSync(__dirname + '/../examples/InputValidation.js', 'utf8'),
9898
InputHorizontal: require('fs').readFileSync(__dirname + '/../examples/InputHorizontal.js', 'utf8'),
99-
InputWrapper: require('fs').readFileSync(__dirname + '/../examples/InputWrapper.js', 'utf8')
99+
InputWrapper: require('fs').readFileSync(__dirname + '/../examples/InputWrapper.js', 'utf8'),
100+
MenuItem: require('fs').readFileSync(__dirname + '/../examples/MenuItem.js', 'utf8')
100101
};

src/MenuItem.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const MenuItem = React.createClass({
1010
target: React.PropTypes.string,
1111
onSelect: React.PropTypes.func,
1212
eventKey: React.PropTypes.any,
13-
active: React.PropTypes.bool
13+
active: React.PropTypes.bool,
14+
disabled: React.PropTypes.bool
1415
},
1516

1617
getDefaultProps() {
@@ -21,6 +22,10 @@ const MenuItem = React.createClass({
2122
},
2223

2324
handleClick(e) {
25+
if (this.props.disabled) {
26+
e.preventDefault();
27+
return;
28+
}
2429
if (this.props.onSelect) {
2530
e.preventDefault();
2631
this.props.onSelect(this.props.eventKey, this.props.href, this.props.target);
@@ -39,7 +44,8 @@ const MenuItem = React.createClass({
3944
let classes = {
4045
'dropdown-header': this.props.header,
4146
'divider': this.props.divider,
42-
'active': this.props.active
47+
'active': this.props.active,
48+
'disabled': this.props.disabled
4349
};
4450

4551
let children = null;

test/MenuItemSpec.js

+9
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,13 @@ describe('MenuItem', function () {
107107
);
108108
ReactTestUtils.Simulate.click(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a'));
109109
});
110+
111+
it('Should be `disabled` link', function () {
112+
let instance = ReactTestUtils.renderIntoDocument(
113+
<MenuItem disabled>
114+
Title
115+
</MenuItem>
116+
);
117+
assert.ok(instance.getDOMNode().className.match(/\bdisabled\b/));
118+
});
110119
});

0 commit comments

Comments
 (0)