Skip to content

Commit

Permalink
feat(Dropdown): add disabled prop to the dropdown head
Browse files Browse the repository at this point in the history
  • Loading branch information
ej9x committed May 21, 2019
1 parent 255b86d commit ac57b5c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/components/Dropdown/DropdownHead.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type DropdownHeadProps = {
stopClickPropagation?: boolean,
/** onClick callback. When exists then disalbe auto toogle dropdown on click */
onClick?: (MouseEvent) => void,
/** Prevent toggle action */
disabled?: boolean,
}


Expand All @@ -31,7 +33,11 @@ const DropdownHead = dropdownHeadEnhancer(
class DropdownHead extends PureComponent<DropdownHeadPropsEnhanced> {

onClick = (event: MouseEvent) => {
const { dropdown: { toggleDropdown }, stopClickPropagation, onClick } = this.props;
const { dropdown: { toggleDropdown }, disabled, stopClickPropagation, onClick } = this.props;

if (!!disabled) {
return;
}

if (typeof onClick === 'function') {
onClick(event);
Expand Down
16 changes: 16 additions & 0 deletions src/components/Dropdown/Dropdowon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ describe('<Dropdown />', () => {
});


it('shouldn\'t open and close dropdwon when disabled=true', () => {
const wrapper = mount(
<Dropdown>
<Dropdown.Head disabled>Head</Dropdown.Head>
<Dropdown.Body>
<div className="body">Body</div>
</Dropdown.Body>
</Dropdown>,
);
expect(wrapper.find('.body')).toHaveLength(0);

wrapper.find(Dropdown.Head).simulate('click');
expect(wrapper.find('.body')).toHaveLength(0);
});


it('should render with function in body', () => {
const onCloseDropdown = jest.fn();

Expand Down

0 comments on commit ac57b5c

Please sign in to comment.