@king-design/react 2.1.0 → 2.1.1

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.
@@ -3,6 +3,7 @@ import { Options, Feedback } from '../position';
3
3
  import { Portal, PortalProps } from '../portal';
4
4
  import { FeedbackCallback } from './usePosition';
5
5
  import type { Events } from '../types';
6
+ import { Virtual } from '../virtual';
6
7
  export declare type Position = Options;
7
8
  export declare type PositionShorthand = 'left' | 'bottom' | 'right' | 'top';
8
9
  export declare const DROPDOWN = "Dropdown";
@@ -12,6 +13,7 @@ export interface DropdownProps {
12
13
  disabled?: boolean;
13
14
  value?: boolean;
14
15
  position?: Position | 'left' | 'bottom' | 'right' | 'top';
16
+ collison?: Position['collision'];
15
17
  of?: 'self' | 'parent' | Event;
16
18
  container?: PortalProps['container'];
17
19
  }
@@ -21,6 +23,8 @@ export interface DropdownEvents {
21
23
  hide: [];
22
24
  mouseenter: [MouseEvent];
23
25
  mouseleave: [MouseEvent];
26
+ click: [MouseEvent];
27
+ contextmenu: [MouseEvent];
24
28
  positioned: [Feedback];
25
29
  }
26
30
  export interface DropdownBlocks {
@@ -30,7 +34,7 @@ export declare class Dropdown<T extends DropdownProps = DropdownProps, E extends
30
34
  static typeDefs: Required<TypeDefs<DropdownProps>>;
31
35
  static defaults: () => Partial<DropdownProps>;
32
36
  static events: Events<DropdownEvents>;
33
- static template: (this: Dropdown) => (VNode<import("intact").VNodeTag> | VNode<typeof Portal>)[];
37
+ static template: (this: Dropdown) => (VNode<typeof Virtual> | VNode<typeof Portal>)[];
34
38
  menuVNode: VNode | null;
35
39
  dropdown: Dropdown | null;
36
40
  rootDropdown: Dropdown | null;
@@ -41,8 +45,7 @@ export declare class Dropdown<T extends DropdownProps = DropdownProps, E extends
41
45
  value: boolean;
42
46
  };
43
47
  };
44
- private timer;
45
- private triggerProps;
48
+ protected timer: number | undefined;
46
49
  init(): void;
47
50
  show(shouldFocus?: boolean): void;
48
51
  hide(immediately?: boolean): void;
@@ -52,6 +55,4 @@ export declare class Dropdown<T extends DropdownProps = DropdownProps, E extends
52
55
  private onContextMenu;
53
56
  private onLeave;
54
57
  private initEventCallbacks;
55
- private callOriginalCallback;
56
- private normalizeTriggerProps;
57
58
  }
@@ -3,14 +3,15 @@ import _inheritsLoose from "@babel/runtime-corejs3/helpers/inheritsLoose";
3
3
  import _concatInstanceProperty from "@babel/runtime-corejs3/core-js/instance/concat";
4
4
  import _filterInstanceProperty from "@babel/runtime-corejs3/core-js/instance/filter";
5
5
  import { __decorate } from "tslib";
6
- import { Component, createVNode as h, directClone, provide, inject, findDomFromVNode, createVNode, nextTick } from 'intact-react';
7
- import { bind, isTextChildren } from '../utils';
8
- import { EMPTY_OBJ, isFunction, noop } from 'intact-shared';
6
+ import { Component, createVNode as h, provide, inject, findDomFromVNode, nextTick } from 'intact-react';
7
+ import { bind, getRestProps } from '../utils';
8
+ import { noop } from 'intact-shared';
9
9
  import { cx } from '@emotion/css';
10
10
  import { useDocumentClick, containsOrEqual } from '../../hooks/useDocumentClick';
11
11
  import { Portal } from '../portal';
12
12
  import { useShowHideEvents } from '../../hooks/useShowHideEvents';
13
13
  import { usePosition } from './usePosition';
14
+ import { Virtual } from '../virtual';
14
15
  export var DROPDOWN = 'Dropdown';
15
16
  export var ROOT_DROPDOWN = 'RootDropdown';
16
17
  var typeDefs = {
@@ -20,7 +21,8 @@ var typeDefs = {
20
21
  position: [Object, 'left', 'bottom', 'right', 'top'],
21
22
  // Event is undefined in NodeJs
22
23
  of: ['self', 'parent', typeof Event === 'undefined' ? undefined : Event],
23
- container: [String, Function]
24
+ container: [String, Function],
25
+ collison: ['none', 'fit', 'flip', 'flipfit', Array]
24
26
  };
25
27
 
26
28
  var defaults = function defaults() {
@@ -36,6 +38,8 @@ var events = {
36
38
  hide: true,
37
39
  mouseenter: true,
38
40
  mouseleave: true,
41
+ click: true,
42
+ contextmenu: true,
39
43
  positioned: true
40
44
  };
41
45
  export var Dropdown = /*#__PURE__*/function (_Component) {
@@ -57,7 +61,6 @@ export var Dropdown = /*#__PURE__*/function (_Component) {
57
61
  _this.showedDropdown = null;
58
62
  _this.positionHook = usePosition();
59
63
  _this.timer = undefined;
60
- _this.triggerProps = null;
61
64
  return _this;
62
65
  }
63
66
 
@@ -95,7 +98,13 @@ export var Dropdown = /*#__PURE__*/function (_Component) {
95
98
 
96
99
  if (this.get('disabled')) return;
97
100
  clearTimeout(this.timer);
98
- this.set('value', true);
101
+ this.set('value', true); // should show parent dropdown
102
+
103
+ var parentDropdown = this.dropdown;
104
+
105
+ if (parentDropdown) {
106
+ parentDropdown.show();
107
+ }
99
108
 
100
109
  if (shouldFocus) {
101
110
  nextTick(function () {
@@ -113,10 +122,16 @@ export var Dropdown = /*#__PURE__*/function (_Component) {
113
122
 
114
123
  if (this.get('disabled')) return;
115
124
  if (!this.get('value')) return;
125
+ var showedDropdown = this.showedDropdown;
126
+
127
+ if (showedDropdown) {
128
+ showedDropdown.hide(immediately);
129
+ }
116
130
 
117
131
  if (immediately) {
118
132
  this.set('value', false);
119
133
  } else {
134
+ clearTimeout(this.timer);
120
135
  this.timer = window.setTimeout(function () {
121
136
  _this4.set('value', false);
122
137
  }, 200);
@@ -136,23 +151,24 @@ export var Dropdown = /*#__PURE__*/function (_Component) {
136
151
  };
137
152
 
138
153
  _proto.onEnter = function onEnter(e) {
139
- this.callOriginalCallback(e.type === 'click' ? 'ev-click' : 'ev-mouseenter', e);
140
154
  this.show();
155
+ this.trigger(e.type, e);
141
156
  };
142
157
 
143
158
  _proto.onContextMenu = function onContextMenu(e) {
144
- this.callOriginalCallback('ev-contextmenu', e);
145
159
  e.preventDefault();
146
160
  this.set('of', e);
147
161
  this.show();
162
+ this.trigger('contextmenu', e);
148
163
  };
149
164
 
150
165
  _proto.onLeave = function onLeave(e) {
151
- this.callOriginalCallback('ev-mouseleave', e);
152
166
  this.hide();
167
+ this.trigger(e.type, e);
153
168
  };
154
169
 
155
- _proto.initEventCallbacks = function initEventCallbacks(trigger) {
170
+ _proto.initEventCallbacks = function initEventCallbacks() {
171
+ var trigger = this.get('trigger');
156
172
  var props = {};
157
173
 
158
174
  switch (trigger) {
@@ -179,51 +195,6 @@ export var Dropdown = /*#__PURE__*/function (_Component) {
179
195
  return props;
180
196
  };
181
197
 
182
- _proto.callOriginalCallback = function callOriginalCallback(name, e) {
183
- var callback = this.triggerProps[name];
184
- var callbackOnDropdown = this.get(name);
185
- if (isFunction(callback)) callback(e);
186
- if (isFunction(callbackOnDropdown)) callbackOnDropdown(e);
187
- };
188
-
189
- _proto.normalizeTriggerProps = function normalizeTriggerProps(props) {
190
- // if use kpc in react or vue, normalize props by Wrapper.props.vnode;
191
- var vnode = props.vnode;
192
- if (!vnode) return props; // maybe we render the intact component in react slot property, in this case
193
- // the $isReact is false. so use the vnode $$typeof field as gauge
194
-
195
- if (vnode.$$typeof || this.$isVueNext) {
196
- var _props = vnode.props;
197
- if (!_props) return props;
198
- return {
199
- vnode: vnode,
200
- 'ev-click': _props.onClick,
201
- 'ev-mouseenter': _props.onMouseEnter,
202
- 'ev-mouseleave': _props.onMouseLeave,
203
- 'ev-contextmenu': _props.onContextMenu,
204
- className: _props.className || _props.class
205
- /* vue-next */
206
-
207
- };
208
- } else if (this.$isVue) {
209
- var data = vnode.data;
210
- var on = data && data.on || EMPTY_OBJ;
211
- var ret = {
212
- vnode: vnode
213
- };
214
- ['click', 'mouseenter', 'mouseleave', 'contextmenu'].forEach(function (event) {
215
- var method = on[event];
216
-
217
- if (method) {
218
- ret["ev-" + event] = method;
219
- }
220
- });
221
- return ret;
222
- }
223
-
224
- return props;
225
- };
226
-
227
198
  return Dropdown;
228
199
  }(Component);
229
200
  Dropdown.$doubleVNodes = true;
@@ -253,21 +224,22 @@ Dropdown.template = function () {
253
224
  var _children = children,
254
225
  trigger = _children[0],
255
226
  menu = _children[1];
256
- var triggerType = this.get('trigger');
257
- var props = this.initEventCallbacks(triggerType);
258
- var clonedTrigger = isTextChildren(trigger) ? createVNode('span', null, trigger) : directClone(trigger);
259
- var triggerProps = this.triggerProps = this.normalizeTriggerProps(trigger.props || EMPTY_OBJ); // add a className for opening status
260
-
261
- var className = trigger.className || triggerProps.className;
262
- className = cx((_cx = {}, _cx[className] = className, _cx['k-dropdown-open'] = this.get('value'), _cx));
263
- clonedTrigger.props = _extends({}, triggerProps, props, {
264
- className: className
265
- });
266
- clonedTrigger.className = className;
227
+ var props = this.initEventCallbacks();
228
+
229
+ var _this$get = this.get(),
230
+ className = _this$get.className,
231
+ value = _this$get.value,
232
+ container = _this$get.container;
233
+
234
+ className = cx((_cx = {
235
+ 'k-dropdown-open': value
236
+ }, _cx[className] = !!className, _cx));
267
237
  this.menuVNode = menu;
268
- return [clonedTrigger, h(Portal, {
238
+ return [h(Virtual, _extends({}, props, getRestProps(this), {
239
+ className: className
240
+ }), trigger), h(Portal, {
269
241
  children: menu,
270
- container: this.get('container')
242
+ container: container
271
243
  })];
272
244
  };
273
245
 
@@ -8,6 +8,7 @@ import { Dropdown, DropdownMenu, DropdownItem } from '../dropdown';
8
8
  import BasicDemo from '~/components/dropdown/demos/basic';
9
9
  import NestedDemo from '~/components/dropdown/demos/nested';
10
10
  import ContextMenuDemo from '~/components/dropdown/demos/contextmenu';
11
+ import TooltipDemo from '~/components/dropdown/demos/tooltip';
11
12
  describe('Dropdown', function () {
12
13
  afterEach(function (done) {
13
14
  unmount();
@@ -113,42 +114,61 @@ describe('Dropdown', function () {
113
114
  }, _callee2);
114
115
  })));
115
116
  it('nested dropdown', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
116
- var _mount3, instance, element, dropdown, _dropdown$querySelect, hoverItem, clickItem, clickSubDropdown, hoverSubDropdown;
117
+ var _mount3, instance, element, dropdown, _dropdown$querySelect, hoverItem, clickItem, clickSubDropdown, hoverSubDropdown, _hoverSubDropdown$que, hoverItem1, hoverSubDropdown1, _hoverSubDropdown1$qu, hoverItem2, hoverSubDropdown2;
117
118
 
118
119
  return _regeneratorRuntime.wrap(function _callee3$(_context4) {
119
120
  while (1) {
120
121
  switch (_context4.prev = _context4.next) {
121
122
  case 0:
123
+ this.timeout(0);
122
124
  _mount3 = mount(NestedDemo), instance = _mount3[0], element = _mount3[1];
123
125
  element.firstElementChild.click();
124
- _context4.next = 4;
126
+ _context4.next = 5;
125
127
  return wait();
126
128
 
127
- case 4:
129
+ case 5:
128
130
  dropdown = getElement('.k-dropdown-menu');
129
131
  _dropdown$querySelect = dropdown.querySelectorAll(':scope > .k-dropdown-item'), hoverItem = _dropdown$querySelect[3], clickItem = _dropdown$querySelect[4];
130
132
  clickItem.click();
131
- _context4.next = 9;
133
+ _context4.next = 10;
132
134
  return wait(500);
133
135
 
134
- case 9:
136
+ case 10:
135
137
  clickSubDropdown = getElement('.k-dropdown-menu');
136
138
  expect(clickSubDropdown.innerHTML).to.matchSnapshot(); // should hide last sub-dropdown and show next
137
139
 
138
140
  dispatchEvent(hoverItem, 'mouseenter');
139
- _context4.next = 14;
141
+ _context4.next = 15;
140
142
  return wait(500);
141
143
 
142
- case 14:
144
+ case 15:
143
145
  hoverSubDropdown = getElement('.k-dropdown-menu');
144
146
  expect(hoverSubDropdown.innerHTML).to.matchSnapshot();
147
+ _hoverSubDropdown$que = hoverSubDropdown.querySelectorAll('.k-dropdown-item'), hoverItem1 = _hoverSubDropdown$que[0];
148
+ dispatchEvent(hoverItem, 'mouseleave');
149
+ dispatchEvent(hoverItem1, 'mouseenter');
150
+ _context4.next = 22;
151
+ return wait(500);
145
152
 
146
- case 16:
153
+ case 22:
154
+ hoverSubDropdown1 = getElement('.k-dropdown-menu');
155
+ expect(hoverSubDropdown1.textContent).to.eql('item 1item 2');
156
+ _hoverSubDropdown1$qu = hoverSubDropdown1.querySelectorAll('.k-dropdown-item'), hoverItem2 = _hoverSubDropdown1$qu[0];
157
+ dispatchEvent(hoverItem1, 'mouseleave');
158
+ dispatchEvent(hoverItem2, 'mouseenter');
159
+ _context4.next = 29;
160
+ return wait(1000);
161
+
162
+ case 29:
163
+ hoverSubDropdown2 = getElement('.k-dropdown-menu');
164
+ expect(hoverSubDropdown2 === hoverSubDropdown1).to.be.true;
165
+
166
+ case 31:
147
167
  case "end":
148
168
  return _context4.stop();
149
169
  }
150
170
  }
151
- }, _callee3);
171
+ }, _callee3, this);
152
172
  })));
153
173
  it('hide on click document', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
154
174
  var _mount4, instance, element;
@@ -483,7 +503,7 @@ describe('Dropdown', function () {
483
503
  }
484
504
  }, _callee9);
485
505
  })));
486
- it('trigger: focus', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
506
+ it('focus trigger type', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
487
507
  var Demo, _mount9, instance;
488
508
 
489
509
  return _regeneratorRuntime.wrap(function _callee10$(_context14) {
@@ -506,39 +526,98 @@ describe('Dropdown', function () {
506
526
  _this4.Dropdown = Dropdown;
507
527
  _this4.DropdownItem = DropdownItem;
508
528
  _this4.DropdownMenu = DropdownMenu;
529
+ _this4.onFocus = sinon.spy(function (e) {
530
+ return console.log(e);
531
+ });
509
532
  return _this4;
510
533
  }
511
534
 
512
535
  return Demo;
513
536
  }(Component);
514
537
 
515
- Demo.template = "\n const {Dropdown, DropdownMenu, DropdownItem} = this;\n <div>\n <Dropdown trigger=\"focus\">\n <input ref=\"trigger\" />\n <DropdownMenu>\n <DropdownItem>test1</DropdownItem>\n <DropdownItem>test2</DropdownItem>\n </DropdownMenu>\n </Dropdown>\n </div>\n ";
538
+ Demo.template = "\n const {Dropdown, DropdownMenu, DropdownItem} = this;\n <div>\n <Dropdown trigger=\"focus\">\n <input ref=\"trigger\" ev-focusin={this.onFocus} />\n <DropdownMenu>\n <DropdownItem>test1</DropdownItem>\n <DropdownItem>test2</DropdownItem>\n </DropdownMenu>\n </Dropdown>\n </div>\n ";
516
539
  _mount9 = mount(Demo), instance = _mount9[0];
517
540
  dispatchEvent(instance.refs.trigger, 'focusin');
518
541
  _context14.next = 6;
519
542
  return wait(500);
520
543
 
521
544
  case 6:
522
- expect(getElement('.k-dropdown-menu')).to.be.exist; // clicking anywhere should not hide menu
545
+ expect(getElement('.k-dropdown-menu')).to.be.exist;
546
+ expect(instance.onFocus.callCount).to.eql(1); // clicking anywhere should not hide menu
523
547
 
524
548
  dispatchEvent(document, 'click');
525
- _context14.next = 10;
549
+ _context14.next = 11;
526
550
  return wait(500);
527
551
 
528
- case 10:
552
+ case 11:
529
553
  expect(getElement('.k-dropdown-menu')).to.be.exist;
530
554
  dispatchEvent(instance.refs.trigger, 'focusout');
531
- _context14.next = 14;
555
+ _context14.next = 15;
532
556
  return wait(700);
533
557
 
534
- case 14:
558
+ case 15:
535
559
  expect(getElement('.k-dropdown-menu')).to.not.be.exist;
536
560
 
537
- case 15:
561
+ case 16:
538
562
  case "end":
539
563
  return _context14.stop();
540
564
  }
541
565
  }
542
566
  }, _callee10);
543
567
  })));
568
+ it('wrap by tooltip', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11() {
569
+ var _mount10, instance, element, dropdown, _dropdown$querySelect4, item1, item2, item3, item4;
570
+
571
+ return _regeneratorRuntime.wrap(function _callee11$(_context15) {
572
+ while (1) {
573
+ switch (_context15.prev = _context15.next) {
574
+ case 0:
575
+ _mount10 = mount(TooltipDemo), instance = _mount10[0], element = _mount10[1];
576
+ dispatchEvent(element.firstChild, 'mouseenter');
577
+ _context15.next = 4;
578
+ return wait();
579
+
580
+ case 4:
581
+ dropdown = getElement('.k-dropdown-menu');
582
+ _dropdown$querySelect4 = dropdown.querySelectorAll('.k-dropdown-item'), item1 = _dropdown$querySelect4[0], item2 = _dropdown$querySelect4[1], item3 = _dropdown$querySelect4[2], item4 = _dropdown$querySelect4[3];
583
+ dispatchEvent(item1, 'mouseenter');
584
+ _context15.next = 9;
585
+ return wait();
586
+
587
+ case 9:
588
+ expect(getElement('.k-tooltip-content').textContent).to.eql('item 1');
589
+ dispatchEvent(item1, 'mouseleave');
590
+ dispatchEvent(item3, 'mouseenter');
591
+ _context15.next = 14;
592
+ return wait();
593
+
594
+ case 14:
595
+ expect(getElement('.k-tooltip-content').textContent).to.eql('disabled');
596
+ dispatchEvent(item3, 'mouseleave');
597
+ dispatchEvent(item4, 'mouseenter');
598
+ _context15.next = 19;
599
+ return wait();
600
+
601
+ case 19:
602
+ expect(getElement('.k-tooltip-content').textContent).to.eql('This is a nested Dropdown.');
603
+ dispatchEvent(item4, 'click');
604
+ _context15.next = 23;
605
+ return wait();
606
+
607
+ case 23:
608
+ expect(getElement('.k-dropdown-menu').textContent).to.eql('item 1item 2');
609
+ dispatchEvent(item4, 'mouseleave');
610
+ _context15.next = 27;
611
+ return wait(800);
612
+
613
+ case 27:
614
+ expect(getElement('.k-dropdown-menu')).to.not.be.exist;
615
+
616
+ case 28:
617
+ case "end":
618
+ return _context15.stop();
619
+ }
620
+ }
621
+ }, _callee11);
622
+ })));
544
623
  });
@@ -21,6 +21,6 @@ export declare class DropdownItem extends Component<DropdownItemProps, DropdownI
21
21
  private dropdownMenu;
22
22
  init(): void;
23
23
  select(): void;
24
- hasSubMenu(): Dropdown<any, any, any> | undefined;
24
+ hasSubMenu(): undefined;
25
25
  private onClick;
26
26
  }
@@ -5,8 +5,9 @@ import { Component, inject } from 'intact-react';
5
5
  import template from './item.vdt';
6
6
  import { bind } from '../utils';
7
7
  import { useItemKeyboard } from './useKeyboard';
8
- import { Dropdown, DROPDOWN } from './dropdown';
8
+ import { DROPDOWN } from './dropdown';
9
9
  import { DROPDOWN_MENU } from './menu';
10
+ import { Dropdown as ExportDropdown, DropdownMenu as ExportDropdownMenu } from '.';
10
11
  var typeDefs = {
11
12
  disabled: Boolean,
12
13
  hideOnSelect: Boolean,
@@ -64,11 +65,22 @@ export var DropdownItem = /*#__PURE__*/function (_Component) {
64
65
  };
65
66
 
66
67
  _proto.hasSubMenu = function hasSubMenu() {
67
- // TODO: wrapped by Tooltip
68
+ // wrapped by Dropdown rather than DropdownMenu
68
69
  var parent = this.$senior;
69
70
 
70
- if (parent instanceof Dropdown) {
71
- return parent;
71
+ while (parent) {
72
+ // Tooltip extends Dropdown, it's also a instance of Dropdown
73
+ // so use constructor to detect
74
+ // if (parent instanceof DropdownMenu) {
75
+ if (parent.constructor === ExportDropdownMenu) {
76
+ return;
77
+ }
78
+
79
+ if (parent.constructor === ExportDropdown) {
80
+ return parent;
81
+ }
82
+
83
+ parent = parent.$senior;
72
84
  }
73
85
  };
74
86
 
@@ -17,7 +17,8 @@ export function usePosition() {
17
17
  ['of', 'position'].forEach(function (item) {
18
18
  instance.watch(item, function (newValue, oldValue) {
19
19
  // return if object is the same
20
- if (isObject(newValue) && isObject(oldValue) && _JSON$stringify(newValue) === _JSON$stringify(oldValue)) {
20
+ if (isObject(newValue) && isObject(oldValue) && // is not event object
21
+ !(newValue instanceof Event) && _JSON$stringify(newValue) === _JSON$stringify(oldValue)) {
21
22
  return;
22
23
  }
23
24
 
@@ -67,7 +68,8 @@ export function usePosition() {
67
68
 
68
69
  position(findDomFromVNode(instance.menuVNode, true), _extends({
69
70
  my: 'left top+8',
70
- at: 'left bottom'
71
+ at: 'left bottom',
72
+ collision: instance.get('collison')
71
73
  }, pos, {
72
74
  of: ofElement,
73
75
  using: function using(_feedback) {
@@ -4,6 +4,7 @@ import _concatInstanceProperty from "@babel/runtime-corejs3/core-js/instance/con
4
4
  import _includesInstanceProperty from "@babel/runtime-corejs3/core-js/instance/includes";
5
5
  import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
6
6
  import { Component } from 'intact-react';
7
+ import BasicDemo from '~/components/menu/demos/basic';
7
8
  import CollapseDemo from '~/components/menu/demos/collapse';
8
9
  import AccordionDemo from '~/components/menu/demos/accordion';
9
10
  import { mount, unmount, dispatchEvent, getElement, wait } from '../../test/utils';
@@ -19,24 +20,29 @@ describe('Menu', function () {
19
20
  while (1) {
20
21
  switch (_context.prev = _context.next) {
21
22
  case 0:
22
- _mount = mount(CollapseDemo), instance = _mount[0], element = _mount[1];
23
+ _mount = mount(BasicDemo), instance = _mount[0], element = _mount[1];
24
+ _context.next = 3;
25
+ return wait();
26
+
27
+ case 3:
28
+ // shrink
23
29
  title = element.querySelector('.k-expanded .k-menu-title');
24
30
  title.click();
25
- _context.next = 5;
31
+ _context.next = 7;
26
32
  return wait(500);
27
33
 
28
- case 5:
34
+ case 7:
29
35
  expect(element.outerHTML).to.matchSnapshot();
30
36
  expect(instance.get('expandedKeys')).to.eql([]);
31
37
  title.click();
32
- _context.next = 10;
38
+ _context.next = 12;
33
39
  return wait(500);
34
40
 
35
- case 10:
41
+ case 12:
36
42
  expect(element.outerHTML).to.matchSnapshot();
37
43
  expect(instance.get('expandedKeys')).to.eql(['3']);
38
44
 
39
- case 12:
45
+ case 14:
40
46
  case "end":
41
47
  return _context.stop();
42
48
  }
@@ -51,39 +57,44 @@ describe('Menu', function () {
51
57
  switch (_context2.prev = _context2.next) {
52
58
  case 0:
53
59
  _mount2 = mount(CollapseDemo), instance = _mount2[0], element = _mount2[1];
60
+ instance.set('collapse', false);
61
+ _context2.next = 4;
62
+ return wait();
63
+
64
+ case 4:
54
65
  expect(element.innerHTML).to.matchSnapshot();
55
66
  _element$querySelecto = element.querySelectorAll('.k-menu-title'), title = _element$querySelecto[0], disabledTitle = _element$querySelecto[1];
56
67
  title.click();
57
- _context2.next = 6;
68
+ _context2.next = 9;
58
69
  return wait();
59
70
 
60
- case 6:
71
+ case 9:
61
72
  expect(element.outerHTML).to.matchSnapshot();
62
73
  expect(instance.get('selectedKey')).to.eql('1');
63
74
  disabledTitle.click();
64
- _context2.next = 11;
75
+ _context2.next = 14;
65
76
  return wait();
66
77
 
67
- case 11:
78
+ case 14:
68
79
  expect(element.outerHTML).to.matchSnapshot();
69
80
  expect(instance.get('selectedKey')).to.eql('1');
70
81
  subTitle = element.querySelector('.k-expanded .k-menu .k-menu-title');
71
82
  subTitle.click();
72
- _context2.next = 17;
83
+ _context2.next = 20;
73
84
  return wait();
74
85
 
75
- case 17:
86
+ case 20:
76
87
  expect(element.outerHTML).to.matchSnapshot();
77
88
  expect(instance.get('selectedKey')).to.eql('3-1'); // clear
78
89
 
79
90
  instance.set('selectedKey', '');
80
- _context2.next = 22;
91
+ _context2.next = 25;
81
92
  return wait();
82
93
 
83
- case 22:
94
+ case 25:
84
95
  expect(element.querySelector('.k-highlighted')).to.be.null;
85
96
 
86
- case 23:
97
+ case 26:
87
98
  case "end":
88
99
  return _context2.stop();
89
100
  }
@@ -1,5 +1,6 @@
1
1
  import { Component, TypeDefs, Key } from 'intact-react';
2
2
  import { Menu } from './menu';
3
+ import { Events } from '../types';
3
4
  export interface MenuItemProps {
4
5
  key: Key;
5
6
  to?: string | object;
@@ -14,6 +15,7 @@ export declare const MENU_ITEM = "MenuItem";
14
15
  export declare class MenuItem extends Component<MenuItemProps, MenuItemEvents> {
15
16
  static template: string | import("intact").Template<any>;
16
17
  static typeDefs: Required<TypeDefs<MenuItemProps>>;
18
+ static events: Events<MenuItemEvents>;
17
19
  rootMenu: Menu<Key>;
18
20
  parentMenu: Menu<Key>;
19
21
  parentMenuItem: MenuItem | null;
@@ -19,6 +19,10 @@ var typeDefs = {
19
19
  dot: Boolean,
20
20
  disabled: Boolean
21
21
  };
22
+ var events = {
23
+ click: true,
24
+ select: true
25
+ };
22
26
  export var MENU_ITEM = 'MenuItem';
23
27
  export var MenuItem = /*#__PURE__*/function (_Component) {
24
28
  _inheritsLoose(MenuItem, _Component);
@@ -76,5 +80,6 @@ export var MenuItem = /*#__PURE__*/function (_Component) {
76
80
  }(Component);
77
81
  MenuItem.template = template;
78
82
  MenuItem.typeDefs = typeDefs;
83
+ MenuItem.events = events;
79
84
 
80
85
  __decorate([bind], MenuItem.prototype, "onClick", null);
@@ -105,7 +105,10 @@ export var Pagination = /*#__PURE__*/function (_Component) {
105
105
 
106
106
  if (page > totalPages) {
107
107
  page = totalPages;
108
- } else if (page < 1) {
108
+ } // perhaps totalPages is 0
109
+
110
+
111
+ if (page < 1) {
109
112
  page = 1;
110
113
  }
111
114