From 6974367b0342733d9e3786f21a1eea6304b26e8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=98=89=E6=B6=B5?= Date: Mon, 27 May 2019 14:59:58 +0800 Subject: [PATCH] [new feature] Search: add right-icon slot --- docs/markdown/changelog.zh-CN.md | 6 ++++++ packages/search/en-US.md | 3 ++- packages/search/index.tsx | 6 +++++- .../search/test/__snapshots__/index.spec.js.snap | 16 ++++++++++++++++ packages/search/test/index.spec.js | 13 +++++++++++++ packages/search/zh-CN.md | 5 +++-- 6 files changed, 45 insertions(+), 4 deletions(-) diff --git a/docs/markdown/changelog.zh-CN.md b/docs/markdown/changelog.zh-CN.md index 3484f2efc..a4f837b98 100644 --- a/docs/markdown/changelog.zh-CN.md +++ b/docs/markdown/changelog.zh-CN.md @@ -24,6 +24,12 @@ - 新增`close-on-popstate`属性 +##### Search + +- 新增`left-icon`属性 +- 新增`right-icon`属性 +- 新增`right-icon`插槽 + ### [v2.0.0-beta.1](https://github.com/youzan/vant/tree/v2.0.0-beta.1) diff --git a/packages/search/en-US.md b/packages/search/en-US.md index 5b344083a..af1e5b14d 100644 --- a/packages/search/en-US.md +++ b/packages/search/en-US.md @@ -92,6 +92,7 @@ Search support all native events of input tag,such as `focus`、`blur`、`keyp | Name | Description | |------|------| +| label | Custom Search label | | action | Custom right button, displayed when `showAction` is true | | left-icon | Custom left icon | -| label | Custom Search label | +| right-icon | Custom right icon | diff --git a/packages/search/index.tsx b/packages/search/index.tsx index c3e5ecade..76c8d8c1b 100644 --- a/packages/search/index.tsx +++ b/packages/search/index.tsx @@ -23,6 +23,7 @@ export type SearchSlots = DefaultSlots & { label?: ScopedSlot; action?: ScopedSlot; 'left-icon'?: ScopedSlot; + 'right-icon'?: ScopedSlot; }; export type SearchEvents = { @@ -97,7 +98,10 @@ function Search( value={props.value} leftIcon={props.leftIcon} rightIcon={props.rightIcon} - scopedSlots={{ 'left-icon': slots['left-icon'] }} + scopedSlots={{ + 'left-icon': slots['left-icon'], + 'right-icon': slots['right-icon'] + }} {...fieldData} /> diff --git a/packages/search/test/__snapshots__/index.spec.js.snap b/packages/search/test/__snapshots__/index.spec.js.snap index b16bd0585..939d3934e 100644 --- a/packages/search/test/__snapshots__/index.spec.js.snap +++ b/packages/search/test/__snapshots__/index.spec.js.snap @@ -45,3 +45,19 @@ exports[`right-icon prop 1`] = ` `; + +exports[`right-icon slot 1`] = ` + +`; diff --git a/packages/search/test/index.spec.js b/packages/search/test/index.spec.js index 0b3a35025..3d8e5e5df 100644 --- a/packages/search/test/index.spec.js +++ b/packages/search/test/index.spec.js @@ -1,3 +1,4 @@ +/* eslint-disable object-shorthand */ import Search from '..'; import { mount } from '../../../test/utils'; @@ -94,3 +95,15 @@ test('right-icon prop', () => { expect(wrapper).toMatchSnapshot(); }); + +test('right-icon slot', () => { + const wrapper = mount(Search, { + scopedSlots: { + 'right-icon'() { + return 'Custom Right Icon'; + } + } + }); + + expect(wrapper).toMatchSnapshot(); +}); diff --git a/packages/search/zh-CN.md b/packages/search/zh-CN.md index aff7f933a..d203918dd 100644 --- a/packages/search/zh-CN.md +++ b/packages/search/zh-CN.md @@ -85,6 +85,7 @@ Search 默认支持 Input 标签所有的原生事件,如 `focus`、`blur`、` | 名称 | 说明 | |------|------| -| action | 自定义搜索框右侧按钮,需要在`showAction`为 true 时才会显示 | -| left-icon | 自定义输入框头部图标 | | label | 自定义搜索框左侧文本 | +| action | 自定义搜索框右侧按钮,需要在`showAction`为 true 时才会显示 | +| left-icon | 自定义输入框左侧图标 | +| right-icon | 自定义输入框右侧图标 |