Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/components/dropdown-item/dropdown-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default class DropdownMenuItem extends SuperComponent {
valueAlias: 'value',
computedLabel: '',
firstCheckedValue: '', // 用于多选再次打开自动定位到首个选项
keepActive: false, // 是否保持标题高亮(含菜单收起态),仅多选且有选中项时生效
};

relations: RelationsOptions = {
Expand Down Expand Up @@ -98,6 +99,14 @@ export default class DropdownMenuItem extends SuperComponent {
'label, computedLabel, disabled'() {
this.$parent?.getAllItems();
},
'keepLabelActive, multiple, value'() {
const { keepLabelActive, multiple, value } = this.data;

this.setData({
keepActive: Boolean(multiple && keepLabelActive && Array.isArray(value) && value.length > 0),
});
this.$parent?.getAllItems();
},
show(visible) {
if (visible) {
this.getParentBottom(() => {
Expand Down
5 changes: 5 additions & 0 deletions packages/components/dropdown-item/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ const props: TdDropdownItemProps = {
type: Boolean,
value: false,
},
/** 是否保持标题高亮(含菜单收起态),仅多选场景生效 */
keepLabelActive: {
type: Boolean,
value: false,
},
/** 用来定义 value / label / disabled 在 `options` 中对应的字段别名 */
keys: {
type: Object,
Expand Down
8 changes: 8 additions & 0 deletions packages/components/dropdown-item/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ export interface TdDropdownItemProps {
type: BooleanConstructor;
value?: boolean;
};
/**
* 是否保持标题高亮(含菜单收起态),仅多选场景生效
* @default false
*/
keepLabelActive?: {
type: BooleanConstructor;
value?: boolean;
};
/**
* 用来定义 value / label / disabled 在 `options` 中对应的字段别名
*/
Expand Down
1 change: 1 addition & 0 deletions packages/components/dropdown-menu/README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ name | type | default | description | required
style | Object | - | CSS(Cascading Style Sheets) | N
custom-style | Object | - | CSS(Cascading Style Sheets),used to set style on virtual component | N
disabled | Boolean | false | \- | N
keep-label-active | Boolean | false | `1.18.0` | N
keys | Object | - | Typescript: `KeysType`。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/common/common.ts) | N
label | String | - | \- | N
multiple | Boolean | false | \- | N
Expand Down
1 change: 1 addition & 0 deletions packages/components/dropdown-menu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ t-class-label | 标签样式类
style | Object | - | 样式 | N
custom-style | Object | - | 样式,一般用于开启虚拟化组件节点场景 | N
disabled | Boolean | false | 是否禁用操作项 | N
keep-label-active | Boolean | false | `1.18.0`。是否保持标题高亮(含菜单收起态),仅多选场景生效 | N
keys | Object | - | 用来定义 value / label / disabled 在 `options` 中对应的字段别名。TS 类型:`KeysType`。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/common/common.ts) | N
label | String | - | 标题 | N
multiple | Boolean | false | 是否多选 | N
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,70 @@ exports[`dropdown-menu :base 1`] = `
</wx-view>
</t-icon>
</wx-view>
<wx-view
ariaDisabled="{{false}}"
ariaExpanded="{{false}}"
ariaHaspopup="menu"
ariaRole="button"
class="t-dropdown-menu__item t-dropdown-menu__item--active t-dropdown-menu__item--2 t-class-item"
data-index="{{2}}"
bind:tap="handleToggle"
>
<wx-view
class="t-dropdown-menu__title t-class-label"
>
保持高亮
</wx-view>
<t-icon
tClass="t-dropdown-menu__icon t-dropdown-menu__icon-- t-class-icon"
bind:click=""
>
<wx-view
ariaHidden="{{true}}"
ariaLabel=""
ariaRole=""
class="t-icon class t-class"
style=""
bind:tap="onTap"
>
<wx-label
class="t-icon-caret-down-small t-icon-base"
/>
</wx-view>
</t-icon>
</wx-view>
<wx-view
ariaDisabled="{{false}}"
ariaExpanded="{{false}}"
ariaHaspopup="menu"
ariaRole="button"
class="t-dropdown-menu__item t-dropdown-menu__item--3 t-class-item"
data-index="{{3}}"
bind:tap="handleToggle"
>
<wx-view
class="t-dropdown-menu__title t-class-label"
>
保持高亮无选中
</wx-view>
<t-icon
tClass="t-dropdown-menu__icon t-dropdown-menu__icon-- t-class-icon"
bind:click=""
>
<wx-view
ariaHidden="{{true}}"
ariaLabel=""
ariaRole=""
class="t-icon class t-class"
style=""
bind:tap="onTap"
>
<wx-label
class="t-icon-caret-down-small t-icon-base"
/>
</wx-view>
</t-icon>
</wx-view>
<t-dropdown-item
id="first"
bind:change="handleSingleSelect"
Expand Down Expand Up @@ -622,6 +686,12 @@ exports[`dropdown-menu :base 1`] = `
<t-dropdown-item
id="second"
/>
<t-dropdown-item
id="keep-active"
/>
<t-dropdown-item
id="keep-active-empty"
/>
</wx-view>
</t-dropdown-menu>
</main>
Expand Down
4 changes: 4 additions & 0 deletions packages/components/dropdown-menu/__test__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Component({
value: ['option_3'],
options: singleSelectOptions,
},
emptyMultipleSelect: {
value: [],
options: singleSelectOptions,
},
closeOnClickOverlay: true,
style: 'color: red',
customStyle: 'font-size: 9px',
Expand Down
25 changes: 25 additions & 0 deletions packages/components/dropdown-menu/__test__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,29 @@ describe('dropdown-menu', () => {
expect($first.dom.textContent.trim()).toBe('first');
}
});

it(':keepLabelActive', async () => {
const comp = simulate.render(id);
comp.attach(document.createElement('parent-wrapper'));
await simulate.sleep();

const $keepActive = comp.querySelector('#keep-active');
const $keepActiveEmpty = comp.querySelector('#keep-active-empty');
const $second = comp.querySelector('#second');

// 子组件:multiple + keepLabelActive + 有选中项 → keepActive 为 true
expect($keepActive.instance.data.keepActive).toBeTruthy();
// 子组件:multiple + keepLabelActive 但无选中项 → keepActive 为 false
expect($keepActiveEmpty.instance.data.keepActive).toBeFalsy();
// 子组件:multiple 但未开启 keepLabelActive → keepActive 为 false
expect($second.instance.data.keepActive).toBeFalsy();

const $items = comp.querySelectorAll('#base >>> .t-dropdown-menu__item');
// 收起态下:multiple + keepLabelActive + 有选中项 → 标题保持高亮
expect($items[2].dom.className).toContain('t-dropdown-menu__item--active');
// multiple 未开启 keepLabelActive → 收起态不高亮
expect($items[1].dom.className).not.toContain('t-dropdown-menu__item--active');
// keepLabelActive 但无选中项 → 不高亮
expect($items[3].dom.className).not.toContain('t-dropdown-menu__item--active');
});
});
16 changes: 16 additions & 0 deletions packages/components/dropdown-menu/__test__/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,20 @@
defaultValue="{{multipleSelect.value}}"
multiple
/>
<t-dropdown-item
id="keep-active"
label="保持高亮"
options="{{multipleSelect.options}}"
defaultValue="{{multipleSelect.value}}"
keepLabelActive
multiple
/>
<t-dropdown-item
id="keep-active-empty"
label="保持高亮无选中"
options="{{multipleSelect.options}}"
defaultValue="{{emptyMultipleSelect.value}}"
keepLabelActive
multiple
/>
</t-dropdown-menu>
1 change: 1 addition & 0 deletions packages/components/dropdown-menu/dropdown-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export default class DropdownMenu extends SuperComponent {
const menus = this.$children.map(({ data }) => ({
label: data.computedLabel || data.label,
disabled: data.disabled,
active: data.keepActive,
}));

this.setData({
Expand Down
2 changes: 1 addition & 1 deletion packages/components/dropdown-menu/dropdown-menu.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
wx:key="index"
bindtap="handleToggle"
data-index="{{index}}"
class="{{_.cls(classPrefix + '__item', [['active', activeIdx == index], ['disabled', item.disabled], [index, true]])}} {{prefix}}-class-item"
class="{{_.cls(classPrefix + '__item', [['active', activeIdx == index || item.active], ['disabled', item.disabled], [index, true]])}} {{prefix}}-class-item"
aria-disabled="{{item.disabled}}"
aria-role="button"
aria-expanded="{{activeIdx === index}}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
top: 0;
overflow: hidden;
bottom: 0;
z-index: var(--td-z-index-dropdown-menu, 11600);

&__content {
display: flex;
flex-direction: column;
z-index: 11600;
overflow: hidden;
}

Expand Down
13 changes: 12 additions & 1 deletion packages/uniapp-components/dropdown-item/dropdown-item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/>
<t-popup
:visible="show"
:z-index="zIndex + 1"
:z-index="zIndex ? zIndex + 1 : 0"
:duration="duration"
:show-overlay="showOverlay"
custom-style="position: absolute"
Expand Down Expand Up @@ -179,6 +179,7 @@ export default {
valueAlias: 'value',
computedLabel: '',
firstCheckedValue: '',
keepActive: false, // 是否保持标题高亮(含菜单收起态),仅多选且有选中项时生效

dataValue: coalesce(this.value, this.defaultValue),

Expand Down Expand Up @@ -270,12 +271,16 @@ export default {
} else {
this.computedLabel = '';
}

this.updateKeepActive();
},
immediate: true,
},
label: 'getParentAllItems',
computedLabel: 'getParentAllItems',
disabled: 'getParentAllItems',
keepLabelActive: 'updateKeepActive',
multiple: 'updateKeepActive',
show: {
handler(visible) {
if (visible) {
Expand Down Expand Up @@ -303,6 +308,12 @@ export default {
getParentAllItems() {
this[RELATION_MAP.DropdownItem]?.getAllItems();
},
updateKeepActive() {
const { keepLabelActive, multiple, dataValue } = this;

this.keepActive = Boolean(multiple && keepLabelActive && Array.isArray(dataValue) && dataValue.length > 0);
this.getParentAllItems();
},
closeDropdown() {
this[RELATION_MAP.DropdownItem].activeIdx = -1;
this.show = false;
Expand Down
2 changes: 2 additions & 0 deletions packages/uniapp-components/dropdown-item/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import type { TdDropdownItemProps } from './type';
export default {
/** 是否禁用操作项 */
disabled: Boolean,
/** 是否保持标题高亮(含菜单收起态),仅多选场景生效 */
keepLabelActive: Boolean,
/** 用来定义 value / label / disabled 在 `options` 中对应的字段别名 */
keys: {
type: Object,
Expand Down
7 changes: 6 additions & 1 deletion packages/uniapp-components/dropdown-item/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export interface TdDropdownItemProps {
* @default false
*/
disabled?: boolean;
/**
* 是否保持标题高亮(含菜单收起态),仅多选场景生效
* @default false
*/
keepLabelActive?: boolean;
/**
* 用来定义 value / label / disabled 在 `options` 中对应的字段别名
*/
Expand Down Expand Up @@ -69,7 +74,7 @@ export interface TdDropdownItemProps {

export interface DropdownOption {
label: string;
disabled: boolean;
disabled?: boolean;
value: DropdownValue | null;
}

Expand Down
11 changes: 6 additions & 5 deletions packages/uniapp-components/dropdown-menu/README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ arrow-icon | String / Object | 'caret-down-small' | \- | N
close-on-click-overlay | Boolean | true | \- | N
duration | String / Number | 200 | \- | N
show-overlay | Boolean | true | \- | N
z-index | Number | 11600 | \- | N
z-index | Number | - | \- | N

### DropdownMenu Events

Expand Down Expand Up @@ -42,15 +42,16 @@ name | type | default | description | required
-- | -- | -- | -- | --
custom-style | Object | - | CSS(Cascading Style Sheets) | N
disabled | Boolean | false | \- | N
keys | Object | - | Typescript:`KeysType`。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/packages/uniapp-components/common/common.ts) | N
keep-label-active | Boolean | false | `1.0.1` | N
keys | Object | - | Typescript: `KeysType`。[see more ts definition](https://github.com/tencent/tdesign-miniprogram/blob/develop/packages/uniapp-components/common/common.ts) | N
label | String | - | \- | N
multiple | Boolean | false | \- | N
options | Array | [] | Typescript:`Array<DropdownOption>` `interface DropdownOption { label: string; disabled: boolean; value: DropdownValue; }`。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/packages/uniapp-components/dropdown-item/type.ts) | N
options | Array | [] | Typescript: `Array<DropdownOption>` `interface DropdownOption { label: string; disabled?: boolean; value: DropdownValue; }`。[see more ts definition](https://github.com/tencent/tdesign-miniprogram/blob/develop/packages/uniapp-components/dropdown-item/type.ts) | N
options-columns | String / Number | 1 | \- | N
options-layout | String | columns | `deprecated` | N
placement | String | left | options: left/right | N
value | String / Number / Array | undefined | `v-model:value` is supported。Typescript:`DropdownValue ` `type DropdownValue = string \| number \| Array<DropdownValue>;`。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/packages/uniapp-components/dropdown-item/type.ts) | N
default-value | String / Number / Array | undefined | uncontrolled property。Typescript:`DropdownValue ` `type DropdownValue = string \| number \| Array<DropdownValue>;`。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/packages/uniapp-components/dropdown-item/type.ts) | N
value | String / Number / Array | undefined | `v-model:value` is supported。Typescript: `DropdownValue ` `type DropdownValue = string \| number \| Array<DropdownValue>;`。[see more ts definition](https://github.com/tencent/tdesign-miniprogram/blob/develop/packages/uniapp-components/dropdown-item/type.ts) | N
default-value | String / Number / Array | undefined | uncontrolled property。Typescript: `DropdownValue ` `type DropdownValue = string \| number \| Array<DropdownValue>;`。[see more ts definition](https://github.com/tencent/tdesign-miniprogram/blob/develop/packages/uniapp-components/dropdown-item/type.ts) | N

### DropdownItem Events

Expand Down
11 changes: 6 additions & 5 deletions packages/uniapp-components/dropdown-menu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ arrow-icon | String / Object | 'caret-down-small' | 自定义箭头图标 | N
close-on-click-overlay | Boolean | true | 是否在点击遮罩层后关闭菜单 | N
duration | String / Number | 200 | 动画时长 | N
show-overlay | Boolean | true | 是否显示遮罩层 | N
z-index | Number | 11600 | 菜单栏 z-index 层级 | N
z-index | Number | - | 菜单栏 z-index 层级,默认为 11600 | N

### DropdownMenu Events

Expand Down Expand Up @@ -72,15 +72,16 @@ t-class-label | 标签样式类
-- | -- | -- | -- | --
custom-style | Object | - | 自定义样式 | N
disabled | Boolean | false | 是否禁用操作项 | N
keys | Object | - | 用来定义 value / label / disabled 在 `options` 中对应的字段别名。TS 类型:`KeysType`。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/packages/uniapp-components/common/common.ts) | N
keep-label-active | Boolean | false | `1.0.1`。是否保持标题高亮(含菜单收起态),仅多选场景生效 | N
keys | Object | - | 用来定义 value / label / disabled 在 `options` 中对应的字段别名。TS 类型:`KeysType`。[通用类型定义](https://github.com/tencent/tdesign-miniprogram/blob/develop/packages/uniapp-components/common/common.ts) | N
label | String | - | 标题 | N
multiple | Boolean | false | 是否多选 | N
options | Array | [] | 选项数据。TS 类型:`Array<DropdownOption>` `interface DropdownOption { label: string; disabled: boolean; value: DropdownValue; }`。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/packages/uniapp-components/dropdown-item/type.ts) | N
options | Array | [] | 选项数据。TS 类型:`Array<DropdownOption>` `interface DropdownOption { label: string; disabled?: boolean; value: DropdownValue; }`。[详细类型定义](https://github.com/tencent/tdesign-miniprogram/blob/develop/packages/uniapp-components/dropdown-item/type.ts) | N
options-columns | String / Number | 1 | 选项分栏(1-3) | N
options-layout | String | columns | 已废弃。选项排列;不再支持 tree 布局,可与 treeSelect 配合使用 | N
placement | String | left | 复选框和内容相对位置,仅单选菜单栏有效。可选项:left/right | N
value | String / Number / Array | undefined | 选中值。支持语法糖 `v-model:value`。TS 类型:`DropdownValue ` `type DropdownValue = string \| number \| Array<DropdownValue>;`。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/packages/uniapp-components/dropdown-item/type.ts) | N
default-value | String / Number / Array | undefined | 选中值。非受控属性。TS 类型:`DropdownValue ` `type DropdownValue = string \| number \| Array<DropdownValue>;`。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/packages/uniapp-components/dropdown-item/type.ts) | N
value | String / Number / Array | undefined | 选中值。支持语法糖 `v-model:value`。TS 类型:`DropdownValue ` `type DropdownValue = string \| number \| Array<DropdownValue>;`。[详细类型定义](https://github.com/tencent/tdesign-miniprogram/blob/develop/packages/uniapp-components/dropdown-item/type.ts) | N
default-value | String / Number / Array | undefined | 选中值。非受控属性。TS 类型:`DropdownValue ` `type DropdownValue = string \| number \| Array<DropdownValue>;`。[详细类型定义](https://github.com/tencent/tdesign-miniprogram/blob/develop/packages/uniapp-components/dropdown-item/type.ts) | N

### DropdownItem Events

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
:data-index="index"
:class="[
classPrefix + '__item',
activeIdx == index ? classPrefix + '__item' + '--active' : '',
activeIdx == index || item.active ? classPrefix + '__item' + '--active' : '',
item.disabled ? classPrefix + '__item' + '--disabled' : '',
true ? classPrefix + '__item' + '--index' : '',
tClassItem,
Expand Down Expand Up @@ -148,6 +148,7 @@ export default {
const menus = this.children?.map((data) => ({
label: data.computedLabel || data.label,
disabled: data.disabled,
active: data.keepActive,
}));

this.menus = menus;
Expand Down
Loading
Loading