@king-design/intact 2.0.12 → 2.0.13-beta.0
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/components/drawer/index.spec.ts +20 -0
- package/components/dropdown/demos/trigger.md +13 -2
- package/components/dropdown/dropdown.ts +29 -13
- package/components/dropdown/index.md +1 -1
- package/components/dropdown/index.spec.ts +34 -0
- package/components/portal.ts +8 -2
- package/components/select/demos/format.md +3 -2
- package/components/select/styles.ts +10 -5
- package/components/timepicker/index.ts +1 -0
- package/components/tooltip/demos/trigger.md +5 -2
- package/components/tooltip/index.md +1 -1
- package/es/components/drawer/index.spec.js +48 -0
- package/es/components/dropdown/dropdown.d.ts +2 -1
- package/es/components/dropdown/dropdown.js +31 -14
- package/es/components/dropdown/index.spec.js +58 -0
- package/es/components/portal.js +9 -2
- package/es/components/select/styles.js +2 -2
- package/es/components/timepicker/index.d.ts +1 -0
- package/es/components/timepicker/index.js +1 -0
- package/es/hooks/useDocumentClick.js +29 -2
- package/es/index.d.ts +2 -2
- package/es/index.js +2 -2
- package/es/site/data/components/dropdown/demos/trigger/react.js +6 -2
- package/es/site/data/components/select/demos/format/react.js +1 -1
- package/es/site/data/components/tooltip/demos/trigger/react.js +7 -2
- package/hooks/useDocumentClick.ts +29 -1
- package/index.ts +2 -2
- package/package.json +1 -1
|
@@ -2,6 +2,9 @@ import BasicDemo from '~/components/drawer/demos/basic';
|
|
|
2
2
|
import PlacementDemo from '~/components/drawer/demos/placement';
|
|
3
3
|
import overlayDemo from '~/components/drawer/demos/overlay';
|
|
4
4
|
import {mount, unmount, dispatchEvent, getElement, wait} from '../../test/utils';
|
|
5
|
+
import {Component} from 'intact';
|
|
6
|
+
import {Drawer} from '.';
|
|
7
|
+
import {Dialog} from '../dialog';
|
|
5
8
|
|
|
6
9
|
describe('Drawer', () => {
|
|
7
10
|
afterEach((done) => {
|
|
@@ -67,4 +70,21 @@ describe('Drawer', () => {
|
|
|
67
70
|
await wait(500);
|
|
68
71
|
expect(getElement('.k-drawer')).to.be.undefined;
|
|
69
72
|
});
|
|
73
|
+
|
|
74
|
+
it('nested dialog', async () => {
|
|
75
|
+
class Demo extends Component {
|
|
76
|
+
static template = `
|
|
77
|
+
const {Dialog, Drawer} = this;
|
|
78
|
+
<Drawer value={true}>
|
|
79
|
+
<Dialog value={true} ref="dialog">Dialog</Dialog>
|
|
80
|
+
</Drawer>
|
|
81
|
+
`;
|
|
82
|
+
private Dialog = Dialog;
|
|
83
|
+
private Drawer = Drawer;
|
|
84
|
+
}
|
|
85
|
+
const [instance, element] = mount(Demo);
|
|
86
|
+
|
|
87
|
+
await wait();
|
|
88
|
+
expect(instance.refs.dialog.dialogRef.value.parentElement.parentElement).to.eql(document.body);
|
|
89
|
+
});
|
|
70
90
|
});
|
|
@@ -3,11 +3,13 @@ title: 触发方式
|
|
|
3
3
|
order: 0
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
`Dropdown`提供了两种触发方式来弹窗菜单,`hover`悬停触发(默认),`click
|
|
6
|
+
`Dropdown`提供了两种触发方式来弹窗菜单,`hover`悬停触发(默认),`click`点击触发,当使用`Input`组件时,还可以
|
|
7
|
+
指定为`foucs`来触发。
|
|
8
|
+
|
|
7
9
|
通过`trigger`属性来指定它们。
|
|
8
10
|
|
|
9
11
|
```vdt
|
|
10
|
-
import {Dropdown, DropdownMenu, DropdownItem, Button, Icon} from 'kpc';
|
|
12
|
+
import {Dropdown, DropdownMenu, DropdownItem, Button, Icon, Input} from 'kpc';
|
|
11
13
|
|
|
12
14
|
<div>
|
|
13
15
|
<Dropdown>
|
|
@@ -31,6 +33,15 @@ import {Dropdown, DropdownMenu, DropdownItem, Button, Icon} from 'kpc';
|
|
|
31
33
|
<DropdownItem>item 3</DropdownItem>
|
|
32
34
|
</DropdownMenu>
|
|
33
35
|
</Dropdown>
|
|
36
|
+
|
|
37
|
+
<Dropdown trigger="focus">
|
|
38
|
+
<Input placeholder="focus" />
|
|
39
|
+
<DropdownMenu>
|
|
40
|
+
<DropdownItem>item 1</DropdownItem>
|
|
41
|
+
<DropdownItem>item 2</DropdownItem>
|
|
42
|
+
<DropdownItem>item 3</DropdownItem>
|
|
43
|
+
</DropdownMenu>
|
|
44
|
+
</Dropdown>
|
|
34
45
|
</div>
|
|
35
46
|
```
|
|
36
47
|
|
|
@@ -31,7 +31,7 @@ export const DROPDOWN = 'Dropdown';
|
|
|
31
31
|
export const ROOT_DROPDOWN = 'RootDropdown';
|
|
32
32
|
|
|
33
33
|
export interface DropdownProps {
|
|
34
|
-
trigger?: 'hover' | 'click' | 'contextmenu'
|
|
34
|
+
trigger?: 'hover' | 'click' | 'contextmenu' | 'focus'
|
|
35
35
|
disabled?: boolean
|
|
36
36
|
value?: boolean
|
|
37
37
|
position?: Position | 'left' | 'bottom' | 'right' | 'top'
|
|
@@ -51,7 +51,7 @@ export interface DropdownEvents {
|
|
|
51
51
|
export interface DropdownBlocks { }
|
|
52
52
|
|
|
53
53
|
const typeDefs: Required<TypeDefs<DropdownProps>> = {
|
|
54
|
-
trigger: ['hover', 'click', 'contextmenu'],
|
|
54
|
+
trigger: ['hover', 'click', 'contextmenu', 'focus'],
|
|
55
55
|
disabled: Boolean,
|
|
56
56
|
value: Boolean,
|
|
57
57
|
position: [Object, 'left', 'bottom', 'right', 'top'],
|
|
@@ -106,17 +106,7 @@ export class Dropdown<
|
|
|
106
106
|
|
|
107
107
|
const [trigger, menu] = children as DropdownChildren;
|
|
108
108
|
const triggerType = this.get('trigger');
|
|
109
|
-
const props
|
|
110
|
-
|
|
111
|
-
if (triggerType !== 'contextmenu') {
|
|
112
|
-
props['ev-click'] = this.onEnter;
|
|
113
|
-
if (triggerType === 'hover') {
|
|
114
|
-
props['ev-mouseenter'] = this.onEnter;
|
|
115
|
-
props['ev-mouseleave'] = this.onLeave;
|
|
116
|
-
}
|
|
117
|
-
} else {
|
|
118
|
-
props['ev-contextmenu'] = this.onContextMenu;
|
|
119
|
-
}
|
|
109
|
+
const props = this.initEventCallbacks(triggerType);
|
|
120
110
|
|
|
121
111
|
const clonedTrigger = isTextChildren(trigger) ?
|
|
122
112
|
createVNode('span', null, trigger) :
|
|
@@ -235,6 +225,29 @@ export class Dropdown<
|
|
|
235
225
|
this.hide();
|
|
236
226
|
}
|
|
237
227
|
|
|
228
|
+
private initEventCallbacks(trigger: DropdownProps['trigger']) {
|
|
229
|
+
const props: Record<string, Function> = {};
|
|
230
|
+
|
|
231
|
+
switch (trigger) {
|
|
232
|
+
case 'focus':
|
|
233
|
+
props['ev-focusin'] = this.onEnter;
|
|
234
|
+
props['ev-focusout'] = this.onLeave;
|
|
235
|
+
break;
|
|
236
|
+
case 'contextmenu':
|
|
237
|
+
props['ev-contextmenu'] = this.onContextMenu;
|
|
238
|
+
break;
|
|
239
|
+
default:
|
|
240
|
+
props['ev-click'] = this.onEnter;
|
|
241
|
+
if (trigger === 'hover') {
|
|
242
|
+
props['ev-mouseenter'] = this.onEnter;
|
|
243
|
+
props['ev-mouseleave'] = this.onLeave;
|
|
244
|
+
}
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return props;
|
|
249
|
+
}
|
|
250
|
+
|
|
238
251
|
private callOriginalCallback(name: string, e: MouseEvent) {
|
|
239
252
|
const callback = this.triggerProps[name];
|
|
240
253
|
const callbackOnDropdown = this.get<Function>(name);
|
|
@@ -283,7 +296,10 @@ function useDocumentClickForDropdown(dropdown: Dropdown) {
|
|
|
283
296
|
const [addDocumentClick, removeDocumentClick] = useDocumentClick(elementRef, (e) => {
|
|
284
297
|
// case 1: if click an trigger and the trigger type is hover, ignore it
|
|
285
298
|
// case 2: if right click on trigger and the trigger type is contextmenu, ignore it
|
|
299
|
+
// case 3: if click on trigger and the trigger type is focus, do nothing
|
|
286
300
|
const trigger = dropdown.get('trigger');
|
|
301
|
+
if (trigger === 'focus') return;
|
|
302
|
+
|
|
287
303
|
const isHover = trigger === 'hover';
|
|
288
304
|
if (isHover || trigger === 'contextmenu') {
|
|
289
305
|
const triggerDom = findDomFromVNode(dropdown.$lastInput!, true) as Element;
|
|
@@ -11,7 +11,7 @@ sidebar: doc
|
|
|
11
11
|
|
|
12
12
|
| 属性 | 说明 | 类型 | 默认值 |
|
|
13
13
|
| --- | --- | --- | --- |
|
|
14
|
-
| trigger | 触发方式,`hover`为悬停触发,`click`为点击触发 | `"hover"` | `"click"` | `"hover"` |
|
|
14
|
+
| trigger | 触发方式,`hover`为悬停触发,`click`为点击触发 | `"hover"` | `"click"` | `"contextmenu"` | `"focus"` | `"hover"` |
|
|
15
15
|
| disabled | 是否禁用整个菜单 | `boolean` | `false` |
|
|
16
16
|
| value | 是否将弹出菜单展示出来,可通过`v-model`双向绑定 | `boolean` | `false` |
|
|
17
17
|
| position | 菜单弹出的位置,默认与触发器左侧对齐向下偏移`8px`的地方 | `Position` | `"left"` | `"bottom"` | `"right"` | `"top"` | `{my: 'left top+8', 'left bottom'}` |
|
|
@@ -280,4 +280,38 @@ describe('Dropdown', () => {
|
|
|
280
280
|
await wait();
|
|
281
281
|
expect(parent.scrollTop).to.eql(item.offsetHeight * 2 - 40);
|
|
282
282
|
});
|
|
283
|
+
|
|
284
|
+
it('trigger: focus', async() => {
|
|
285
|
+
class Demo extends Component {
|
|
286
|
+
static template = `
|
|
287
|
+
const {Dropdown, DropdownMenu, DropdownItem} = this;
|
|
288
|
+
<div>
|
|
289
|
+
<Dropdown trigger="focus">
|
|
290
|
+
<input ref="trigger" />
|
|
291
|
+
<DropdownMenu>
|
|
292
|
+
<DropdownItem>test1</DropdownItem>
|
|
293
|
+
<DropdownItem>test2</DropdownItem>
|
|
294
|
+
</DropdownMenu>
|
|
295
|
+
</Dropdown>
|
|
296
|
+
</div>
|
|
297
|
+
`;
|
|
298
|
+
private Dropdown = Dropdown;
|
|
299
|
+
private DropdownItem = DropdownItem;
|
|
300
|
+
private DropdownMenu = DropdownMenu;
|
|
301
|
+
}
|
|
302
|
+
const [instance] = mount(Demo);
|
|
303
|
+
|
|
304
|
+
dispatchEvent(instance.refs.trigger, 'focusin');
|
|
305
|
+
await wait(500);
|
|
306
|
+
expect(getElement('.k-dropdown-menu')).to.be.exist;
|
|
307
|
+
|
|
308
|
+
// clicking anywhere should not hide menu
|
|
309
|
+
dispatchEvent(document, 'click');
|
|
310
|
+
await wait(500);
|
|
311
|
+
expect(getElement('.k-dropdown-menu')).to.be.exist;
|
|
312
|
+
|
|
313
|
+
dispatchEvent(instance.refs.trigger, 'focusout');
|
|
314
|
+
await wait(700);
|
|
315
|
+
expect(getElement('.k-dropdown-menu')).to.not.be.exist;
|
|
316
|
+
});
|
|
283
317
|
});
|
package/components/portal.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
import {isString} from 'intact-shared';
|
|
15
15
|
import {DIALOG} from './dialog/constants';
|
|
16
16
|
import type {Dialog} from './dialog';
|
|
17
|
+
import {BaseDialog} from './dialog/base';
|
|
17
18
|
|
|
18
19
|
export interface PortalProps {
|
|
19
20
|
container?: Container
|
|
@@ -131,8 +132,13 @@ export class Portal<T extends PortalProps = PortalProps> extends Component<T> {
|
|
|
131
132
|
}
|
|
132
133
|
}
|
|
133
134
|
if (!this.container) {
|
|
134
|
-
|
|
135
|
-
|
|
135
|
+
if (this.$senior instanceof BaseDialog) {
|
|
136
|
+
// Dialog and Drawer must be inserted into document.body
|
|
137
|
+
this.container = document.body;
|
|
138
|
+
} else {
|
|
139
|
+
// find the closest dialog if exists
|
|
140
|
+
this.container = parentDom.closest('.k-dialog') || document.body;
|
|
141
|
+
}
|
|
136
142
|
|
|
137
143
|
/**
|
|
138
144
|
* @FIXME: We cannot get parent ref from sub component in Vue
|
|
@@ -34,7 +34,7 @@ import {Select, Option, Icon} from 'kpc';
|
|
|
34
34
|
</Option>
|
|
35
35
|
<b:value args="[value, label]">
|
|
36
36
|
<Icon class={value} style="vertical-align: middle;" />
|
|
37
|
-
<span class="
|
|
37
|
+
<span class="middle">{value}</span>
|
|
38
38
|
</b:value>
|
|
39
39
|
</Select>
|
|
40
40
|
</div>
|
|
@@ -67,8 +67,9 @@ import {Select, Option, Icon} from 'kpc';
|
|
|
67
67
|
height 60px
|
|
68
68
|
line-height 60px
|
|
69
69
|
text-align center
|
|
70
|
-
.
|
|
70
|
+
.middle
|
|
71
71
|
margin-left 6px
|
|
72
|
+
vertical-align middle
|
|
72
73
|
.label
|
|
73
74
|
display inline-block
|
|
74
75
|
width 100px
|
|
@@ -58,7 +58,7 @@ const defaults = deepDefaults(
|
|
|
58
58
|
},
|
|
59
59
|
tag: {
|
|
60
60
|
margin: `3px 8px 3px 0`,
|
|
61
|
-
padding: `
|
|
61
|
+
padding: `3px 8px`,
|
|
62
62
|
get borderRadius() { return theme.borderRadius },
|
|
63
63
|
get bgColor() { return theme.color.bg },
|
|
64
64
|
disabledBgColor: '#eee',
|
|
@@ -225,6 +225,7 @@ export default function makeStyles() {
|
|
|
225
225
|
.k-select-values {
|
|
226
226
|
display: inline-block;
|
|
227
227
|
margin-right: -${getRight(select.tag.margin)};
|
|
228
|
+
width: 100%;
|
|
228
229
|
&.k-with-values {
|
|
229
230
|
margin: 0;
|
|
230
231
|
}
|
|
@@ -236,16 +237,20 @@ export default function makeStyles() {
|
|
|
236
237
|
background: ${select.tag.bgColor};
|
|
237
238
|
border-radius: ${select.tag.borderRadius};
|
|
238
239
|
margin: ${select.tag.margin};
|
|
239
|
-
|
|
240
|
+
max-width: calc(100% - ${getRight(select.tag.margin)} - 1px);
|
|
241
|
+
}
|
|
242
|
+
.k-select-text {
|
|
243
|
+
max-width: calc(100% - 18px);
|
|
244
|
+
word-break: break-word;
|
|
240
245
|
}
|
|
241
246
|
.k-select-close {
|
|
242
247
|
margin-left: ${select.tag.delete.gap};
|
|
243
248
|
font-size: ${select.tag.delete.fontSize};
|
|
244
249
|
color: ${select.tag.delete.color};
|
|
245
250
|
}
|
|
246
|
-
.k-select-input {
|
|
247
|
-
margin-right: ${getRight(select.tag.margin)};
|
|
248
|
-
}
|
|
251
|
+
// .k-select-input {
|
|
252
|
+
// margin-right: ${getRight(select.tag.margin)};
|
|
253
|
+
// }
|
|
249
254
|
|
|
250
255
|
// size
|
|
251
256
|
${sizes.map(size => {
|
|
@@ -9,6 +9,7 @@ export class Timepicker<
|
|
|
9
9
|
Multipe extends boolean = false,
|
|
10
10
|
Range extends boolean = false,
|
|
11
11
|
> extends Component<TimepickerProps<Multipe, Range>, TimepickerEvents, TimepickerBlocks<Range>> {
|
|
12
|
+
static $doubleVNodes = true;
|
|
12
13
|
static template(this: Timepicker) {
|
|
13
14
|
const props = this.get();
|
|
14
15
|
if (props.step && !props.range) {
|
|
@@ -3,11 +3,11 @@ title: 触发方式
|
|
|
3
3
|
order: 2
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
使用`trigger`指定触发方式,`click`点击触发,`hover
|
|
6
|
+
使用`trigger`指定触发方式,`click`点击触发,`hover`悬浮触发,`foucs`聚焦触发,默认为`hover`,在悬浮触发情况下,
|
|
7
7
|
鼠标离开触发器,弹层就会消失,如果我们需要鼠标能离开触发器并悬浮在弹层上,需要添加`canHover`属性
|
|
8
8
|
|
|
9
9
|
```vdt
|
|
10
|
-
import {Tooltip, ButtonGroup, Button} from 'kpc';
|
|
10
|
+
import {Tooltip, ButtonGroup, Button, Input} from 'kpc';
|
|
11
11
|
|
|
12
12
|
<ButtonGroup>
|
|
13
13
|
<Tooltip content="hover">
|
|
@@ -19,5 +19,8 @@ import {Tooltip, ButtonGroup, Button} from 'kpc';
|
|
|
19
19
|
<Tooltip hoverable content="the text can be hovered">
|
|
20
20
|
<Button>hoverable</Button>
|
|
21
21
|
</Tooltip>
|
|
22
|
+
<Tooltip trigger="focus" content="foucs">
|
|
23
|
+
<Input placeholder="focus" />
|
|
24
|
+
</Tooltip>
|
|
22
25
|
</ButtonGroup>
|
|
23
26
|
```
|
|
@@ -9,7 +9,7 @@ sidebar: doc
|
|
|
9
9
|
|
|
10
10
|
| 属性 | 说明 | 类型 | 默认值 |
|
|
11
11
|
| --- | --- | --- | --- |
|
|
12
|
-
| trigger | 触发方式,`hover`为悬停触发,`click`为点击触发 | `"hover"` | `"click"` | `"hover"` |
|
|
12
|
+
| trigger | 触发方式,`hover`为悬停触发,`click`为点击触发 | `"hover"` | `"click"` | `"focus"` | `"hover"` |
|
|
13
13
|
| disabled | 是否禁用整个菜单 | `boolean` | `false` |
|
|
14
14
|
| value | 是否将弹出菜单展示出来,可通过`v-model`双向绑定 | `boolean` | `false` |
|
|
15
15
|
| position | 菜单弹出的位置,默认在触发器正上方向上偏移`10px`的地方 | `Position` | `"left"` | `"bottom"` | `"right"` | `"top"` | `{my: 'center bottom-10', at: 'center top', collision: 'flipfit'}` |
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime-corejs3/helpers/inheritsLoose";
|
|
1
2
|
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
|
|
3
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js/instance/concat";
|
|
2
4
|
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
|
|
3
5
|
import BasicDemo from '~/components/drawer/demos/basic';
|
|
4
6
|
import PlacementDemo from '~/components/drawer/demos/placement';
|
|
5
7
|
import overlayDemo from '~/components/drawer/demos/overlay';
|
|
6
8
|
import { mount, unmount, dispatchEvent, getElement, wait } from '../../test/utils';
|
|
9
|
+
import { Component } from 'intact';
|
|
10
|
+
import { Drawer } from '.';
|
|
11
|
+
import { Dialog } from '../dialog';
|
|
7
12
|
describe('Drawer', function () {
|
|
8
13
|
afterEach(function (done) {
|
|
9
14
|
unmount();
|
|
@@ -159,4 +164,47 @@ describe('Drawer', function () {
|
|
|
159
164
|
}
|
|
160
165
|
}, _callee4);
|
|
161
166
|
})));
|
|
167
|
+
it('nested dialog', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
|
|
168
|
+
var Demo, _mount4, instance, element;
|
|
169
|
+
|
|
170
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context6) {
|
|
171
|
+
while (1) {
|
|
172
|
+
switch (_context6.prev = _context6.next) {
|
|
173
|
+
case 0:
|
|
174
|
+
Demo = /*#__PURE__*/function (_Component) {
|
|
175
|
+
_inheritsLoose(Demo, _Component);
|
|
176
|
+
|
|
177
|
+
function Demo() {
|
|
178
|
+
var _context5;
|
|
179
|
+
|
|
180
|
+
var _this;
|
|
181
|
+
|
|
182
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
183
|
+
args[_key] = arguments[_key];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
_this = _Component.call.apply(_Component, _concatInstanceProperty(_context5 = [this]).call(_context5, args)) || this;
|
|
187
|
+
_this.Dialog = Dialog;
|
|
188
|
+
_this.Drawer = Drawer;
|
|
189
|
+
return _this;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return Demo;
|
|
193
|
+
}(Component);
|
|
194
|
+
|
|
195
|
+
Demo.template = "\n const {Dialog, Drawer} = this;\n <Drawer value={true}>\n <Dialog value={true} ref=\"dialog\">Dialog</Dialog>\n </Drawer>\n ";
|
|
196
|
+
_mount4 = mount(Demo), instance = _mount4[0], element = _mount4[1];
|
|
197
|
+
_context6.next = 5;
|
|
198
|
+
return wait();
|
|
199
|
+
|
|
200
|
+
case 5:
|
|
201
|
+
expect(instance.refs.dialog.dialogRef.value.parentElement.parentElement).to.eql(document.body);
|
|
202
|
+
|
|
203
|
+
case 6:
|
|
204
|
+
case "end":
|
|
205
|
+
return _context6.stop();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}, _callee5);
|
|
209
|
+
})));
|
|
162
210
|
});
|
|
@@ -8,7 +8,7 @@ export declare type PositionShorthand = 'left' | 'bottom' | 'right' | 'top';
|
|
|
8
8
|
export declare const DROPDOWN = "Dropdown";
|
|
9
9
|
export declare const ROOT_DROPDOWN = "RootDropdown";
|
|
10
10
|
export interface DropdownProps {
|
|
11
|
-
trigger?: 'hover' | 'click' | 'contextmenu';
|
|
11
|
+
trigger?: 'hover' | 'click' | 'contextmenu' | 'focus';
|
|
12
12
|
disabled?: boolean;
|
|
13
13
|
value?: boolean;
|
|
14
14
|
position?: Position | 'left' | 'bottom' | 'right' | 'top';
|
|
@@ -52,6 +52,7 @@ export declare class Dropdown<T extends DropdownProps = DropdownProps, E extends
|
|
|
52
52
|
private onEnter;
|
|
53
53
|
private onContextMenu;
|
|
54
54
|
private onLeave;
|
|
55
|
+
private initEventCallbacks;
|
|
55
56
|
private callOriginalCallback;
|
|
56
57
|
private normalizeTriggerProps;
|
|
57
58
|
}
|
|
@@ -14,7 +14,7 @@ import { usePosition } from './usePosition';
|
|
|
14
14
|
export var DROPDOWN = 'Dropdown';
|
|
15
15
|
export var ROOT_DROPDOWN = 'RootDropdown';
|
|
16
16
|
var typeDefs = {
|
|
17
|
-
trigger: ['hover', 'click', 'contextmenu'],
|
|
17
|
+
trigger: ['hover', 'click', 'contextmenu', 'focus'],
|
|
18
18
|
disabled: Boolean,
|
|
19
19
|
value: Boolean,
|
|
20
20
|
position: [Object, 'left', 'bottom', 'right', 'top'],
|
|
@@ -154,6 +154,33 @@ export var Dropdown = /*#__PURE__*/function (_Component) {
|
|
|
154
154
|
this.hide();
|
|
155
155
|
};
|
|
156
156
|
|
|
157
|
+
_proto.initEventCallbacks = function initEventCallbacks(trigger) {
|
|
158
|
+
var props = {};
|
|
159
|
+
|
|
160
|
+
switch (trigger) {
|
|
161
|
+
case 'focus':
|
|
162
|
+
props['ev-focusin'] = this.onEnter;
|
|
163
|
+
props['ev-focusout'] = this.onLeave;
|
|
164
|
+
break;
|
|
165
|
+
|
|
166
|
+
case 'contextmenu':
|
|
167
|
+
props['ev-contextmenu'] = this.onContextMenu;
|
|
168
|
+
break;
|
|
169
|
+
|
|
170
|
+
default:
|
|
171
|
+
props['ev-click'] = this.onEnter;
|
|
172
|
+
|
|
173
|
+
if (trigger === 'hover') {
|
|
174
|
+
props['ev-mouseenter'] = this.onEnter;
|
|
175
|
+
props['ev-mouseleave'] = this.onLeave;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return props;
|
|
182
|
+
};
|
|
183
|
+
|
|
157
184
|
_proto.callOriginalCallback = function callOriginalCallback(name, e) {
|
|
158
185
|
var callback = this.triggerProps[name];
|
|
159
186
|
var callbackOnDropdown = this.get(name);
|
|
@@ -229,19 +256,7 @@ Dropdown.template = function () {
|
|
|
229
256
|
trigger = _children[0],
|
|
230
257
|
menu = _children[1];
|
|
231
258
|
var triggerType = this.get('trigger');
|
|
232
|
-
var props =
|
|
233
|
-
|
|
234
|
-
if (triggerType !== 'contextmenu') {
|
|
235
|
-
props['ev-click'] = this.onEnter;
|
|
236
|
-
|
|
237
|
-
if (triggerType === 'hover') {
|
|
238
|
-
props['ev-mouseenter'] = this.onEnter;
|
|
239
|
-
props['ev-mouseleave'] = this.onLeave;
|
|
240
|
-
}
|
|
241
|
-
} else {
|
|
242
|
-
props['ev-contextmenu'] = this.onContextMenu;
|
|
243
|
-
}
|
|
244
|
-
|
|
259
|
+
var props = this.initEventCallbacks(triggerType);
|
|
245
260
|
var clonedTrigger = isTextChildren(trigger) ? createVNode('span', null, trigger) : directClone(trigger);
|
|
246
261
|
var triggerProps = this.triggerProps = this.normalizeTriggerProps(trigger.props || EMPTY_OBJ); // add a className for opening status
|
|
247
262
|
|
|
@@ -275,7 +290,9 @@ function useDocumentClickForDropdown(dropdown) {
|
|
|
275
290
|
var _useDocumentClick = useDocumentClick(elementRef, function (e) {
|
|
276
291
|
// case 1: if click an trigger and the trigger type is hover, ignore it
|
|
277
292
|
// case 2: if right click on trigger and the trigger type is contextmenu, ignore it
|
|
293
|
+
// case 3: if click on trigger and the trigger type is focus, do nothing
|
|
278
294
|
var trigger = dropdown.get('trigger');
|
|
295
|
+
if (trigger === 'focus') return;
|
|
279
296
|
var isHover = trigger === 'hover';
|
|
280
297
|
|
|
281
298
|
if (isHover || trigger === 'contextmenu') {
|
|
@@ -483,4 +483,62 @@ describe('Dropdown', function () {
|
|
|
483
483
|
}
|
|
484
484
|
}, _callee9);
|
|
485
485
|
})));
|
|
486
|
+
it('trigger: focus', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
|
|
487
|
+
var Demo, _mount9, instance;
|
|
488
|
+
|
|
489
|
+
return _regeneratorRuntime.wrap(function _callee10$(_context14) {
|
|
490
|
+
while (1) {
|
|
491
|
+
switch (_context14.prev = _context14.next) {
|
|
492
|
+
case 0:
|
|
493
|
+
Demo = /*#__PURE__*/function (_Component4) {
|
|
494
|
+
_inheritsLoose(Demo, _Component4);
|
|
495
|
+
|
|
496
|
+
function Demo() {
|
|
497
|
+
var _context13;
|
|
498
|
+
|
|
499
|
+
var _this4;
|
|
500
|
+
|
|
501
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
502
|
+
args[_key4] = arguments[_key4];
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
_this4 = _Component4.call.apply(_Component4, _concatInstanceProperty(_context13 = [this]).call(_context13, args)) || this;
|
|
506
|
+
_this4.Dropdown = Dropdown;
|
|
507
|
+
_this4.DropdownItem = DropdownItem;
|
|
508
|
+
_this4.DropdownMenu = DropdownMenu;
|
|
509
|
+
return _this4;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
return Demo;
|
|
513
|
+
}(Component);
|
|
514
|
+
|
|
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 ";
|
|
516
|
+
_mount9 = mount(Demo), instance = _mount9[0];
|
|
517
|
+
dispatchEvent(instance.refs.trigger, 'focusin');
|
|
518
|
+
_context14.next = 6;
|
|
519
|
+
return wait(500);
|
|
520
|
+
|
|
521
|
+
case 6:
|
|
522
|
+
expect(getElement('.k-dropdown-menu')).to.be.exist; // clicking anywhere should not hide menu
|
|
523
|
+
|
|
524
|
+
dispatchEvent(document, 'click');
|
|
525
|
+
_context14.next = 10;
|
|
526
|
+
return wait(500);
|
|
527
|
+
|
|
528
|
+
case 10:
|
|
529
|
+
expect(getElement('.k-dropdown-menu')).to.be.exist;
|
|
530
|
+
dispatchEvent(instance.refs.trigger, 'focusout');
|
|
531
|
+
_context14.next = 14;
|
|
532
|
+
return wait(700);
|
|
533
|
+
|
|
534
|
+
case 14:
|
|
535
|
+
expect(getElement('.k-dropdown-menu')).to.not.be.exist;
|
|
536
|
+
|
|
537
|
+
case 15:
|
|
538
|
+
case "end":
|
|
539
|
+
return _context14.stop();
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}, _callee10);
|
|
543
|
+
})));
|
|
486
544
|
});
|
package/es/components/portal.js
CHANGED
|
@@ -3,6 +3,7 @@ import _concatInstanceProperty from "@babel/runtime-corejs3/core-js/instance/con
|
|
|
3
3
|
import { Component, createCommentVNode, createTextVNode, mount, patch, remove, inject } from 'intact';
|
|
4
4
|
import { isString } from 'intact-shared';
|
|
5
5
|
import { DIALOG } from './dialog/constants';
|
|
6
|
+
import { BaseDialog } from './dialog/base';
|
|
6
7
|
var typeDefs = {
|
|
7
8
|
container: [String, Function]
|
|
8
9
|
};
|
|
@@ -96,8 +97,13 @@ export var Portal = /*#__PURE__*/function (_Component) {
|
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
if (!this.container) {
|
|
99
|
-
|
|
100
|
-
|
|
100
|
+
if (this.$senior instanceof BaseDialog) {
|
|
101
|
+
// Dialog and Drawer must be inserted into document.body
|
|
102
|
+
this.container = document.body;
|
|
103
|
+
} else {
|
|
104
|
+
// find the closest dialog if exists
|
|
105
|
+
this.container = parentDom.closest('.k-dialog') || document.body;
|
|
106
|
+
}
|
|
101
107
|
/**
|
|
102
108
|
* @FIXME: We cannot get parent ref from sub component in Vue
|
|
103
109
|
*/
|
|
@@ -108,6 +114,7 @@ export var Portal = /*#__PURE__*/function (_Component) {
|
|
|
108
114
|
// } else {
|
|
109
115
|
// this.container = document.body;
|
|
110
116
|
// }
|
|
117
|
+
|
|
111
118
|
}
|
|
112
119
|
};
|
|
113
120
|
|
|
@@ -94,7 +94,7 @@ var defaults = deepDefaults({
|
|
|
94
94
|
},
|
|
95
95
|
tag: {
|
|
96
96
|
margin: "3px 8px 3px 0",
|
|
97
|
-
padding: "
|
|
97
|
+
padding: "3px 8px",
|
|
98
98
|
|
|
99
99
|
get borderRadius() {
|
|
100
100
|
return theme.borderRadius;
|
|
@@ -188,7 +188,7 @@ setDefault(function () {
|
|
|
188
188
|
}).select;
|
|
189
189
|
});
|
|
190
190
|
export default function makeStyles() {
|
|
191
|
-
return /*#__PURE__*/css("display:inline-flex;align-items:center;vertical-align:middle;position:relative;width:", select.width, ";cursor:pointer;outline:none;border:", select.border, ";background:", select.bgColor, ";transition:border ", select.transition, ",background ", select.transition, ",box-shadow ", select.transition, ";border-radius:", select.borderRadius, ";.k-select-main{flex:1;min-width:0;}.k-select-prefix,.k-select-suffix{color:", select.iconColor, ";position:relative;}.k-select-suffix{margin-left:", select.suffixGap, ";}.k-select-placeholder{color:", select.placeholderColor, ";user-select:none;}&.k-fluid{width:100%;}.k-select-clear{opacity:0;transition:opacity ", select.transition, ",color ", select.transition, "!important;pointer-events:none;position:absolute;z-index:1;top:50%;left:50%;transform:translate(-50%, -50%);}&:hover{border:", select.hoverBorder, ";.k-select-clear.k-show{opacity:1;pointer-events:all;+.k-select-suffix-icon{opacity:0;}}}.k-select-suffix-icon{display:inline-block;transition:opacity ", select.transition, ";}.k-select-arrow{display:inline-block;transition:transform ", select.transition, ";&.k-disabled{color:", select.disabledArrowColor, ";}}&.k-dropdown-open{border:", select.focusBorder, ";.k-select-arrow{transform:rotateX(180deg);}}&:focus{outline:none;border:", select.focusBorder, ";}&.k-disabled{color:", select.disabled.color, ";cursor:not-allowed;background:", select.disabled.bgColor, ";border-color:", select.disabled.borderColor, ";.k-select-tag{background:", select.tag.disabledBgColor, ";}}.k-select-values{display:inline-block;margin-right:-", getRight(select.tag.margin), "
|
|
191
|
+
return /*#__PURE__*/css("display:inline-flex;align-items:center;vertical-align:middle;position:relative;width:", select.width, ";cursor:pointer;outline:none;border:", select.border, ";background:", select.bgColor, ";transition:border ", select.transition, ",background ", select.transition, ",box-shadow ", select.transition, ";border-radius:", select.borderRadius, ";.k-select-main{flex:1;min-width:0;}.k-select-prefix,.k-select-suffix{color:", select.iconColor, ";position:relative;}.k-select-suffix{margin-left:", select.suffixGap, ";}.k-select-placeholder{color:", select.placeholderColor, ";user-select:none;}&.k-fluid{width:100%;}.k-select-clear{opacity:0;transition:opacity ", select.transition, ",color ", select.transition, "!important;pointer-events:none;position:absolute;z-index:1;top:50%;left:50%;transform:translate(-50%, -50%);}&:hover{border:", select.hoverBorder, ";.k-select-clear.k-show{opacity:1;pointer-events:all;+.k-select-suffix-icon{opacity:0;}}}.k-select-suffix-icon{display:inline-block;transition:opacity ", select.transition, ";}.k-select-arrow{display:inline-block;transition:transform ", select.transition, ";&.k-disabled{color:", select.disabledArrowColor, ";}}&.k-dropdown-open{border:", select.focusBorder, ";.k-select-arrow{transform:rotateX(180deg);}}&:focus{outline:none;border:", select.focusBorder, ";}&.k-disabled{color:", select.disabled.color, ";cursor:not-allowed;background:", select.disabled.bgColor, ";border-color:", select.disabled.borderColor, ";.k-select-tag{background:", select.tag.disabledBgColor, ";}}.k-select-values{display:inline-block;margin-right:-", getRight(select.tag.margin), ";width:100%;&.k-with-values{margin:0;}}.k-select-tag{display:inline-flex;align-items:center;padding:", select.tag.padding, ";background:", select.tag.bgColor, ";border-radius:", select.tag.borderRadius, ";margin:", select.tag.margin, ";max-width:calc(100% - ", getRight(select.tag.margin), " - 1px);}.k-select-text{max-width:calc(100% - 18px);word-break:break-word;}.k-select-close{margin-left:", select.tag.delete.gap, ";font-size:", select.tag.delete.fontSize, ";color:", select.tag.delete.color, ";}", _mapInstanceProperty(sizes).call(sizes, function (size) {
|
|
192
192
|
var styles = select[size];
|
|
193
193
|
var className = /*#__PURE__*/css("font-size:", styles.fontSize, ";min-height:", styles.height, ";padding:", styles.padding, ";");
|
|
194
194
|
if (size === 'default') return className;
|
|
@@ -3,6 +3,7 @@ import { TimepickerProps, TimepickerEvents, TimepickerBlocks } from './constants
|
|
|
3
3
|
import { SelectPicker } from './selectPicker';
|
|
4
4
|
export type { TimepickerProps, TimepickerEvents, TimepickerBlocks };
|
|
5
5
|
export declare class Timepicker<Multipe extends boolean = false, Range extends boolean = false> extends Component<TimepickerProps<Multipe, Range>, TimepickerEvents, TimepickerBlocks<Range>> {
|
|
6
|
+
static $doubleVNodes: boolean;
|
|
6
7
|
static template(this: Timepicker): import("intact").VNode<typeof SelectPicker>;
|
|
7
8
|
static typeDefs: Required<import("intact").TypeDefs<TimepickerProps<boolean, boolean>>>;
|
|
8
9
|
}
|
|
@@ -1,12 +1,38 @@
|
|
|
1
1
|
import { onMounted, onUnmounted } from 'intact';
|
|
2
|
-
import { isFunction } from 'intact-shared';
|
|
2
|
+
import { isFunction } from 'intact-shared'; // @reference: Vue3.0
|
|
3
|
+
|
|
4
|
+
var getNow = Date.now; // Determine what event timestamp the browser is using. Annoyingly, the
|
|
5
|
+
// timestamp can either be hi-res (relative to page load) or low-res
|
|
6
|
+
// (relative to UNIX epoch), so in order to compare time we have to use the
|
|
7
|
+
// same timestamp type when saving the flush timestamp.
|
|
8
|
+
|
|
9
|
+
if (getNow() > document.createEvent('Event').timeStamp) {
|
|
10
|
+
// if the low-res timestamp which is bigger than the event timestamp
|
|
11
|
+
// (which is evaluated AFTER) it means the event is using a hi-res timestamp,
|
|
12
|
+
// and we need to use the hi-res version for event listeners as well.
|
|
13
|
+
getNow = function getNow() {
|
|
14
|
+
return performance.now();
|
|
15
|
+
};
|
|
16
|
+
} // #3485: Firefox <= 53 has incorrect Event.timeStamp implementation
|
|
17
|
+
// and does not fire microtasks in between event propagation, so safe to exclude.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
var ffMatch = navigator.userAgent.match(/firefox\/(\d+)/i);
|
|
21
|
+
var skipTimestampCheck = !!(ffMatch && Number(ffMatch[1]) <= 53);
|
|
3
22
|
export function useDocumentClick(ref, callback, manual) {
|
|
4
23
|
if (manual === void 0) {
|
|
5
24
|
manual = false;
|
|
6
25
|
}
|
|
7
26
|
|
|
8
27
|
var onDocumentClick = function onDocumentClick(e) {
|
|
9
|
-
if (e._ignore) return;
|
|
28
|
+
if (e._ignore) return; // https://github.com/ksc-fe/kpc/issues/788
|
|
29
|
+
|
|
30
|
+
var timeStamp = e.timeStamp || getNow();
|
|
31
|
+
|
|
32
|
+
if (!skipTimestampCheck && onDocumentClick.timeStamp > timeStamp + 1) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
10
36
|
var target = e.target;
|
|
11
37
|
var elem = isFunction(ref) ? ref() : ref.value;
|
|
12
38
|
if (containsOrEqual(elem, target)) return;
|
|
@@ -14,6 +40,7 @@ export function useDocumentClick(ref, callback, manual) {
|
|
|
14
40
|
};
|
|
15
41
|
|
|
16
42
|
var add = function add() {
|
|
43
|
+
onDocumentClick.timeStamp = getNow();
|
|
17
44
|
document.addEventListener('click', onDocumentClick);
|
|
18
45
|
document.addEventListener('contextmenu', onDocumentClick);
|
|
19
46
|
};
|
package/es/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @king-design v2.0.
|
|
2
|
+
* @king-design v2.0.13-beta.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Kingsoft Cloud
|
|
5
5
|
* Released under the MIT License
|
|
@@ -57,4 +57,4 @@ export * from './components/tree';
|
|
|
57
57
|
export * from './components/treeSelect';
|
|
58
58
|
export * from './components/upload';
|
|
59
59
|
export * from './components/wave';
|
|
60
|
-
export declare const version = "2.0.
|
|
60
|
+
export declare const version = "2.0.13-beta.0";
|
package/es/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @king-design v2.0.
|
|
2
|
+
* @king-design v2.0.13-beta.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Kingsoft Cloud
|
|
5
5
|
* Released under the MIT License
|
|
@@ -59,5 +59,5 @@ export * from './components/tree';
|
|
|
59
59
|
export * from './components/treeSelect';
|
|
60
60
|
export * from './components/upload';
|
|
61
61
|
export * from './components/wave';
|
|
62
|
-
export var version = '2.0.
|
|
62
|
+
export var version = '2.0.13-beta.0';
|
|
63
63
|
/* generate end */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _inheritsLoose from "@babel/runtime-corejs3/helpers/inheritsLoose";
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { Dropdown, DropdownMenu, DropdownItem, Button, Icon } from '@king-design/react';
|
|
3
|
+
import { Dropdown, DropdownMenu, DropdownItem, Button, Icon, Input } from '@king-design/react';
|
|
4
4
|
import './index.styl';
|
|
5
5
|
|
|
6
6
|
var Demo = /*#__PURE__*/function (_React$Component) {
|
|
@@ -23,7 +23,11 @@ var Demo = /*#__PURE__*/function (_React$Component) {
|
|
|
23
23
|
type: "primary"
|
|
24
24
|
}, "click ", /*#__PURE__*/React.createElement(Icon, {
|
|
25
25
|
className: "ion-ios-arrow-down"
|
|
26
|
-
})), /*#__PURE__*/React.createElement(DropdownMenu, null, /*#__PURE__*/React.createElement(DropdownItem, null, "item 1"), /*#__PURE__*/React.createElement(DropdownItem, null, "item 2"), /*#__PURE__*/React.createElement(DropdownItem, null, "item 3")))
|
|
26
|
+
})), /*#__PURE__*/React.createElement(DropdownMenu, null, /*#__PURE__*/React.createElement(DropdownItem, null, "item 1"), /*#__PURE__*/React.createElement(DropdownItem, null, "item 2"), /*#__PURE__*/React.createElement(DropdownItem, null, "item 3"))), /*#__PURE__*/React.createElement(Dropdown, {
|
|
27
|
+
trigger: "focus"
|
|
28
|
+
}, /*#__PURE__*/React.createElement(Input, {
|
|
29
|
+
placeholder: "focus"
|
|
30
|
+
}), /*#__PURE__*/React.createElement(DropdownMenu, null, /*#__PURE__*/React.createElement(DropdownItem, null, "item 1"), /*#__PURE__*/React.createElement(DropdownItem, null, "item 2"), /*#__PURE__*/React.createElement(DropdownItem, null, "item 3"))));
|
|
27
31
|
};
|
|
28
32
|
|
|
29
33
|
return Demo;
|
|
@@ -95,7 +95,7 @@ var Demo = /*#__PURE__*/function (_React$Component) {
|
|
|
95
95
|
"verticalAlign": "middle"
|
|
96
96
|
}
|
|
97
97
|
}), /*#__PURE__*/React.createElement("span", {
|
|
98
|
-
className: "
|
|
98
|
+
className: "middle"
|
|
99
99
|
}, value));
|
|
100
100
|
}
|
|
101
101
|
}, _mapInstanceProperty(_context3 = ['ion-chatbubble', 'ion-person-stalker', 'ion-beer', 'ion-camera']).call(_context3, function ($value, $key) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _inheritsLoose from "@babel/runtime-corejs3/helpers/inheritsLoose";
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { Tooltip, ButtonGroup, Button } from '@king-design/react';
|
|
3
|
+
import { Tooltip, ButtonGroup, Button, Input } from '@king-design/react';
|
|
4
4
|
|
|
5
5
|
var Demo = /*#__PURE__*/function (_React$Component) {
|
|
6
6
|
_inheritsLoose(Demo, _React$Component);
|
|
@@ -20,7 +20,12 @@ var Demo = /*#__PURE__*/function (_React$Component) {
|
|
|
20
20
|
}, /*#__PURE__*/React.createElement(Button, null, "click")), /*#__PURE__*/React.createElement(Tooltip, {
|
|
21
21
|
hoverable: true,
|
|
22
22
|
content: "the text can be hovered"
|
|
23
|
-
}, /*#__PURE__*/React.createElement(Button, null, "hoverable"))
|
|
23
|
+
}, /*#__PURE__*/React.createElement(Button, null, "hoverable")), /*#__PURE__*/React.createElement(Tooltip, {
|
|
24
|
+
trigger: "focus",
|
|
25
|
+
content: "foucs"
|
|
26
|
+
}, /*#__PURE__*/React.createElement(Input, {
|
|
27
|
+
placeholder: "focus"
|
|
28
|
+
})));
|
|
24
29
|
};
|
|
25
30
|
|
|
26
31
|
return Demo;
|
|
@@ -5,13 +5,40 @@ export interface IgnoreClickEvent extends MouseEvent {
|
|
|
5
5
|
_ignore?: boolean
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
type FnWithTime = {
|
|
9
|
+
(e: IgnoreClickEvent): void;
|
|
10
|
+
timeStamp?: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// @reference: Vue3.0
|
|
14
|
+
let getNow = Date.now;
|
|
15
|
+
// Determine what event timestamp the browser is using. Annoyingly, the
|
|
16
|
+
// timestamp can either be hi-res (relative to page load) or low-res
|
|
17
|
+
// (relative to UNIX epoch), so in order to compare time we have to use the
|
|
18
|
+
// same timestamp type when saving the flush timestamp.
|
|
19
|
+
if (getNow() > document.createEvent('Event').timeStamp) {
|
|
20
|
+
// if the low-res timestamp which is bigger than the event timestamp
|
|
21
|
+
// (which is evaluated AFTER) it means the event is using a hi-res timestamp,
|
|
22
|
+
// and we need to use the hi-res version for event listeners as well.
|
|
23
|
+
getNow = () => performance.now();
|
|
24
|
+
}
|
|
25
|
+
// #3485: Firefox <= 53 has incorrect Event.timeStamp implementation
|
|
26
|
+
// and does not fire microtasks in between event propagation, so safe to exclude.
|
|
27
|
+
const ffMatch = navigator.userAgent.match(/firefox\/(\d+)/i);
|
|
28
|
+
const skipTimestampCheck = !!(ffMatch && Number(ffMatch[1]) <= 53);
|
|
29
|
+
|
|
8
30
|
export function useDocumentClick(
|
|
9
31
|
ref: RefObject<Element> | (() => Element),
|
|
10
32
|
callback: (e: MouseEvent) => void,
|
|
11
33
|
manual: boolean = false
|
|
12
34
|
) {
|
|
13
|
-
const onDocumentClick = (e: IgnoreClickEvent) => {
|
|
35
|
+
const onDocumentClick: FnWithTime = (e: IgnoreClickEvent) => {
|
|
14
36
|
if (e._ignore) return;
|
|
37
|
+
// https://github.com/ksc-fe/kpc/issues/788
|
|
38
|
+
const timeStamp = e.timeStamp || getNow();
|
|
39
|
+
if (!skipTimestampCheck && onDocumentClick.timeStamp! > timeStamp + 1) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
15
42
|
|
|
16
43
|
const target = e.target as Element;
|
|
17
44
|
const elem = isFunction(ref) ? ref() : ref.value!;
|
|
@@ -21,6 +48,7 @@ export function useDocumentClick(
|
|
|
21
48
|
};
|
|
22
49
|
|
|
23
50
|
const add = () => {
|
|
51
|
+
onDocumentClick.timeStamp = getNow();
|
|
24
52
|
document.addEventListener('click', onDocumentClick);
|
|
25
53
|
document.addEventListener('contextmenu', onDocumentClick);
|
|
26
54
|
};
|
package/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @king-design v2.0.
|
|
2
|
+
* @king-design v2.0.13-beta.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Kingsoft Cloud
|
|
5
5
|
* Released under the MIT License
|
|
@@ -62,6 +62,6 @@ export * from './components/treeSelect';
|
|
|
62
62
|
export * from './components/upload';
|
|
63
63
|
export * from './components/wave';
|
|
64
64
|
|
|
65
|
-
export const version = '2.0.
|
|
65
|
+
export const version = '2.0.13-beta.0';
|
|
66
66
|
|
|
67
67
|
/* generate end */
|