Skip to content

Commit cd3c1ce

Browse files
TheSharpieOneeddywashere
authored andcommitted
fix(DropdownToggle): support non Button styles (#221)
* fix(DropdownToggle): always use Button; passing tag if provided * fix(DropdownToggle): support non Button styles
1 parent ca9e28e commit cd3c1ce

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/DropdownToggle.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const defaultProps = {
2121
'data-toggle': 'dropdown',
2222
'aria-haspopup': true,
2323
color: 'secondary',
24-
tag: Button
2524
};
2625

2726
const contextTypes = {
@@ -42,7 +41,7 @@ class DropdownToggle extends React.Component {
4241
return;
4342
}
4443

45-
if (this.props.nav) {
44+
if (this.props.nav && !this.props.tag) {
4645
e.preventDefault();
4746
}
4847

@@ -54,7 +53,7 @@ class DropdownToggle extends React.Component {
5453
}
5554

5655
render() {
57-
const { className, cssModule, caret, split, nav, tag: Tag, ...props } = this.props;
56+
const { className, cssModule, caret, split, nav, tag, ...props } = this.props;
5857
const ariaLabel = props['aria-label'] || 'Toggle Dropdown';
5958
const classes = mapToCssModules(classNames(
6059
className,
@@ -67,9 +66,15 @@ class DropdownToggle extends React.Component {
6766
), cssModule);
6867
const children = props.children || <span className="sr-only">{ariaLabel}</span>;
6968

70-
if (nav) {
71-
props.tag = 'a';
69+
let Tag;
70+
71+
if (nav && !tag) {
72+
Tag = 'a';
7273
props.href = '#';
74+
} else if (!tag) {
75+
Tag = Button;
76+
} else {
77+
Tag = tag;
7378
}
7479

7580
return (

src/__tests__/DropdownToggle.spec.js

+14
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,20 @@ describe('DropdownToggle', () => {
170170
expect(wrapper.find('.nav-link').length).toBe(1);
171171
});
172172

173+
it('should not set the tag prop when the tag is defined', () => {
174+
const wrapper = mount(
175+
<DropdownToggle nav tag="span">Ello world</DropdownToggle>,
176+
{
177+
context: {
178+
isOpen: isOpen,
179+
toggle: toggle
180+
}
181+
}
182+
);
183+
184+
expect(wrapper.find('[aria-haspopup="true"]').prop('tag')).toBe(undefined);
185+
});
186+
173187
it('should preventDefault', () => {
174188
const e = { preventDefault: jasmine.createSpy('preventDefault') };
175189
const wrapper = mount(

0 commit comments

Comments
 (0)