feat: update tree doubleclick to dbclick

pull/1431/head
tanjinzhou 2019-11-15 13:03:59 +08:00
parent b552450d9a
commit 5e27ff8da4
6 changed files with 19 additions and 13 deletions

View File

@ -1,6 +1,7 @@
import omit from 'omit.js'; import omit from 'omit.js';
import debounce from 'lodash/debounce'; import debounce from 'lodash/debounce';
import PropTypes from '../_util/vue-types'; import PropTypes from '../_util/vue-types';
import warning from '../_util/warning';
import { conductExpandParent, convertTreeToEntities } from '../vc-tree/src/util'; import { conductExpandParent, convertTreeToEntities } from '../vc-tree/src/util';
import Tree, { TreeProps } from './Tree'; import Tree, { TreeProps } from './Tree';
import { calcRangeKeys, getFullKeyList } from './util'; import { calcRangeKeys, getFullKeyList } from './util';
@ -9,7 +10,7 @@ import BaseMixin from '../_util/BaseMixin';
import { initDefaultProps, getOptionProps } from '../_util/props-util'; import { initDefaultProps, getOptionProps } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider'; import { ConfigConsumerProps } from '../config-provider';
// export type ExpandAction = false | 'click' | 'doubleClick'; export interface // export type ExpandAction = false | 'click' | 'dbclick'; export interface
// DirectoryTreeProps extends TreeProps { expandAction?: ExpandAction; } // DirectoryTreeProps extends TreeProps { expandAction?: ExpandAction; }
// export interface DirectoryTreeState { expandedKeys?: string[]; // export interface DirectoryTreeState { expandedKeys?: string[];
// selectedKeys?: string[]; } // selectedKeys?: string[]; }
@ -32,7 +33,7 @@ export default {
props: initDefaultProps( props: initDefaultProps(
{ {
...TreeProps(), ...TreeProps(),
expandAction: PropTypes.oneOf([false, 'click', 'doubleclick']), expandAction: PropTypes.oneOf([false, 'click', 'doubleclick', 'dbclick']),
}, },
{ {
showIcon: true, showIcon: true,
@ -103,11 +104,12 @@ export default {
const { expandAction } = this.$props; const { expandAction } = this.$props;
// Expand the tree // Expand the tree
if (expandAction === 'doubleclick') { if (expandAction === 'dbclick' || expandAction === 'doubleclick') {
this.onDebounceExpand(event, node); this.onDebounceExpand(event, node);
} }
this.$emit('doubleclick', event, node); this.$emit('doubleclick', event, node);
this.$emit('dbclick', event, node);
}, },
onSelect(keys, event) { onSelect(keys, event) {
@ -181,6 +183,10 @@ export default {
const getPrefixCls = this.configProvider.getPrefixCls; const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('tree', customizePrefixCls); const prefixCls = getPrefixCls('tree', customizePrefixCls);
const { _expandedKeys: expandedKeys, _selectedKeys: selectedKeys } = this.$data; const { _expandedKeys: expandedKeys, _selectedKeys: selectedKeys } = this.$data;
warning(
!this.$listeners.doubleclick,
'`doubleclick` is deprecated. please use `dbclick` instead.',
);
const treeProps = { const treeProps = {
props: { props: {
icon: getIcon, icon: getIcon,
@ -195,7 +201,7 @@ export default {
...omit(this.$listeners, ['update:selectedKeys']), ...omit(this.$listeners, ['update:selectedKeys']),
select: this.onSelect, select: this.onSelect,
click: this.onClick, click: this.onClick,
doubleclick: this.onDoubleClick, dbclick: this.onDoubleClick,
expand: this.onExpand, expand: this.onExpand,
}, },
}; };

View File

@ -64,8 +64,8 @@ One of the Tree `treeNode` prop for describing the tree's node, TreeNode has the
### DirectoryTree props ### DirectoryTree props
| Property | Description | Type | Default | | Property | Description | Type | Default |
| --- | --- | --- | --- | | ------------ | ------------------------------------------------------------ | ------ | ------- |
| expandAction | Directory open logic, optional `false` `'click'` `'doubleclick'` | string | click | | expandAction | Directory open logic, optional `false` `'click'` `'dbclick'` | string | click |
## FAQ ## FAQ

View File

@ -64,8 +64,8 @@
### DirectoryTree props ### DirectoryTree props
| 参数 | 说明 | 类型 | 默认值 | | 参数 | 说明 | 类型 | 默认值 |
| ------------ | ---------------------------------------------------- | ------ | ------ | | ------------ | ------------------------------------------------ | ------ | ------ |
| expandAction | 目录展开逻辑,可选 `false` `'click'` `'doubleclick'` | string | click | | expandAction | 目录展开逻辑,可选 `false` `'click'` `'dbclick'` | string | click |
## FAQ ## FAQ

View File

@ -61,7 +61,7 @@ export default {
}, },
on: { on: {
click: onSelect, click: onSelect,
doubleclick: onItemDoubleClick, dbclick: onItemDoubleClick,
mousedown: e => e.preventDefault(), mousedown: e => e.preventDefault(),
}, },
key: Array.isArray(key) ? key.join('__ant__') : key, key: Array.isArray(key) ? key.join('__ant__') : key,

View File

@ -116,7 +116,7 @@ export default {
customRow={(record, index) => ({ customRow={(record, index) => ({
on: { on: {
click: onRowClick.bind(null, record, index), click: onRowClick.bind(null, record, index),
dblclick: onRowDoubleClick.bind(null, record, index), dbclick: onRowDoubleClick.bind(null, record, index),
}, },
})} })}
/> />

View File

@ -380,7 +380,7 @@ const Tree = {
}, },
onNodeDoubleClick(e, treeNode) { onNodeDoubleClick(e, treeNode) {
this.__emit('doubleclick', e, treeNode); this.__emit('dbclick', e, treeNode);
}, },
onNodeSelect(e, treeNode) { onNodeSelect(e, treeNode) {