@king-design/react 2.1.0 → 2.1.2
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.
- package/__tests__/__snapshots__/React Demos.md +102 -10
- package/components/dropdown/dropdown.d.ts +6 -5
- package/components/dropdown/dropdown.js +42 -69
- package/components/dropdown/index.spec.js +96 -17
- package/components/dropdown/item.d.ts +1 -1
- package/components/dropdown/item.js +16 -4
- package/components/dropdown/usePosition.js +4 -2
- package/components/form/index.spec.js +49 -2
- package/components/menu/index.spec.js +26 -15
- package/components/menu/item.d.ts +2 -0
- package/components/menu/item.js +5 -0
- package/components/pagination/index.js +4 -1
- package/components/pagination/index.spec.js +49 -0
- package/components/tooltip/content.d.ts +1 -0
- package/components/tooltip/content.js +18 -1
- package/components/tooltip/content.vdt.js +3 -1
- package/components/tooltip/index.spec.js +165 -0
- package/components/tooltip/styles.d.ts +22 -0
- package/components/tooltip/styles.js +1 -1
- package/components/tooltip/tooltip.d.ts +1 -0
- package/components/tooltip/tooltip.js +16 -1
- package/components/virtual.d.ts +8 -0
- package/components/virtual.js +126 -0
- package/index.d.ts +2 -2
- package/index.js +2 -2
- package/package.json +2 -2
|
@@ -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<
|
|
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
|
-
|
|
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,
|
|
7
|
-
import { bind,
|
|
8
|
-
import {
|
|
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,13 +21,15 @@ 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() {
|
|
27
29
|
return {
|
|
28
30
|
trigger: 'hover',
|
|
29
|
-
of: 'self'
|
|
31
|
+
of: 'self',
|
|
32
|
+
value: false
|
|
30
33
|
};
|
|
31
34
|
};
|
|
32
35
|
|
|
@@ -36,6 +39,8 @@ var events = {
|
|
|
36
39
|
hide: true,
|
|
37
40
|
mouseenter: true,
|
|
38
41
|
mouseleave: true,
|
|
42
|
+
click: true,
|
|
43
|
+
contextmenu: true,
|
|
39
44
|
positioned: true
|
|
40
45
|
};
|
|
41
46
|
export var Dropdown = /*#__PURE__*/function (_Component) {
|
|
@@ -57,7 +62,6 @@ export var Dropdown = /*#__PURE__*/function (_Component) {
|
|
|
57
62
|
_this.showedDropdown = null;
|
|
58
63
|
_this.positionHook = usePosition();
|
|
59
64
|
_this.timer = undefined;
|
|
60
|
-
_this.triggerProps = null;
|
|
61
65
|
return _this;
|
|
62
66
|
}
|
|
63
67
|
|
|
@@ -95,7 +99,13 @@ export var Dropdown = /*#__PURE__*/function (_Component) {
|
|
|
95
99
|
|
|
96
100
|
if (this.get('disabled')) return;
|
|
97
101
|
clearTimeout(this.timer);
|
|
98
|
-
this.set('value', true);
|
|
102
|
+
this.set('value', true); // should show parent dropdown
|
|
103
|
+
|
|
104
|
+
var parentDropdown = this.dropdown;
|
|
105
|
+
|
|
106
|
+
if (parentDropdown) {
|
|
107
|
+
parentDropdown.show();
|
|
108
|
+
}
|
|
99
109
|
|
|
100
110
|
if (shouldFocus) {
|
|
101
111
|
nextTick(function () {
|
|
@@ -113,10 +123,16 @@ export var Dropdown = /*#__PURE__*/function (_Component) {
|
|
|
113
123
|
|
|
114
124
|
if (this.get('disabled')) return;
|
|
115
125
|
if (!this.get('value')) return;
|
|
126
|
+
var showedDropdown = this.showedDropdown;
|
|
127
|
+
|
|
128
|
+
if (showedDropdown) {
|
|
129
|
+
showedDropdown.hide(immediately);
|
|
130
|
+
}
|
|
116
131
|
|
|
117
132
|
if (immediately) {
|
|
118
133
|
this.set('value', false);
|
|
119
134
|
} else {
|
|
135
|
+
clearTimeout(this.timer);
|
|
120
136
|
this.timer = window.setTimeout(function () {
|
|
121
137
|
_this4.set('value', false);
|
|
122
138
|
}, 200);
|
|
@@ -136,23 +152,24 @@ export var Dropdown = /*#__PURE__*/function (_Component) {
|
|
|
136
152
|
};
|
|
137
153
|
|
|
138
154
|
_proto.onEnter = function onEnter(e) {
|
|
139
|
-
this.callOriginalCallback(e.type === 'click' ? 'ev-click' : 'ev-mouseenter', e);
|
|
140
155
|
this.show();
|
|
156
|
+
this.trigger(e.type, e);
|
|
141
157
|
};
|
|
142
158
|
|
|
143
159
|
_proto.onContextMenu = function onContextMenu(e) {
|
|
144
|
-
this.callOriginalCallback('ev-contextmenu', e);
|
|
145
160
|
e.preventDefault();
|
|
146
161
|
this.set('of', e);
|
|
147
162
|
this.show();
|
|
163
|
+
this.trigger('contextmenu', e);
|
|
148
164
|
};
|
|
149
165
|
|
|
150
166
|
_proto.onLeave = function onLeave(e) {
|
|
151
|
-
this.callOriginalCallback('ev-mouseleave', e);
|
|
152
167
|
this.hide();
|
|
168
|
+
this.trigger(e.type, e);
|
|
153
169
|
};
|
|
154
170
|
|
|
155
|
-
_proto.initEventCallbacks = function initEventCallbacks(
|
|
171
|
+
_proto.initEventCallbacks = function initEventCallbacks() {
|
|
172
|
+
var trigger = this.get('trigger');
|
|
156
173
|
var props = {};
|
|
157
174
|
|
|
158
175
|
switch (trigger) {
|
|
@@ -179,51 +196,6 @@ export var Dropdown = /*#__PURE__*/function (_Component) {
|
|
|
179
196
|
return props;
|
|
180
197
|
};
|
|
181
198
|
|
|
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
199
|
return Dropdown;
|
|
228
200
|
}(Component);
|
|
229
201
|
Dropdown.$doubleVNodes = true;
|
|
@@ -253,21 +225,22 @@ Dropdown.template = function () {
|
|
|
253
225
|
var _children = children,
|
|
254
226
|
trigger = _children[0],
|
|
255
227
|
menu = _children[1];
|
|
256
|
-
var
|
|
257
|
-
|
|
258
|
-
var
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
});
|
|
266
|
-
clonedTrigger.className = className;
|
|
228
|
+
var props = this.initEventCallbacks();
|
|
229
|
+
|
|
230
|
+
var _this$get = this.get(),
|
|
231
|
+
className = _this$get.className,
|
|
232
|
+
value = _this$get.value,
|
|
233
|
+
container = _this$get.container;
|
|
234
|
+
|
|
235
|
+
className = cx((_cx = {
|
|
236
|
+
'k-dropdown-open': value
|
|
237
|
+
}, _cx[className] = !!className, _cx));
|
|
267
238
|
this.menuVNode = menu;
|
|
268
|
-
return [
|
|
239
|
+
return [h(Virtual, _extends({}, props, getRestProps(this), {
|
|
240
|
+
className: className
|
|
241
|
+
}), trigger), h(Portal, {
|
|
269
242
|
children: menu,
|
|
270
|
-
container:
|
|
243
|
+
container: container
|
|
271
244
|
})];
|
|
272
245
|
};
|
|
273
246
|
|
|
@@ -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 =
|
|
126
|
+
_context4.next = 5;
|
|
125
127
|
return wait();
|
|
126
128
|
|
|
127
|
-
case
|
|
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 =
|
|
133
|
+
_context4.next = 10;
|
|
132
134
|
return wait(500);
|
|
133
135
|
|
|
134
|
-
case
|
|
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 =
|
|
141
|
+
_context4.next = 15;
|
|
140
142
|
return wait(500);
|
|
141
143
|
|
|
142
|
-
case
|
|
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
|
|
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
|
|
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;
|
|
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 =
|
|
549
|
+
_context14.next = 11;
|
|
526
550
|
return wait(500);
|
|
527
551
|
|
|
528
|
-
case
|
|
552
|
+
case 11:
|
|
529
553
|
expect(getElement('.k-dropdown-menu')).to.be.exist;
|
|
530
554
|
dispatchEvent(instance.refs.trigger, 'focusout');
|
|
531
|
-
_context14.next =
|
|
555
|
+
_context14.next = 15;
|
|
532
556
|
return wait(700);
|
|
533
557
|
|
|
534
|
-
case
|
|
558
|
+
case 15:
|
|
535
559
|
expect(getElement('.k-dropdown-menu')).to.not.be.exist;
|
|
536
560
|
|
|
537
|
-
case
|
|
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
|
});
|
|
@@ -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 {
|
|
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
|
-
//
|
|
68
|
+
// wrapped by Dropdown rather than DropdownMenu
|
|
68
69
|
var parent = this.$senior;
|
|
69
70
|
|
|
70
|
-
|
|
71
|
-
|
|
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) &&
|
|
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) {
|
|
@@ -8,10 +8,11 @@ import BasicDemo, { data as basicDemoData } from '~/components/form/demos/basic'
|
|
|
8
8
|
import CustomDemo from '~/components/form/demos/custom';
|
|
9
9
|
import VariableDemo from '~/components/form/demos/variable';
|
|
10
10
|
import RemoteDemo from '~/components/form/demos/remote';
|
|
11
|
-
import { mount, dispatchEvent, wait } from '../../test/utils';
|
|
11
|
+
import { mount, unmount, dispatchEvent, wait } from '../../test/utils';
|
|
12
12
|
import { Component } from 'intact-react';
|
|
13
13
|
import { Form, FormItem } from './';
|
|
14
14
|
import { Input } from '../input';
|
|
15
|
+
import { Select } from '../select';
|
|
15
16
|
|
|
16
17
|
RemoteDemo.prototype.validateUserName = function (value) {
|
|
17
18
|
// mock api
|
|
@@ -29,7 +30,9 @@ RemoteDemo.prototype.validateUserName = function (value) {
|
|
|
29
30
|
};
|
|
30
31
|
|
|
31
32
|
describe('Form', function () {
|
|
32
|
-
|
|
33
|
+
afterEach(function () {
|
|
34
|
+
return unmount();
|
|
35
|
+
});
|
|
33
36
|
it('validate', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
34
37
|
var _mount, instance, element, form, item, input;
|
|
35
38
|
|
|
@@ -1315,4 +1318,48 @@ describe('Form', function () {
|
|
|
1315
1318
|
}
|
|
1316
1319
|
}, _callee7);
|
|
1317
1320
|
})));
|
|
1321
|
+
it('should not validate when select is disabled on init', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
|
|
1322
|
+
var Demo, _mount8, instance, element;
|
|
1323
|
+
|
|
1324
|
+
return _regeneratorRuntime.wrap(function _callee8$(_context11) {
|
|
1325
|
+
while (1) {
|
|
1326
|
+
switch (_context11.prev = _context11.next) {
|
|
1327
|
+
case 0:
|
|
1328
|
+
Demo = /*#__PURE__*/function (_Component3) {
|
|
1329
|
+
_inheritsLoose(Demo, _Component3);
|
|
1330
|
+
|
|
1331
|
+
function Demo() {
|
|
1332
|
+
var _context10;
|
|
1333
|
+
|
|
1334
|
+
var _this3;
|
|
1335
|
+
|
|
1336
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
1337
|
+
args[_key3] = arguments[_key3];
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
_this3 = _Component3.call.apply(_Component3, _concatInstanceProperty(_context10 = [this]).call(_context10, args)) || this;
|
|
1341
|
+
_this3.Form = Form;
|
|
1342
|
+
_this3.FormItem = FormItem;
|
|
1343
|
+
_this3.Select = Select;
|
|
1344
|
+
return _this3;
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
return Demo;
|
|
1348
|
+
}(Component);
|
|
1349
|
+
|
|
1350
|
+
Demo.template = "\n const {Form, FormItem, Select} = this;\n <Form ref=\"form\">\n <FormItem rules={{required: true}}>\n <Select disabled />\n </FormItem>\n </Form>\n ";
|
|
1351
|
+
_mount8 = mount(Demo), instance = _mount8[0], element = _mount8[1];
|
|
1352
|
+
_context11.next = 5;
|
|
1353
|
+
return wait(500);
|
|
1354
|
+
|
|
1355
|
+
case 5:
|
|
1356
|
+
expect(element.querySelector('.k-form-error')).to.be.null;
|
|
1357
|
+
|
|
1358
|
+
case 6:
|
|
1359
|
+
case "end":
|
|
1360
|
+
return _context11.stop();
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
}, _callee8);
|
|
1364
|
+
})));
|
|
1318
1365
|
});
|