diff --git a/src/address-list/Item.tsx b/src/address-list/Item.tsx index 8aa233297..743be2543 100644 --- a/src/address-list/Item.tsx +++ b/src/address-list/Item.tsx @@ -29,6 +29,7 @@ export type AddressItemProps = { export type AddressItemSlots = DefaultSlots & { bottom?: ScopedSlot; + tag?: ScopedSlot; }; export type AddressItemEvents = { @@ -68,6 +69,9 @@ function AddressItem( ); function genTag() { + if (slots.tag) { + return slots.tag({ ...props.data }); + } if (props.data.isDefault && props.defaultTagText) { return ( diff --git a/src/address-list/README.md b/src/address-list/README.md index 81abb90b6..e8459db45 100644 --- a/src/address-list/README.md +++ b/src/address-list/README.md @@ -105,11 +105,12 @@ export default { ### Slots -| Name | Description | SlotProps | -| -------------------- | ------------------------------ | --------- | -| default | Custom content after list | - | -| top | Custom content before list | - | -| item-bottom `v2.5.0` | Custom content after list item | item | +| Name | Description | SlotProps | +| -------------------- | --------------------------------- | --------- | +| default | Custom content after list | - | +| top | Custom content before list | - | +| item-bottom `v2.5.0` | Custom content after list item | item | +| tag | Custom tag conetent for list item | item | ### Less Variables diff --git a/src/address-list/README.zh-CN.md b/src/address-list/README.zh-CN.md index 5ce0fc715..06d1c9482 100644 --- a/src/address-list/README.zh-CN.md +++ b/src/address-list/README.zh-CN.md @@ -114,6 +114,7 @@ export default { | default | 在列表下方插入内容 | - | | top | 在顶部插入内容 | - | | item-bottom `v2.5.0` | 在列表项底部插入内容 | 列表项的值 | +| tag | 列表项标签内容自定义 | 列表项的值 | ### 样式变量 diff --git a/src/address-list/index.tsx b/src/address-list/index.tsx index 1726e0508..6b9b13da2 100644 --- a/src/address-list/index.tsx +++ b/src/address-list/index.tsx @@ -24,6 +24,7 @@ export type AddressListProps = { export type AddressListSlots = DefaultSlots & { top?: ScopedSlot; 'item-bottom'?: ScopedSlot; + tag?: ScopedSlot; }; const [createComponent, bem, t] = createNamespace('address-list'); @@ -48,6 +49,7 @@ function AddressList( defaultTagText={props.defaultTagText} scopedSlots={{ bottom: slots['item-bottom'], + tag: slots.tag, }} onSelect={() => { emit(ctx, disabled ? 'select-disabled' : 'select', item, index); diff --git a/src/address-list/test/__snapshots__/index.spec.js.snap b/src/address-list/test/__snapshots__/index.spec.js.snap index 4b8ac0806..1db3fb075 100644 --- a/src/address-list/test/__snapshots__/index.spec.js.snap +++ b/src/address-list/test/__snapshots__/index.spec.js.snap @@ -1,5 +1,14 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`should render tag slot correctly 1`] = ` +
+
+
+
+`; + exports[`unswitchable 1`] = `
diff --git a/src/address-list/test/index.spec.js b/src/address-list/test/index.spec.js index bd651cee6..24a2aac16 100644 --- a/src/address-list/test/index.spec.js +++ b/src/address-list/test/index.spec.js @@ -62,3 +62,12 @@ test('click-item event', () => { expect(onClickItem).toHaveBeenCalledTimes(1); }); + +test('should render tag slot correctly', () => { + const wrapper = mount(AddressList, { + scopedSlots: { + tag: () => 'Custom Tag', + }, + }); + expect(wrapper.html()).toMatchSnapshot(); +});