@king-design/react 3.0.0-beta.0 → 3.0.0-beta.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.
- package/__tests__/__snapshots__/Dialog.md +1 -1
- package/__tests__/__snapshots__/React Demos.md +461 -309
- package/__tests__/components/cascader.spec.tsx +53 -0
- package/__tests__/components/drawer.spec.tsx +67 -5
- package/components/button/index.d.ts +1 -1
- package/components/button/index.js +1 -1
- package/components/button/styles.js +1 -1
- package/components/cascader/index.d.ts +22 -11
- package/components/cascader/index.js +9 -12
- package/components/cascader/index.spec.js +81 -0
- package/components/cascader/index.vdt.js +10 -8
- package/components/cascader/styles.js +1 -1
- package/components/cascader/useFields.d.ts +2 -0
- package/components/cascader/useFields.js +18 -0
- package/components/cascader/useFilterable.d.ts +2 -1
- package/components/cascader/useFilterable.js +17 -6
- package/components/cascader/useLabel.d.ts +2 -1
- package/components/cascader/useLabel.js +4 -4
- package/components/cascader/useLoad.d.ts +2 -1
- package/components/cascader/useLoad.js +9 -7
- package/components/colorpicker/index.d.ts +2 -0
- package/components/colorpicker/index.js +7 -2
- package/components/colorpicker/index.vdt.js +3 -6
- package/components/copy/index.d.ts +17 -0
- package/components/copy/index.js +43 -0
- package/components/copy/index.spec.d.ts +1 -0
- package/components/copy/index.spec.js +52 -0
- package/components/copy/index.vdt.js +45 -0
- package/components/copy/styles.d.ts +2 -0
- package/components/copy/styles.js +14 -0
- package/components/copy/useCopy.d.ts +4 -0
- package/components/copy/useCopy.js +90 -0
- package/components/datepicker/index.spec.js +1 -1
- package/components/datepicker/index.vdt.js +1 -1
- package/components/datepicker/styles.js +1 -1
- package/components/diagram/shapes/callout.d.ts +1 -1
- package/components/diagram/shapes/circle.d.ts +1 -1
- package/components/diagram/shapes/document.d.ts +1 -1
- package/components/diagram/shapes/ellipse.d.ts +1 -1
- package/components/diagram/shapes/hexagon.d.ts +1 -1
- package/components/diagram/shapes/image.d.ts +1 -1
- package/components/diagram/shapes/parallelogram.d.ts +1 -1
- package/components/diagram/shapes/rectangle.d.ts +1 -1
- package/components/diagram/shapes/square.d.ts +1 -1
- package/components/diagram/shapes/text.d.ts +1 -1
- package/components/dialog/alert.vdt.js +6 -5
- package/components/dialog/index.spec.js +6 -6
- package/components/dropdown/dropdown.d.ts +6 -6
- package/components/dropdown/dropdown.js +58 -75
- package/components/dropdown/index.spec.js +96 -17
- package/components/dropdown/item.d.ts +1 -1
- package/components/dropdown/item.js +19 -7
- package/components/dropdown/menu.js +1 -1
- package/components/dropdown/usePosition.js +11 -2
- package/components/editable/index.d.ts +1 -0
- package/components/editable/index.js +20 -6
- package/components/editable/index.vdt.js +2 -1
- package/components/form/index.spec.js +4 -2
- package/components/form/item.vdt.js +2 -1
- package/components/form/styles.js +4 -4
- package/components/grid/useGutter.js +8 -8
- package/components/input/index.d.ts +11 -2
- package/components/input/index.js +13 -13
- package/components/input/index.spec.js +169 -1
- package/components/input/index.vdt.js +28 -7
- package/components/input/styles.js +20 -3
- package/components/input/useAutoRows.d.ts +2 -0
- package/components/input/useAutoRows.js +79 -0
- package/components/input/useAutoWidth.js +13 -3
- package/components/input/useShowPassword.d.ts +7 -0
- package/components/input/useShowPassword.js +31 -0
- 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.d.ts +1 -1
- package/components/pagination/index.js +3 -2
- package/components/pagination/index.spec.js +49 -0
- package/components/pagination/index.vdt.js +8 -10
- package/components/pagination/styles.js +1 -1
- package/components/popover/content.d.ts +19 -0
- package/components/popover/content.js +31 -0
- package/components/popover/content.vdt.js +68 -0
- package/components/popover/index.d.ts +16 -0
- package/components/popover/index.js +44 -0
- package/components/popover/index.spec.d.ts +1 -0
- package/components/popover/index.spec.js +195 -0
- package/components/popover/styles.d.ts +1 -0
- package/components/popover/styles.js +22 -0
- package/components/portal.d.ts +6 -2
- package/components/portal.js +4 -3
- package/components/position.js +2 -1
- package/components/progress/index.js +1 -1
- package/components/progress/index.vdt.js +46 -8
- package/components/progress/styles.js +19 -13
- package/components/rate/styles.js +1 -1
- package/components/select/base.d.ts +7 -3
- package/components/select/base.js +9 -3
- package/components/select/base.vdt.js +46 -35
- package/components/select/index.spec.js +2 -2
- package/components/select/menu.vdt.js +1 -1
- package/components/select/styles.js +11 -5
- package/components/select/useDraggble.d.ts +2 -0
- package/components/select/useDraggble.js +11 -0
- package/components/select/useNowrap.d.ts +3 -0
- package/components/select/useNowrap.js +19 -0
- package/components/slider/index.spec.js +48 -9
- package/components/slider/index.vdt.js +23 -12
- package/components/slider/styles.js +23 -14
- package/components/slider/useValue.d.ts +3 -1
- package/components/slider/useValue.js +12 -0
- package/components/spinner/index.d.ts +0 -1
- package/components/spinner/index.js +1 -19
- package/components/spinner/index.vdt.js +9 -4
- package/components/spinner/useChange.d.ts +1 -1
- package/components/spinner/useChange.js +2 -2
- package/components/spinner/useValue.d.ts +1 -0
- package/components/spinner/useValue.js +16 -1
- package/components/split/index.vdt.js +32 -20
- package/components/split/memo.d.ts +9 -0
- package/components/split/memo.js +26 -0
- package/components/steps/index.d.ts +1 -0
- package/components/steps/index.js +2 -1
- package/components/steps/index.spec.js +1 -1
- package/components/steps/index.vdt.js +7 -4
- package/components/steps/step.vdt.js +0 -1
- package/components/steps/styles.d.ts +1 -0
- package/components/steps/styles.js +45 -16
- package/components/switch/index.spec.js +82 -65
- package/components/table/cell.js +1 -6
- package/components/table/index.spec.js +130 -19
- package/components/table/row.d.ts +1 -1
- package/components/table/row.js +2 -1
- package/components/table/styles.js +1 -1
- package/components/table/table.d.ts +15 -0
- package/components/table/table.js +16 -7
- package/components/table/table.vdt.js +20 -6
- package/components/table/useChecked.d.ts +3 -2
- package/components/table/useChecked.js +23 -12
- package/components/table/useDisableRow.d.ts +2 -1
- package/components/table/useDisableRow.js +4 -4
- package/components/table/useDraggable.d.ts +3 -2
- package/components/table/useDraggable.js +11 -15
- package/components/table/useGroup.js +3 -0
- package/components/table/useMerge.d.ts +2 -1
- package/components/table/useMerge.js +5 -4
- package/components/table/usePagination.d.ts +8 -0
- package/components/table/usePagination.js +81 -0
- package/components/table/useStickyScrollbar.js +2 -2
- package/components/table/useTree.d.ts +2 -1
- package/components/table/useTree.js +3 -4
- package/components/table/useWidth.js +2 -2
- package/components/tabs/index.d.ts +1 -1
- package/components/tabs/index.js +1 -1
- package/components/tabs/index.spec.js +67 -0
- package/components/tabs/index.vdt.js +4 -4
- package/components/tabs/styles.js +32 -34
- package/components/tabs/useScroll.d.ts +1 -1
- package/components/tabs/useScroll.js +75 -48
- package/components/tag/base.d.ts +1 -0
- package/components/tag/base.js +1 -1
- package/components/tag/index.d.ts +1 -0
- package/components/tag/index.js +2 -1
- package/components/tag/index.spec.js +147 -4
- package/components/tag/styles.d.ts +67 -0
- package/components/tag/styles.js +33 -8
- package/components/tag/tags.d.ts +27 -0
- package/components/tag/tags.js +51 -0
- package/components/tag/tags.vdt.js +79 -0
- package/components/tag/useChildren.d.ts +2 -0
- package/components/tag/useChildren.js +39 -0
- package/components/tag/useDraggable.d.ts +3 -0
- package/components/tag/useDraggable.js +89 -0
- package/components/tag/useNowrap.d.ts +7 -0
- package/components/tag/useNowrap.js +115 -0
- package/components/timepicker/index.spec.js +1 -1
- package/components/tooltip/content.d.ts +3 -2
- package/components/tooltip/content.js +18 -1
- package/components/tooltip/content.vdt.js +22 -10
- package/components/tooltip/index.spec.js +147 -92
- package/components/tooltip/styles.d.ts +23 -0
- package/components/tooltip/styles.js +2 -2
- package/components/tooltip/tooltip.d.ts +1 -1
- package/components/tooltip/tooltip.js +11 -11
- package/components/upload/index.spec.js +5 -6
- package/components/upload/index.vdt.js +3 -1
- package/components/utils.d.ts +2 -0
- package/components/utils.js +24 -3
- package/components/virtual.d.ts +8 -0
- package/components/virtual.js +126 -0
- package/hooks/useResizeObserver.d.ts +1 -1
- package/hooks/useResizeObserver.js +19 -6
- package/i18n/en-US.d.ts +4 -1
- package/i18n/en-US.js +6 -2
- package/index.d.ts +5 -3
- package/index.js +5 -3
- package/package.json +2 -2
- package/styles/fonts/iconfont.js +1 -1
- package/styles/fonts/ionicons.js +3 -3
- package/styles/global.js +1 -1
- package/yarn-error.log +41 -43
- package/components/table/useResizeObserver.d.ts +0 -2
- package/components/table/useResizeObserver.js +0 -20
|
@@ -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,13 @@ 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
|
-
position: {},
|
|
30
31
|
of: 'self'
|
|
31
32
|
};
|
|
32
33
|
};
|
|
@@ -37,6 +38,8 @@ var events = {
|
|
|
37
38
|
hide: true,
|
|
38
39
|
mouseenter: true,
|
|
39
40
|
mouseleave: true,
|
|
41
|
+
click: true,
|
|
42
|
+
contextmenu: true,
|
|
40
43
|
positioned: true
|
|
41
44
|
};
|
|
42
45
|
export var Dropdown = /*#__PURE__*/function (_Component) {
|
|
@@ -57,9 +60,7 @@ export var Dropdown = /*#__PURE__*/function (_Component) {
|
|
|
57
60
|
_this.rootDropdown = null;
|
|
58
61
|
_this.showedDropdown = null;
|
|
59
62
|
_this.positionHook = usePosition();
|
|
60
|
-
_this.alwaysPortal = false;
|
|
61
63
|
_this.timer = undefined;
|
|
62
|
-
_this.triggerProps = null;
|
|
63
64
|
return _this;
|
|
64
65
|
}
|
|
65
66
|
|
|
@@ -97,7 +98,13 @@ export var Dropdown = /*#__PURE__*/function (_Component) {
|
|
|
97
98
|
|
|
98
99
|
if (this.get('disabled')) return;
|
|
99
100
|
clearTimeout(this.timer);
|
|
100
|
-
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
|
+
}
|
|
101
108
|
|
|
102
109
|
if (shouldFocus) {
|
|
103
110
|
nextTick(function () {
|
|
@@ -115,10 +122,16 @@ export var Dropdown = /*#__PURE__*/function (_Component) {
|
|
|
115
122
|
|
|
116
123
|
if (this.get('disabled')) return;
|
|
117
124
|
if (!this.get('value')) return;
|
|
125
|
+
var showedDropdown = this.showedDropdown;
|
|
126
|
+
|
|
127
|
+
if (showedDropdown) {
|
|
128
|
+
showedDropdown.hide(immediately);
|
|
129
|
+
}
|
|
118
130
|
|
|
119
131
|
if (immediately) {
|
|
120
132
|
this.set('value', false);
|
|
121
133
|
} else {
|
|
134
|
+
clearTimeout(this.timer);
|
|
122
135
|
this.timer = window.setTimeout(function () {
|
|
123
136
|
_this4.set('value', false);
|
|
124
137
|
}, 200);
|
|
@@ -138,23 +151,24 @@ export var Dropdown = /*#__PURE__*/function (_Component) {
|
|
|
138
151
|
};
|
|
139
152
|
|
|
140
153
|
_proto.onEnter = function onEnter(e) {
|
|
141
|
-
this.callOriginalCallback(e.type === 'click' ? 'ev-click' : 'ev-mouseenter', e);
|
|
142
154
|
this.show();
|
|
155
|
+
this.trigger(e.type, e);
|
|
143
156
|
};
|
|
144
157
|
|
|
145
158
|
_proto.onContextMenu = function onContextMenu(e) {
|
|
146
|
-
this.callOriginalCallback('ev-contextmenu', e);
|
|
147
159
|
e.preventDefault();
|
|
148
160
|
this.set('of', e);
|
|
149
161
|
this.show();
|
|
162
|
+
this.trigger('contextmenu', e);
|
|
150
163
|
};
|
|
151
164
|
|
|
152
165
|
_proto.onLeave = function onLeave(e) {
|
|
153
|
-
this.callOriginalCallback('ev-mouseleave', e);
|
|
154
166
|
this.hide();
|
|
167
|
+
this.trigger(e.type, e);
|
|
155
168
|
};
|
|
156
169
|
|
|
157
|
-
_proto.initEventCallbacks = function initEventCallbacks(
|
|
170
|
+
_proto.initEventCallbacks = function initEventCallbacks() {
|
|
171
|
+
var trigger = this.get('trigger');
|
|
158
172
|
var props = {};
|
|
159
173
|
|
|
160
174
|
switch (trigger) {
|
|
@@ -181,51 +195,6 @@ export var Dropdown = /*#__PURE__*/function (_Component) {
|
|
|
181
195
|
return props;
|
|
182
196
|
};
|
|
183
197
|
|
|
184
|
-
_proto.callOriginalCallback = function callOriginalCallback(name, e) {
|
|
185
|
-
var callback = this.triggerProps[name];
|
|
186
|
-
var callbackOnDropdown = this.get(name);
|
|
187
|
-
if (isFunction(callback)) callback(e);
|
|
188
|
-
if (isFunction(callbackOnDropdown)) callbackOnDropdown(e);
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
_proto.normalizeTriggerProps = function normalizeTriggerProps(props) {
|
|
192
|
-
// if use kpc in react or vue, normalize props by Wrapper.props.vnode;
|
|
193
|
-
var vnode = props.vnode;
|
|
194
|
-
if (!vnode) return props; // maybe we render the intact component in react slot property, in this case
|
|
195
|
-
// the $isReact is false. so use the vnode $$typeof field as gauge
|
|
196
|
-
|
|
197
|
-
if (vnode.$$typeof || this.$isVueNext) {
|
|
198
|
-
var _props = vnode.props;
|
|
199
|
-
if (!_props) return props;
|
|
200
|
-
return {
|
|
201
|
-
vnode: vnode,
|
|
202
|
-
'ev-click': _props.onClick,
|
|
203
|
-
'ev-mouseenter': _props.onMouseEnter,
|
|
204
|
-
'ev-mouseleave': _props.onMouseLeave,
|
|
205
|
-
'ev-contextmenu': _props.onContextMenu,
|
|
206
|
-
className: _props.className || _props.class
|
|
207
|
-
/* vue-next */
|
|
208
|
-
|
|
209
|
-
};
|
|
210
|
-
} else if (this.$isVue) {
|
|
211
|
-
var data = vnode.data;
|
|
212
|
-
var on = data && data.on || EMPTY_OBJ;
|
|
213
|
-
var ret = {
|
|
214
|
-
vnode: vnode
|
|
215
|
-
};
|
|
216
|
-
['click', 'mouseenter', 'mouseleave', 'contextmenu'].forEach(function (event) {
|
|
217
|
-
var method = on[event];
|
|
218
|
-
|
|
219
|
-
if (method) {
|
|
220
|
-
ret["ev-" + event] = method;
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
return ret;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return props;
|
|
227
|
-
};
|
|
228
|
-
|
|
229
198
|
return Dropdown;
|
|
230
199
|
}(Component);
|
|
231
200
|
Dropdown.$doubleVNodes = true;
|
|
@@ -255,23 +224,23 @@ Dropdown.template = function () {
|
|
|
255
224
|
var _children = children,
|
|
256
225
|
trigger = _children[0],
|
|
257
226
|
menu = _children[1];
|
|
258
|
-
var
|
|
259
|
-
|
|
260
|
-
var
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
});
|
|
268
|
-
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));
|
|
269
237
|
this.menuVNode = menu;
|
|
270
|
-
return [
|
|
271
|
-
|
|
238
|
+
return [h(Virtual, _extends({}, props, getRestProps(this), {
|
|
239
|
+
className: className
|
|
240
|
+
}), trigger), h(Portal, {
|
|
272
241
|
children: menu,
|
|
273
|
-
container:
|
|
274
|
-
})
|
|
242
|
+
container: container
|
|
243
|
+
})];
|
|
275
244
|
};
|
|
276
245
|
|
|
277
246
|
__decorate([bind], Dropdown.prototype, "position", null);
|
|
@@ -288,9 +257,10 @@ function useDocumentClickForDropdown(dropdown) {
|
|
|
288
257
|
};
|
|
289
258
|
|
|
290
259
|
var _useDocumentClick = useDocumentClick(elementRef, function (e) {
|
|
291
|
-
// case 1: if click
|
|
292
|
-
// case 2: if right click on trigger and
|
|
293
|
-
// case 3: if click on trigger and
|
|
260
|
+
// case 1: if click a trigger and its trigger type is hover, ignore it
|
|
261
|
+
// case 2: if right click on a trigger and its trigger type is contextmenu, ignore it
|
|
262
|
+
// case 3: if click on a trigger and its trigger type is focus, do nothing
|
|
263
|
+
// case 3: if click on sub-dropdown, we should also show the parent dropdown, so ignore it
|
|
294
264
|
var trigger = dropdown.get('trigger');
|
|
295
265
|
if (trigger === 'focus') return;
|
|
296
266
|
var isHover = trigger === 'hover';
|
|
@@ -305,6 +275,7 @@ function useDocumentClickForDropdown(dropdown) {
|
|
|
305
275
|
}
|
|
306
276
|
}
|
|
307
277
|
|
|
278
|
+
if (isSubDropdownElement(e.target, dropdown)) return;
|
|
308
279
|
dropdown.hide(true);
|
|
309
280
|
}, true),
|
|
310
281
|
addDocumentClick = _useDocumentClick[0],
|
|
@@ -314,6 +285,18 @@ function useDocumentClickForDropdown(dropdown) {
|
|
|
314
285
|
dropdown.on('hide', removeDocumentClick);
|
|
315
286
|
}
|
|
316
287
|
|
|
288
|
+
function isSubDropdownElement(elem, dropdown) {
|
|
289
|
+
var showedDropdown = dropdown.showedDropdown;
|
|
290
|
+
if (!showedDropdown) return false;
|
|
291
|
+
var subMenuElement = findDomFromVNode(showedDropdown.menuVNode, true);
|
|
292
|
+
|
|
293
|
+
if (containsOrEqual(subMenuElement, elem)) {
|
|
294
|
+
return true;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return isSubDropdownElement(elem, showedDropdown);
|
|
298
|
+
}
|
|
299
|
+
|
|
317
300
|
function useHideLastMenuOnShow(dropdown) {
|
|
318
301
|
var parentDropdown = dropdown.dropdown;
|
|
319
302
|
dropdown.on('show', function () {
|
|
@@ -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,
|
|
@@ -49,7 +50,9 @@ export var DropdownItem = /*#__PURE__*/function (_Component) {
|
|
|
49
50
|
};
|
|
50
51
|
|
|
51
52
|
_proto.select = function select() {
|
|
52
|
-
if (this.parentDropdown) return;
|
|
53
|
+
if (this.parentDropdown) return; // trigger select event firstly for Cascader update values
|
|
54
|
+
|
|
55
|
+
this.trigger('select');
|
|
53
56
|
|
|
54
57
|
if (this.get('hideOnSelect')) {
|
|
55
58
|
// hide all dropdowns
|
|
@@ -59,16 +62,25 @@ export var DropdownItem = /*#__PURE__*/function (_Component) {
|
|
|
59
62
|
dropdown.hide(true);
|
|
60
63
|
} while (dropdown = dropdown.dropdown);
|
|
61
64
|
}
|
|
62
|
-
|
|
63
|
-
this.trigger('select');
|
|
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
|
|
|
@@ -85,7 +85,7 @@ function useKeyboardForDropdownMenu(dropdown) {
|
|
|
85
85
|
var focus = function focus() {
|
|
86
86
|
return focusByIndex(0);
|
|
87
87
|
}; // In Cascader the menu may have been replaced by another menu, in this case,
|
|
88
|
-
// if the dropdown has showed
|
|
88
|
+
// if the dropdown has showed while we mounted the menu, add keydown listener
|
|
89
89
|
|
|
90
90
|
|
|
91
91
|
if (dropdown.get('value')) {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import _extends from "@babel/runtime-corejs3/helpers/extends";
|
|
2
|
+
import _JSON$stringify from "@babel/runtime-corejs3/core-js/json/stringify";
|
|
2
3
|
import { useInstance, findDomFromVNode } from 'intact-react';
|
|
3
4
|
import { position } from '../position';
|
|
4
5
|
import { noop } from 'intact-shared';
|
|
6
|
+
import { isObject } from 'intact-shared';
|
|
5
7
|
export function usePosition() {
|
|
6
8
|
var instance = useInstance();
|
|
7
9
|
var positioned = {
|
|
@@ -13,7 +15,13 @@ export function usePosition() {
|
|
|
13
15
|
}
|
|
14
16
|
});
|
|
15
17
|
['of', 'position'].forEach(function (item) {
|
|
16
|
-
instance.watch(item, function () {
|
|
18
|
+
instance.watch(item, function (newValue, oldValue) {
|
|
19
|
+
// return if object is the same
|
|
20
|
+
if (isObject(newValue) && isObject(oldValue) && // is not event object
|
|
21
|
+
!(newValue instanceof Event) && _JSON$stringify(newValue) === _JSON$stringify(oldValue)) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
17
25
|
if (instance.get('value')) {
|
|
18
26
|
handle(noop);
|
|
19
27
|
}
|
|
@@ -60,7 +68,8 @@ export function usePosition() {
|
|
|
60
68
|
|
|
61
69
|
position(findDomFromVNode(instance.menuVNode, true), _extends({
|
|
62
70
|
my: 'left top+8',
|
|
63
|
-
at: 'left bottom'
|
|
71
|
+
at: 'left bottom',
|
|
72
|
+
collision: instance.get('collison')
|
|
64
73
|
}, pos, {
|
|
65
74
|
of: ofElement,
|
|
66
75
|
using: function using(_feedback) {
|
|
@@ -2,7 +2,7 @@ import _inheritsLoose from "@babel/runtime-corejs3/helpers/inheritsLoose";
|
|
|
2
2
|
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js/instance/concat";
|
|
3
3
|
import _trimInstanceProperty from "@babel/runtime-corejs3/core-js/instance/trim";
|
|
4
4
|
import { __decorate } from "tslib";
|
|
5
|
-
import { Component, createRef
|
|
5
|
+
import { Component, createRef } from 'intact-react';
|
|
6
6
|
import template from './index.vdt';
|
|
7
7
|
import { _$ } from '../../i18n';
|
|
8
8
|
import { bind } from '../utils';
|
|
@@ -49,12 +49,24 @@ export var Editable = /*#__PURE__*/function (_Component) {
|
|
|
49
49
|
var _proto = Editable.prototype;
|
|
50
50
|
|
|
51
51
|
_proto.edit = function edit() {
|
|
52
|
-
var _this2 = this;
|
|
53
|
-
|
|
54
52
|
this.set('editing', true);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Intact will update in nextTick, but Vue will call
|
|
55
|
+
* call updated method in nextTick of this nextTick
|
|
56
|
+
* so we should do it after two nextTicks
|
|
57
|
+
* https://github.com/ksc-fe/kpc/issues/847
|
|
58
|
+
*
|
|
59
|
+
* use binding this.select to Input $mounted event instead
|
|
60
|
+
*/
|
|
61
|
+
// nextTick(() => {
|
|
62
|
+
// nextTick(() => {
|
|
63
|
+
// this.inputRef.value!.select();
|
|
64
|
+
// });
|
|
65
|
+
// });
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
_proto.select = function select() {
|
|
69
|
+
this.inputRef.value.select();
|
|
58
70
|
};
|
|
59
71
|
|
|
60
72
|
_proto.onBlur = function onBlur(e) {
|
|
@@ -124,6 +136,8 @@ Editable.events = events;
|
|
|
124
136
|
|
|
125
137
|
__decorate([bind], Editable.prototype, "edit", null);
|
|
126
138
|
|
|
139
|
+
__decorate([bind], Editable.prototype, "select", null);
|
|
140
|
+
|
|
127
141
|
__decorate([bind], Editable.prototype, "onBlur", null);
|
|
128
142
|
|
|
129
143
|
__decorate([bind], Editable.prototype, "onKeydown", null);
|
|
@@ -40,7 +40,8 @@ export default function ($props, $blocks, $__proto__) {
|
|
|
40
40
|
'ev-blur': this.onBlur,
|
|
41
41
|
'ev-keydown': this.onKeydown,
|
|
42
42
|
'ref': this.inputRef,
|
|
43
|
-
'frozenOnInput': true
|
|
43
|
+
'frozenOnInput': true,
|
|
44
|
+
'ev-$mounted': this.select
|
|
44
45
|
}, null, this.inputRef), 0, 'c-ellipsis')]);
|
|
45
46
|
}
|
|
46
47
|
;
|
|
@@ -8,7 +8,7 @@ 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';
|
|
@@ -29,7 +29,9 @@ RemoteDemo.prototype.validateUserName = function (value) {
|
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
describe('Form', function () {
|
|
32
|
-
|
|
32
|
+
afterEach(function () {
|
|
33
|
+
return unmount();
|
|
34
|
+
});
|
|
33
35
|
it('validate', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
34
36
|
var _mount, instance, element, form, item, input;
|
|
35
37
|
|
|
@@ -8,7 +8,8 @@ import { makeItemStyles } from './styles';
|
|
|
8
8
|
import { context as ErrorContext } from './useError';
|
|
9
9
|
var _$tmp0 = {
|
|
10
10
|
'className': 'ion-ios-information-outline k-form-error-more',
|
|
11
|
-
'size': 'small'
|
|
11
|
+
'size': 'small',
|
|
12
|
+
'color': 'inherit'
|
|
12
13
|
};
|
|
13
14
|
export default function ($props, $blocks, $__proto__) {
|
|
14
15
|
var _classNameObj, _$cn2;
|