@imposium-hub/components 1.38.15 → 1.38.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,7 @@ interface IButtonMenuProps {
4
4
  button : any;
5
5
  items : any;
6
6
  position : string;
7
+ isOpen ? : boolean;
7
8
  }
8
9
 
9
10
  interface IButtonMenuState {
@@ -13,28 +14,33 @@ interface IButtonMenuState {
13
14
  class ButtonMenu extends React.PureComponent<IButtonMenuProps, IButtonMenuState> {
14
15
 
15
16
  private evtHandlers : any;
17
+ private toggleRef : any;
16
18
 
17
19
  constructor(props) {
18
20
 
19
21
  super(props);
20
-
21
22
  this.state = {
22
- open : false
23
+ open : this.props.isOpen || false
23
24
  };
24
25
 
25
26
  this.evtHandlers = {
26
27
  toggleMenu: (e) => this.toggleMenu(e),
27
28
  clickOutside: (e) => this.handleClickOutside(e)
28
29
  };
30
+
31
+ this.toggleRef = React.createRef();
29
32
  }
30
33
 
31
34
  private handleClickOutside(e) {
32
35
 
33
- document.removeEventListener('click', this.evtHandlers.clickOutside);
36
+ const clickOnToggle = (this.toggleRef && this.toggleRef.current && this.toggleRef.current.contains(e.target)) ? true : false;
34
37
 
35
- this.setState({
36
- open: false
37
- });
38
+ if (!clickOnToggle) {
39
+ document.removeEventListener('click', this.evtHandlers.clickOutside);
40
+ this.setState({
41
+ open: false
42
+ });
43
+ }
38
44
  }
39
45
 
40
46
  public componentWillUnmount() {
@@ -44,9 +50,6 @@ class ButtonMenu extends React.PureComponent<IButtonMenuProps, IButtonMenuState>
44
50
 
45
51
  public toggleMenu(e) {
46
52
 
47
- e.preventDefault();
48
- e.stopPropagation();
49
-
50
53
  const newState = !this.state.open;
51
54
 
52
55
  this.setState({
@@ -106,6 +109,7 @@ class ButtonMenu extends React.PureComponent<IButtonMenuProps, IButtonMenuState>
106
109
 
107
110
  // Clone the trigger button passed in and add an onClick listener
108
111
  const trigger = React.cloneElement(button, {
112
+ buttonRef: this.toggleRef,
109
113
  onClick: this.evtHandlers.toggleMenu,
110
114
  active: open
111
115
  });
@@ -71,7 +71,6 @@ export default class ImposiumDropdown extends React.PureComponent<IDropdownMenuP
71
71
  }
72
72
 
73
73
  private onEsc = (e : any) : void => {
74
- const {onOutsideClick} = this.props;
75
74
 
76
75
  if (e.keyCode === ImposiumDropdown.ESC_CODE) {
77
76
  this.cancelRender(true);
@@ -79,14 +78,13 @@ export default class ImposiumDropdown extends React.PureComponent<IDropdownMenuP
79
78
  }
80
79
 
81
80
  private detectOutsideClick = (e : any) : void => {
82
- const {toggleRef, onOutsideClick} = this.props;
81
+ const {toggleRef} = this.props;
83
82
  const {target} = e;
84
83
 
85
- if (
86
- this.dropdownRef.current &&
87
- !this.dropdownRef.current.contains(target) &&
88
- !toggleRef.current.contains(target)
89
- ) {
84
+ const clickInside = (this.dropdownRef.current && this.dropdownRef.current.contains(target)) ? true : false;
85
+ const clickOnToggle = (toggleRef && toggleRef.current && toggleRef.current.contains(target)) ? true : false;
86
+
87
+ if (!clickInside && !clickOnToggle) {
90
88
  this.cancelRender(true);
91
89
  }
92
90
  }