Skip to content

Commit

Permalink
fix(DropdownToggle): support non Button styles (#221)
Browse files Browse the repository at this point in the history
* fix(DropdownToggle): always use Button; passing tag if provided

* fix(DropdownToggle): support non Button styles
  • Loading branch information
TheSharpieOne authored and eddywashere committed Nov 13, 2016
1 parent ca9e28e commit cd3c1ce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/DropdownToggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const defaultProps = {
'data-toggle': 'dropdown',
'aria-haspopup': true,
color: 'secondary',
tag: Button
};

const contextTypes = {
Expand All @@ -42,7 +41,7 @@ class DropdownToggle extends React.Component {
return;
}

if (this.props.nav) {
if (this.props.nav && !this.props.tag) {
e.preventDefault();
}

Expand All @@ -54,7 +53,7 @@ class DropdownToggle extends React.Component {
}

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

if (nav) {
props.tag = 'a';
let Tag;

if (nav && !tag) {
Tag = 'a';
props.href = '#';
} else if (!tag) {
Tag = Button;
} else {
Tag = tag;
}

return (
Expand Down
14 changes: 14 additions & 0 deletions src/__tests__/DropdownToggle.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,20 @@ describe('DropdownToggle', () => {
expect(wrapper.find('.nav-link').length).toBe(1);
});

it('should not set the tag prop when the tag is defined', () => {
const wrapper = mount(
<DropdownToggle nav tag="span">Ello world</DropdownToggle>,
{
context: {
isOpen: isOpen,
toggle: toggle
}
}
);

expect(wrapper.find('[aria-haspopup="true"]').prop('tag')).toBe(undefined);
});

it('should preventDefault', () => {
const e = { preventDefault: jasmine.createSpy('preventDefault') };
const wrapper = mount(
Expand Down

0 comments on commit cd3c1ce

Please sign in to comment.