diff --git a/scss/components/form/_nested-select.scss b/scss/components/form/_nested-select.scss index b4495733..ebd66042 100644 --- a/scss/components/form/_nested-select.scss +++ b/scss/components/form/_nested-select.scss @@ -41,6 +41,26 @@ background: $Form-select-onHover-bg; } + &--multi { + .#{$ns}Select-value { + position: static; + user-select: none; + line-height: $Form-input-lineHeight * $Form-input-fontSize - px2rem(2px); + display: inline-block; + vertical-align: middle; + font-size: $Form-selectValue-fontSize; + color: $Form-selectValue-color; + background: $Form-selectValue-bg; + border: px2rem(1px) solid $Form-selectValue-borderColor; + border-radius: px2rem(2px); + margin-right: $gap-xs; + margin-bottom: $gap-xs; + } + .#{$ns}Select-valueLabel { + padding: 0 $gap-xs; + } + } + &-placeholder { color: $Form-select-placeholderColor; line-height: $Form-input-lineHeight; @@ -52,12 +72,6 @@ flex-grow: 1; } - .#{$ns}Select-arrow { - position: absolute; - right: 0; - top: px2rem(10px); - } - &-clear { padding: px2rem(3px); cursor: pointer; @@ -95,7 +109,7 @@ } &-menu { - min-width: px2rem(160px); + min-width: px2rem(120px); max-height: px2rem(300px); background: $Form-select-menu-bg; color: $Form-select-menu-color; @@ -147,3 +161,17 @@ } } } + +// 需要能撑开 +@include media-breakpoint-up(sm) { + .#{$ns}Form-control--sizeXs > .#{$ns}NestedSelect, + .#{$ns}Form-control--sizeSm > .#{$ns}NestedSelect, + .#{$ns}Form-control--sizeMd > .#{$ns}NestedSelect, + .#{$ns}Form-control--sizeLg > .#{$ns}NestedSelect { + display: inline-flex !important; + + .#{$ns}Select-valueWrap { + width: 0; // ! 没有这个会撑开。 + } + } +} diff --git a/src/renderers/Cards.tsx b/src/renderers/Cards.tsx index 792366e4..5dd61bf5 100644 --- a/src/renderers/Cards.tsx +++ b/src/renderers/Cards.tsx @@ -752,7 +752,8 @@ export default class Cards extends React.Component { checkOnItemClick, masonryLayout, itemsClassName, - classnames: cx + classnames: cx, + data } = this.props; this.renderedToolbars = []; // 用来记录哪些 toolbar 已经渲染了,已经渲染了就不重复渲染了。 @@ -838,7 +839,9 @@ export default class Cards extends React.Component { })} ) : ( -
{placeholder}
+
+ {filter(placeholder, data)} +
)} {footer} diff --git a/src/renderers/Form/NestedSelect.tsx b/src/renderers/Form/NestedSelect.tsx index 21c74e1a..5e543dad 100644 --- a/src/renderers/Form/NestedSelect.tsx +++ b/src/renderers/Form/NestedSelect.tsx @@ -67,19 +67,75 @@ export default class NestedSelectControl extends React.Component< }); } + removeItem(index: number, e?: React.MouseEvent) { + let { + onChange, + selectedOptions, + disabled, + joinValues, + valueField, + extractValue, + delimiter, + value + } = this.props; + + if (disabled) { + return; + } + + e && e.stopPropagation(); + + selectedOptions.splice(index, 1); + + if (joinValues) { + value = (selectedOptions as Options) + .map(item => item[valueField || 'value']) + .join(delimiter || ','); + } else if (extractValue) { + value = (selectedOptions as Options).map( + item => item[valueField || 'value'] + ); + } + + onChange(value); + } + renderValue() { - const {multiple, classnames: cx, selectedOptions, labelField} = this.props; - const len = Array.isArray(selectedOptions) ? selectedOptions.length : 0; - return ( -
- {len > 0 ? ( -
- {multiple - ? `已选择 ${len} 项` - : selectedOptions[0][labelField || 'label']} -
- ) : null} -
+ const { + multiple, + classnames: cx, + selectedOptions, + labelField, + placeholder, + disabled + } = this.props; + + if (!(selectedOptions && selectedOptions.length > 0)) { + return ( +
{placeholder}
+ ); + } + + return selectedOptions.map((item, index) => + multiple ? ( +
+ + × + + + {item[labelField || 'label']} + +
+ ) : ( +
+ {item[labelField || 'label']} +
+ ) ); } @@ -364,11 +420,14 @@ export default class NestedSelectControl extends React.Component<
{index === 0 ? searchInput : null} {multiple && index === 0 ? ( -
+
+
- {!(selectedOptions && selectedOptions.length > 0) ? ( -
{placeholder}
- ) : null} +
+ {this.renderValue()} +
- {this.renderValue()} {this.renderClear()}