Skip to content

Commit

Permalink
feat(Tag): closable attributes support object type (#2590)
Browse files Browse the repository at this point in the history
* feat(Tag): closable attributes support object type

* test: update snapshots
  • Loading branch information
anlyyao authored Feb 5, 2024
1 parent b202baf commit 040aeb0
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/tag/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ isComponent: true

名称 | 类型 | 默认值 | 说明 | 必传
-- | -- | -- | -- | --
closable | Boolean | false | 标签是否可关闭 | N
closable | Boolean / Object / Slot | false | 标签是否可关闭 | N
disabled | Boolean | false | 标签禁用态,失效标签不能触发事件。默认风格(theme=default)才有禁用态 | N
icon | String / Object / Slot | - | 标签中的图标,可自定义图标呈现 | N
max-width | String / Number | - | 标签最大宽度,宽度超出后会出现省略号。示例:'50px' / 80 | N
Expand Down
2 changes: 1 addition & 1 deletion src/tag/__test__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ describe('tag', () => {

if (!VIRTUAL_HOST) {
const $click = comp.querySelector('.base >>> .t-tag');
const $close = comp.querySelector('.base >>> .t-tag__icon-close');
const $close = comp.querySelector('.base >>> .t-icon');

// 禁用态:event 不会触发
$click.dispatchEvent('tap');
Expand Down
2 changes: 1 addition & 1 deletion src/tag/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { TdTagProps } from './type';
const props: TdTagProps = {
/** 标签是否可关闭 */
closable: {
type: Boolean,
type: null,
value: false,
},
/** 标签禁用态,失效标签不能触发事件。默认风格(theme=default)才有禁用态 */
Expand Down
6 changes: 6 additions & 0 deletions src/tag/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export default class Tag extends SuperComponent {
_icon: calcIcon(v),
});
},

closable(v) {
this.setData({
_closable: calcIcon(v, 'close'),
});
},
};

methods = {
Expand Down
12 changes: 5 additions & 7 deletions src/tag/tag.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
<view class="{{classPrefix}}__text">
<slot />
</view>
<t-icon
wx:if="{{ closable }}"
class="{{classPrefix}}__icon-close"
t-class="{{prefix}}-icon"
<template
wx:if="{{_closable}}"
is="icon"
data="{{class: classPrefix + '__icon-close', tClass: prefix + '-icon', bindclick: 'handleClose', ariaRole: 'button', ariaLabel: '关闭', ..._closable }}"
catch:tap="handleClose"
name="close"
aria-role="button"
aria-label="关闭"
/>
<slot wx:else name="closable" />
</view>
4 changes: 2 additions & 2 deletions src/tag/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export interface TdTagProps {
* @default false
*/
closable?: {
type: BooleanConstructor;
value?: boolean;
type: null;
value?: boolean | object;
};
/**
* 自定义组件样式
Expand Down

0 comments on commit 040aeb0

Please sign in to comment.