From ac57b5c83f0fa8593469aa16e0ee7bdcaf76e9a7 Mon Sep 17 00:00:00 2001 From: ej9x Date: Tue, 21 May 2019 18:35:02 +0300 Subject: [PATCH] feat(Dropdown): add disabled prop to the dropdown head --- src/components/Dropdown/DropdownHead.js | 8 +++++++- src/components/Dropdown/Dropdowon.test.js | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/components/Dropdown/DropdownHead.js b/src/components/Dropdown/DropdownHead.js index 3b041399..af17a1ff 100644 --- a/src/components/Dropdown/DropdownHead.js +++ b/src/components/Dropdown/DropdownHead.js @@ -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, } @@ -31,7 +33,11 @@ const DropdownHead = dropdownHeadEnhancer( class DropdownHead extends PureComponent { 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); diff --git a/src/components/Dropdown/Dropdowon.test.js b/src/components/Dropdown/Dropdowon.test.js index b1bd90e3..9e04af58 100644 --- a/src/components/Dropdown/Dropdowon.test.js +++ b/src/components/Dropdown/Dropdowon.test.js @@ -85,6 +85,22 @@ describe('', () => { }); + it('shouldn\'t open and close dropdwon when disabled=true', () => { + const wrapper = mount( + + Head + +
Body
+
+
, + ); + 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();