diff --git a/scss/components/form/_tree.scss b/scss/components/form/_tree.scss index 6b452490..5dce1891 100644 --- a/scss/components/form/_tree.scss +++ b/scss/components/form/_tree.scss @@ -1,3 +1,29 @@ +@mixin tree-input { + > i { + display: inline-block; + cursor: pointer; + margin-left: px2rem(5px); + } + + > input { + margin-left: px2rem(15px); + padding: px2rem(5px); + width: px2rem(150px); + height: px2rem(25px); + color: $Form-input-color; + + &::placeholder { + color: $Form-input-placeholderColor; + user-select: none; + } + + &:focus { + outline: none; + border: $borderWidth solid $info; + } + } +} + // todo .#{$ns}TreeControl { border: 1px solid $Form-input-borderColor; @@ -31,30 +57,7 @@ } > li { - > i { - display: inline-block; - cursor: pointer; - margin-left: 5px; - } - - > input { - margin-left: 15px; - padding: px2rem(5px); - width: px2rem(150px); - height: px2rem(25px); - color: $Form-input-color; - //height: $Form-input-lineHeight * $Form-input-fontSize; - - &::placeholder { - color: $Form-input-placeholderColor; - user-select: none; - } - - &:focus { - outline: none; - border: $borderWidth solid $info; - } - } + @include tree-input; } } @@ -72,7 +75,7 @@ > span > i { display: inline-block; cursor: pointer; - margin-left: 5px; + margin-left: px2rem(5px); } } @@ -82,35 +85,28 @@ &--isEdit { display: inline-block; - > i { - display: inline-block; - cursor: pointer; - margin-left: 5px; - } - - > input { - margin-left: 15px; - padding: px2rem(5px); - width: px2rem(150px); - height: px2rem(25px); - color: $Form-input-color; - //height: $Form-input-lineHeight * $Form-input-fontSize; - - &::placeholder { - color: $Form-input-placeholderColor; - user-select: none; - } - - &:focus { - outline: none; - border: $borderWidth solid $info; - } - } + @include tree-input; } } - &-rootItem > a > i { - margin-left: 0 !important; + &-rootItem { + > a > i { + margin-left: 0 !important; + } + + .#{$ns}Tree-addTop { + height: px2rem(25px); + line-height: px2rem(25px); + cursor: pointer; + padding-left: $Tree-indent; + > p > span { + padding-left: px2rem(5px); + } + + &-input { + @include tree-input + } + } } &-itemArrow { diff --git a/src/components/Tree.tsx b/src/components/Tree.tsx index 8c048791..2b756d24 100644 --- a/src/components/Tree.tsx +++ b/src/components/Tree.tsx @@ -9,7 +9,6 @@ import {eachTree, isVisible, isObject} from '../utils/helper'; import {Option, Options, value2array} from './Checkboxes'; import {ClassNamesFn, themeable} from '../theme'; import {highlight} from '../renderers/Form/Options'; -import debounce = require('lodash/debounce'); interface TreeSelectorProps { classPrefix: string; @@ -72,6 +71,7 @@ interface TreeSelectorState { addItem: Option | null; addingItem: Option | null; editingItem: Option | null; + addTop: boolean; } export class TreeSelector extends React.Component { @@ -135,7 +135,8 @@ export class TreeSelector extends React.Component { @@ -497,8 +517,8 @@ export class TreeSelector extends React.Component= maxLength) || - (minLength && selfChecked && this.state.value.length <= minLength)) + ((maxLength && !selfChecked && stateValue.length >= maxLength) || + (minLength && selfChecked && stateValue.length <= minLength)) ) { nodeDisabled = true; } @@ -543,13 +563,13 @@ export class TreeSelector extends React.Component - {!this.state.editItem || isObject(this.state.editItem) && (this.state.editItem as Option)[valueField] !== item[valueField] ? ( + {!editItem || isObject(editItem) && (editItem as Option)[valueField] !== item[valueField] ? ( {!isLeaf ? ( this.toggleUnfolded(item)} className={cx('Tree-itemArrow', { - 'is-folded': !this.state.unfolded[item[valueField]], + 'is-folded': !unfolded[item[valueField]], })} /> ) : null} @@ -579,10 +599,11 @@ export class TreeSelector extends React.Component {/* 非添加时 && 非编辑时 && 鼠标覆盖时是当前item时,显示添加/编辑/删除图标 */} - {!this.state.addItem - && !this.state.editItem - && isObject(this.state.hoverItem) - && (this.state.hoverItem as Option)[valueField as string] === item[valueField] ? ( + {!addTop + && !addItem + && !editItem + && isObject(hoverItem) + && (hoverItem as Option)[valueField as string] === item[valueField] ? ( {addMode ? this.addItem(item, !isLeaf)}> : null} {deletable ? this.deleteItem(item)}> : null} @@ -592,19 +613,19 @@ export class TreeSelector extends React.Component ) : (
- this.onChangeEditItem(item, e.currentTarget.value)}/> + this.onChangeEditItem(item, e.currentTarget.value)}/>
)} {/* 有children而且为展开状态 或者 添加child时 */} - {((childrenItems && this.state.unfolded[item[valueField]]) || this.state.addItem && (this.state.addItem[valueField] === item[valueField])) ? ( + {((childrenItems && unfolded[item[valueField]]) || addItem && (addItem[valueField] === item[valueField])) ? (