forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDropdownToggle.js
More file actions
62 lines (51 loc) · 1.4 KB
/
Copy pathDropdownToggle.js
File metadata and controls
62 lines (51 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React from 'react';
import classNames from 'classnames';
import Button from './Button';
import SafeAnchor from './SafeAnchor';
import { bsClass as setBsClass } from './utils/bootstrapUtils';
const propTypes = {
noCaret: React.PropTypes.bool,
open: React.PropTypes.bool,
title: React.PropTypes.string,
useAnchor: React.PropTypes.bool,
};
const defaultProps = {
open: false,
useAnchor: false,
bsRole: 'toggle',
};
class DropdownToggle extends React.Component {
render() {
const {
noCaret,
open,
useAnchor,
bsClass,
className,
children,
...props
} = this.props;
delete props.bsRole;
const Component = useAnchor ? SafeAnchor : Button;
const useCaret = !noCaret;
// This intentionally forwards bsSize and bsStyle (if set) to the
// underlying component, to allow it to render size and style variants.
// FIXME: Should this really fall back to `title` as children?
return (
<Component
{...props}
role="button"
className={classNames(className, bsClass)}
aria-haspopup
aria-expanded={open}
>
{children || props.title}
{useCaret && ' '}
{useCaret && <span className="caret" />}
</Component>
);
}
}
DropdownToggle.propTypes = propTypes;
DropdownToggle.defaultProps = defaultProps;
export default setBsClass('dropdown-toggle', DropdownToggle);