Skip to content

Commit

Permalink
fix(DropdownMenuItem): the label attribute has higher priority than t…
Browse files Browse the repository at this point in the history
…he selected item (#1547)
  • Loading branch information
anlyyao authored Aug 27, 2024
1 parent 22620f3 commit c726a51
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
17 changes: 11 additions & 6 deletions src/dropdown-menu/dropdown-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useExpose } from '../shared';
import { findRelativeRect, findRelativeContainer } from './dom-utils';
import { useContent } from '../hooks/tnode';
import DropdownMenuProps from './props';
import { TdDropdownItemProps } from './type';

const { prefix } = config;
const name = `${prefix}-dropdown-menu`;
Expand Down Expand Up @@ -65,11 +66,13 @@ export default defineComponent({
state.itemsLabel.push(computedLabel);

return {
labelProps: label, // 优先级: label属性 > 选中项
label: computedLabel,
disabled: disabled !== undefined && disabled !== false,
};
}
return {
labelProps: label,
label: label || target.label,
disabled: disabled !== undefined && disabled !== false,
};
Expand Down Expand Up @@ -177,12 +180,14 @@ export default defineComponent({

return (
<div ref={refBar} class={classes.value}>
{(menuTitles.value || []).map((item: { label: any }, idx: number) => (
<div class={styleBarItem.value(item, idx)} onClick={() => expandMenu(item, idx)}>
<div class={`${name}__title`}>{item.label}</div>
{renderDownIcon(item, idx)}
</div>
))}
{(menuTitles.value || []).map(
(item: { label: any; labelProps: TdDropdownItemProps['label'] }, idx: number) => (
<div class={styleBarItem.value(item, idx)} onClick={() => expandMenu(item, idx)}>
<div class={`${name}__title`}>{item.labelProps || item.label}</div>
{renderDownIcon(item, idx)}
</div>
),
)}
{defaultSlot}
</div>
);
Expand Down
9 changes: 5 additions & 4 deletions src/popup/popup.en-US.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
:: BASE_DOC ::

## API

### Popup Props

name | type | default | description | required
Expand All @@ -9,8 +10,8 @@ attach | String / Function | 'body' | Typescript:`AttachNode`。[see more ts d
closeBtn | Boolean / Slot / Function | - | Typescript:`boolean \| TNode`[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N
closeOnOverlayClick | Boolean | true | \- | N
destroyOnClose | Boolean | false | \- | N
overlayProps | Object | {} | \- | N
placement | String | top | optionstop/left/right/bottom/center | N
overlayProps | Object | {} | Typescript:`OverlayProps`[Overlay API Documents](./overlay?tab=api)[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/popup/type.ts) | N
placement | String | top | options: top/left/right/bottom/center | N
preventScrollThrough | Boolean | true | \- | N
showOverlay | Boolean | true | \- | N
transitionName | String | - | \- | N
Expand All @@ -33,10 +34,10 @@ open | \- | \-
opened | \- | \-
visible-change | `(visible: boolean, trigger: PopupSource) ` | [see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/popup/type.ts)。<br/>`type PopupSource = 'close-btn' \| 'overlay'`<br/>


### CSS Variables

The component provides the following CSS variables, which can be used to customize styles.
Name | Default Value | Description
-- | -- | --
--td-popup-bg-color | @bg-color-container | -
--td-popup-border-radius | @radius-default | -
--td-popup-border-radius | @radius-default | -
9 changes: 5 additions & 4 deletions src/popup/popup.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
:: BASE_DOC ::

## API

### Popup Props

名称 | 类型 | 默认值 | 说明 | 必传
名称 | 类型 | 默认值 | 描述 | 必传
-- | -- | -- | -- | --
attach | String / Function | 'body' | 制定挂载节点。数据类型为 String 时,会被当作选择器处理,进行节点查询。示例:'body' 或 () => document.body。TS 类型:`AttachNode`[通用类型定义](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N
closeBtn | Boolean / Slot / Function | - | 是否展示关闭按钮,值为 `true` 显示默认关闭按钮;值为 `false` 则不显示关闭按钮;也可以自定义关闭按钮。TS 类型:`boolean \| TNode`[通用类型定义](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N
closeOnOverlayClick | Boolean | true | 点击遮罩层是否关闭 | N
destroyOnClose | Boolean | false | 是否在关闭浮层时销毁浮层 | N
overlayProps | Object | {} | 遮罩层的属性,透传至 overlay | N
overlayProps | Object | {} | 遮罩层的属性,透传至 overlay。TS 类型:`OverlayProps`[Overlay API Documents](./overlay?tab=api)[详细类型定义](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/popup/type.ts) | N
placement | String | top | 浮层出现位置。可选项:top/left/right/bottom/center | N
preventScrollThrough | Boolean | true | 是否阻止背景滚动 | N
showOverlay | Boolean | true | 是否显示遮罩层 | N
Expand All @@ -33,10 +34,10 @@ open | \- | 组件准备展示时触发
opened | \- | 组件展示且动画结束后执行
visible-change | `(visible: boolean, trigger: PopupSource) ` | 当浮层隐藏或显示时触发。[详细类型定义](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/popup/type.ts)。<br/>`type PopupSource = 'close-btn' \| 'overlay'`<br/>


### CSS Variables

组件提供了下列 CSS 变量,可用于自定义样式。
名称 | 默认值 | 描述
-- | -- | --
--td-popup-bg-color | @bg-color-container | -
--td-popup-border-radius | @radius-default | -
--td-popup-border-radius | @radius-default | -
4 changes: 2 additions & 2 deletions src/popup/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ export default {
/** 浮层出现位置 */
placement: {
type: String as PropType<TdPopupProps['placement']>,
// default: 'top' as TdPopupProps['placement'],
default: 'top' as TdPopupProps['placement'],
validator(val: TdPopupProps['placement']): boolean {
if (!val) return true;
return ['top', 'left', 'right', 'bottom', 'center'].includes(val);
},
},
/** 防止滚动穿透 */
/** 是否阻止背景滚动 */
preventScrollThrough: {
type: Boolean,
default: true,
Expand Down
7 changes: 4 additions & 3 deletions src/popup/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC
* */

import { OverlayProps } from '../overlay';
import { TNode, AttachNode } from '../common';

export interface TdPopupProps {
Expand All @@ -30,14 +31,14 @@ export interface TdPopupProps {
* 遮罩层的属性,透传至 overlay
* @default {}
*/
overlayProps?: object;
overlayProps?: OverlayProps;
/**
* 浮层出现位置
* @default top
*/
placement?: 'top' | 'left' | 'right' | 'bottom' | 'center' | '';
placement?: 'top' | 'left' | 'right' | 'bottom' | 'center';
/**
* 防止滚动穿透
* 是否阻止背景滚动
* @default true
*/
preventScrollThrough?: boolean;
Expand Down

0 comments on commit c726a51

Please sign in to comment.