From 01519773f5ebbf901f58e4fc161bf8f4f865a2c0 Mon Sep 17 00:00:00 2001 From: byqbai Date: Wed, 27 Dec 2023 10:53:10 +0800 Subject: [PATCH 1/7] =?UTF-8?q?feat(search):=20=E6=96=B0=E5=A2=9E=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=AE=8C=E6=88=90=E9=A1=B9=E9=A2=84=E8=A7=88=E5=88=97?= =?UTF-8?q?=E8=A1=A8.=20(#2432)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #2432 --- .../__test__/__snapshots__/index.test.js.snap | 4 ++-- .../__test__/__snapshots__/demo.test.js.snap | 10 +++++++++- .../__test__/__snapshots__/index.test.js.snap | 3 +++ src/search/_example/base/index.js | 14 ++++++++++++++ src/search/_example/base/index.wxml | 6 +++++- src/search/_example/base/index.wxss | 4 ++++ src/search/props.ts | 5 +++++ src/search/search.less | 19 +++++++++++++++++++ src/search/search.ts | 11 +++++++++++ src/search/search.wxml | 9 +++++++++ src/search/type.ts | 4 ++++ 11 files changed, 85 insertions(+), 4 deletions(-) diff --git a/src/dropdown-menu/__test__/__snapshots__/index.test.js.snap b/src/dropdown-menu/__test__/__snapshots__/index.test.js.snap index ec94925df..166658e43 100644 --- a/src/dropdown-menu/__test__/__snapshots__/index.test.js.snap +++ b/src/dropdown-menu/__test__/__snapshots__/index.test.js.snap @@ -91,7 +91,7 @@ exports[`dropdown-menu :base 1`] = ` bind:visible-change="handleMaskClick" > @@ -626,7 +626,7 @@ exports[`dropdown-menu :base 1`] = ` + + + diff --git a/src/search/__test__/__snapshots__/index.test.js.snap b/src/search/__test__/__snapshots__/index.test.js.snap index 01d0fd3cc..110cde4eb 100644 --- a/src/search/__test__/__snapshots__/index.test.js.snap +++ b/src/search/__test__/__snapshots__/index.test.js.snap @@ -64,6 +64,9 @@ exports[`search Props :base 1`] = ` + `; diff --git a/src/search/_example/base/index.js b/src/search/_example/base/index.js index d6ebd8e2d..621e91131 100644 --- a/src/search/_example/base/index.js +++ b/src/search/_example/base/index.js @@ -1,5 +1,19 @@ Component({ data: { value: '', + resultList: [], + }, + methods: { + onChangeValue(e) { + const { value } = e.detail; + + this.setData({ + resultList: value + ? Array.from({ length: 3 }).map((v, i) => { + return `预览结果:${i}`; + }) + : [], + }); + }, }, }); diff --git a/src/search/_example/base/index.wxml b/src/search/_example/base/index.wxml index 5ec180077..e3e61c42c 100644 --- a/src/search/_example/base/index.wxml +++ b/src/search/_example/base/index.wxml @@ -1,3 +1,7 @@ - + + + + + diff --git a/src/search/_example/base/index.wxss b/src/search/_example/base/index.wxss index a5f17d78a..408ab45a6 100644 --- a/src/search/_example/base/index.wxss +++ b/src/search/_example/base/index.wxss @@ -2,3 +2,7 @@ background-color: #fff; padding: 16rpx 32rpx; } + +.example-search:not(:last-child) { + margin-bottom: 32rpx; +} \ No newline at end of file diff --git a/src/search/props.ts b/src/search/props.ts index 436ba7e7c..4202767bb 100644 --- a/src/search/props.ts +++ b/src/search/props.ts @@ -6,6 +6,11 @@ import { TdSearchProps } from './type'; const props: TdSearchProps = { + /** 预览结果列表 */ + resultList: { + type: Array, + value: [], + }, /** 自定义右侧操作按钮文字 */ action: { type: String, diff --git a/src/search/search.less b/src/search/search.less index 2e2fb01b3..dea119fd7 100644 --- a/src/search/search.less +++ b/src/search/search.less @@ -84,4 +84,23 @@ text-align: center; } } + &__result-item { + padding: 30rpx; + position: relative; + display: flex; + align-items: center; + font-size: 34rpx; + color: rgba(0, 0, 0, 0.55); + position: relative; + &:not(:last-child)::after { + content: ''; + position: absolute; + left: 0; + bottom: 0; + right: 0; + height: 1rpx; + z-index: 2; + background-color: rgba(0, 0, 0, 0.1); + } + } } diff --git a/src/search/search.ts b/src/search/search.ts index 87bebfb11..11e3df38a 100644 --- a/src/search/search.ts +++ b/src/search/search.ts @@ -59,6 +59,7 @@ export default class Search extends SuperComponent { handleClear() { this.setData({ value: '' }); this.triggerEvent('clear', { value: '' }); + this.triggerEvent('change', { value: '' }); } onConfirm(e) { @@ -69,4 +70,14 @@ export default class Search extends SuperComponent { onActionClick() { this.triggerEvent('action-click'); } + + selectResultItem(e) { + const { index } = e.currentTarget.dataset + const item = this.properties.resultList[index] + this.setData({ + value: item + }) + this.triggerEvent('change', { value: item }); + this.triggerEvent('selectresult', { index, item }) + } } diff --git a/src/search/search.wxml b/src/search/search.wxml index 667d0d771..593e62592 100644 --- a/src/search/search.wxml +++ b/src/search/search.wxml @@ -59,3 +59,12 @@ + + {{item}} + diff --git a/src/search/type.ts b/src/search/type.ts index 0ce847c52..b3ebad779 100644 --- a/src/search/type.ts +++ b/src/search/type.ts @@ -5,6 +5,10 @@ * */ export interface TdSearchProps { + resultList: { + type: ArrayConstructor; + value?: []; + }; /** * 自定义组件样式 * @default '' From 4b0ed5f6c2b9d318ac72096126ed1f4d752edfbe Mon Sep 17 00:00:00 2001 From: byqbai Date: Wed, 27 Dec 2023 11:42:50 +0800 Subject: [PATCH 2/7] =?UTF-8?q?fix(search):=20=E6=9B=B4=E6=96=B0=E5=BF=AB?= =?UTF-8?q?=E7=85=A7.=20(#2432)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #2432 --- src/fab/__test__/__snapshots__/demo.test.js.snap | 13 +++++++++++++ src/fab/__test__/demo.test.js | 2 +- src/input/__test__/demo.test.js | 16 +--------------- src/rate/__test__/demo.test.js | 13 +------------ .../__test__/__snapshots__/index.test.js.snap | 1 + 5 files changed, 17 insertions(+), 28 deletions(-) diff --git a/src/fab/__test__/__snapshots__/demo.test.js.snap b/src/fab/__test__/__snapshots__/demo.test.js.snap index c4b571c5b..1e5194378 100644 --- a/src/fab/__test__/__snapshots__/demo.test.js.snap +++ b/src/fab/__test__/__snapshots__/demo.test.js.snap @@ -25,3 +25,16 @@ exports[`Fab Fab base demo works fine 1`] = ` /> `; + +exports[`Fab Fab draggable demo works fine 1`] = ` + + + +`; diff --git a/src/fab/__test__/demo.test.js b/src/fab/__test__/demo.test.js index 22966d52a..a2634c421 100644 --- a/src/fab/__test__/demo.test.js +++ b/src/fab/__test__/demo.test.js @@ -5,7 +5,7 @@ import path from 'path'; import simulate from 'miniprogram-simulate'; -const mapper = ['advance', 'base']; +const mapper = ['advance', 'base', 'draggable']; describe('Fab', () => { mapper.forEach((demoName) => { diff --git a/src/input/__test__/demo.test.js b/src/input/__test__/demo.test.js index 603f344e8..cdffa0aab 100644 --- a/src/input/__test__/demo.test.js +++ b/src/input/__test__/demo.test.js @@ -5,21 +5,7 @@ import path from 'path'; import simulate from 'miniprogram-simulate'; -const mapper = [ - 'align', - 'banner', - 'base', - 'bordered', - 'custom', - 'label', - 'layout', - 'maxlength', - 'prefix', - 'size', - 'special', - 'status', - 'suffix', -]; +const mapper = ['align', 'banner', 'base', 'bordered', 'custom', 'label', 'layout', 'maxlength', 'prefix', 'size', 'special', 'status', 'suffix']; describe('Input', () => { mapper.forEach((demoName) => { diff --git a/src/rate/__test__/demo.test.js b/src/rate/__test__/demo.test.js index 4d10e7c23..fe7849981 100644 --- a/src/rate/__test__/demo.test.js +++ b/src/rate/__test__/demo.test.js @@ -5,18 +5,7 @@ import path from 'path'; import simulate from 'miniprogram-simulate'; -const mapper = [ - 'action', - 'base', - 'color', - 'count', - 'custom', - 'custom-prefix', - 'show-text', - 'size', - 'special', - 'un-filled', -]; +const mapper = ['action', 'base', 'color', 'count', 'custom', 'custom-prefix', 'show-text', 'size', 'special', 'un-filled']; describe('Rate', () => { mapper.forEach((demoName) => { diff --git a/src/search/__test__/__snapshots__/index.test.js.snap b/src/search/__test__/__snapshots__/index.test.js.snap index 110cde4eb..9371575aa 100644 --- a/src/search/__test__/__snapshots__/index.test.js.snap +++ b/src/search/__test__/__snapshots__/index.test.js.snap @@ -65,6 +65,7 @@ exports[`search Props :base 1`] = ` From f3938efb21464bfad02e2a731d5e1a7c48c88b1f Mon Sep 17 00:00:00 2001 From: anlyyao Date: Wed, 27 Dec 2023 14:49:20 +0800 Subject: [PATCH 3/7] test: update snapshots --- src/dropdown-menu/__test__/__snapshots__/index.test.js.snap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dropdown-menu/__test__/__snapshots__/index.test.js.snap b/src/dropdown-menu/__test__/__snapshots__/index.test.js.snap index 166658e43..ec94925df 100644 --- a/src/dropdown-menu/__test__/__snapshots__/index.test.js.snap +++ b/src/dropdown-menu/__test__/__snapshots__/index.test.js.snap @@ -91,7 +91,7 @@ exports[`dropdown-menu :base 1`] = ` bind:visible-change="handleMaskClick" > @@ -626,7 +626,7 @@ exports[`dropdown-menu :base 1`] = ` Date: Tue, 18 Jun 2024 15:34:25 +0800 Subject: [PATCH 4/7] =?UTF-8?q?fix(search):=20=E9=A2=84=E8=A7=88=E6=95=88?= =?UTF-8?q?=E6=9E=9C=E4=BC=98=E5=8C=96.=20(#2432)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/search/_example/base/index.js | 15 ++++++---- src/search/search.json | 3 +- src/search/search.less | 18 ++---------- src/search/search.ts | 47 ++++++++++++++++++++++++------- src/search/search.wxml | 15 ++++++---- src/search/search.wxs | 6 ++++ src/search/type.ts | 4 +++ 7 files changed, 70 insertions(+), 38 deletions(-) create mode 100644 src/search/search.wxs diff --git a/src/search/_example/base/index.js b/src/search/_example/base/index.js index 621e91131..3e47aac0f 100644 --- a/src/search/_example/base/index.js +++ b/src/search/_example/base/index.js @@ -6,13 +6,16 @@ Component({ methods: { onChangeValue(e) { const { value } = e.detail; - + const list = [ + 'tdesign-vue', + 'tdesign-react', + 'tdesign-miniprogram', + 'tdesign-angular', + 'tdesign-mobile-vue', + 'tdesign-mobile-react', + ]; this.setData({ - resultList: value - ? Array.from({ length: 3 }).map((v, i) => { - return `预览结果:${i}`; - }) - : [], + resultList: value ? list.filter((v) => v.includes(value)) : [], }); }, }, diff --git a/src/search/search.json b/src/search/search.json index 049940c16..5a7c1a361 100644 --- a/src/search/search.json +++ b/src/search/search.json @@ -1,6 +1,7 @@ { "component": true, "usingComponents": { - "t-icon": "../icon/icon" + "t-icon": "../icon/icon", + "t-cell": "../cell/cell" } } diff --git a/src/search/search.less b/src/search/search.less index dea119fd7..4de5fc08f 100644 --- a/src/search/search.less +++ b/src/search/search.less @@ -85,22 +85,8 @@ } } &__result-item { - padding: 30rpx; - position: relative; - display: flex; - align-items: center; - font-size: 34rpx; - color: rgba(0, 0, 0, 0.55); - position: relative; - &:not(:last-child)::after { - content: ''; - position: absolute; - left: 0; - bottom: 0; - right: 0; - height: 1rpx; - z-index: 2; - background-color: rgba(0, 0, 0, 0.1); + &--hightlight { + color: @brand-color; } } } diff --git a/src/search/search.ts b/src/search/search.ts index 11e3df38a..fe82fca93 100644 --- a/src/search/search.ts +++ b/src/search/search.ts @@ -23,24 +23,49 @@ export default class Search extends SuperComponent { properties = props; - observers = {}; + observers = { + resultList(val) { + const { isSelected } = this.data; + if (val.length) { + if (isSelected) { + // 已选择 + this.setData({ + isShowResultList: false, + isSelected: false, + }); + } else { + this.setData({ + isShowResultList: true, + }); + } + } else { + this.setData({ + isShowResultList: false, + }); + } + }, + }; data = { classPrefix: name, prefix, + isShowResultList: false, + isSelected: false, }; onInput(e) { let { value } = e.detail; const { maxcharacter } = this.properties; - if (maxcharacter && typeof maxcharacter === 'number' && maxcharacter > 0) { const { characters } = getCharacterLength('maxcharacter', value, maxcharacter); value = characters; } - this.setData({ value }); + this.setData({ + value, + }); + this.triggerEvent('change', { value }); } @@ -70,14 +95,16 @@ export default class Search extends SuperComponent { onActionClick() { this.triggerEvent('action-click'); } - - selectResultItem(e) { - const { index } = e.currentTarget.dataset - const item = this.properties.resultList[index] + + onSelectResultItem(e) { + const { index } = e.currentTarget.dataset; + const item = this.properties.resultList[index]; this.setData({ - value: item - }) + value: item, + isSelected: true, + }); + this.triggerEvent('change', { value: item }); - this.triggerEvent('selectresult', { index, item }) + this.triggerEvent('selectresult', { index, item }); } } diff --git a/src/search/search.wxml b/src/search/search.wxml index 593e62592..99ebb886a 100644 --- a/src/search/search.wxml +++ b/src/search/search.wxml @@ -59,12 +59,17 @@ - - + + {{item}} + hover + bind:tap="onSelectResultItem" + aria-role="option" + > + + diff --git a/src/search/search.wxs b/src/search/search.wxs new file mode 100644 index 000000000..ebb8266ee --- /dev/null +++ b/src/search/search.wxs @@ -0,0 +1,6 @@ +var hightLight = function (label, keyword) { + return label.replace(keyword, '' + keyword + ''); +}; +module.exports = { + hightLight: hightLight, +}; diff --git a/src/search/type.ts b/src/search/type.ts index b3ebad779..884290c0e 100644 --- a/src/search/type.ts +++ b/src/search/type.ts @@ -5,6 +5,10 @@ * */ export interface TdSearchProps { + /** + * 预览结果列表 + * @default [] + */ resultList: { type: ArrayConstructor; value?: []; From 2375323a650c485ef448cf6f7c348fb06293d9fe Mon Sep 17 00:00:00 2001 From: anlyyao Date: Thu, 27 Jun 2024 19:26:10 +0800 Subject: [PATCH 5/7] fix: fix cr --- src/search/README.md | 2 ++ src/search/__test__/__snapshots__/demo.test.js.snap | 2 +- .../__test__/__snapshots__/index.test.js.snap | 4 ---- src/search/_example/base/index.wxml | 2 +- src/search/search.less | 13 +++++++++++-- src/search/search.wxml | 5 +++-- src/search/search.wxs | 6 +++--- 7 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/search/README.md b/src/search/README.md index 2bdb4fa9a..1899966e3 100644 --- a/src/search/README.md +++ b/src/search/README.md @@ -57,6 +57,7 @@ confirm-type | String | search | 设置键盘右下角按钮的文字,仅在ty always-embed | Boolean | false | 强制 input 处于同层状态,默认 focus 时 input 会切到非同层状态 (仅在 iOS 下生效) | N confirm-hold | Boolean | false | 点击键盘右下角按钮时是否保持键盘不收起 | N cursor | Number | - | 必需。指定 focus 时的光标位置 | Y +result-list | Array | [] | 预览结果列表 | N selection-start | Number | -1 | 光标起始位置,自动聚集时有效,需与 selection-end 搭配使用 | N selection-end | Number | -1 | 光标结束位置,自动聚集时有效,需与 selection-start 搭配使用 | N adjust-position | Boolean | true | 键盘弹起时,是否自动上推页面 | N @@ -105,5 +106,6 @@ t-class-clear | 右侧图标样式类 --td-search-label-color | @font-gray-1 | - --td-search-padding | 16rpx 24rpx | - --td-search-placeholder-color | @font-gray-3 | - +--td-search-result-high-light-color | @brand-color | - --td-search-square-radius | @radius-default | - --td-search-text-color | @font-gray-1 | - diff --git a/src/search/__test__/__snapshots__/demo.test.js.snap b/src/search/__test__/__snapshots__/demo.test.js.snap index 26595e5fe..6d165ba4c 100644 --- a/src/search/__test__/__snapshots__/demo.test.js.snap +++ b/src/search/__test__/__snapshots__/demo.test.js.snap @@ -32,7 +32,7 @@ exports[`Search Search base demo works fine 1`] = ` class="example-search" > diff --git a/src/search/__test__/__snapshots__/index.test.js.snap b/src/search/__test__/__snapshots__/index.test.js.snap index 9371575aa..01d0fd3cc 100644 --- a/src/search/__test__/__snapshots__/index.test.js.snap +++ b/src/search/__test__/__snapshots__/index.test.js.snap @@ -64,10 +64,6 @@ exports[`search Props :base 1`] = ` - `; diff --git a/src/search/_example/base/index.wxml b/src/search/_example/base/index.wxml index e3e61c42c..6c1ae2827 100644 --- a/src/search/_example/base/index.wxml +++ b/src/search/_example/base/index.wxml @@ -3,5 +3,5 @@ - + diff --git a/src/search/search.less b/src/search/search.less index 2840677ae..cd2c0bcd9 100644 --- a/src/search/search.less +++ b/src/search/search.less @@ -12,6 +12,7 @@ @search-round-radius: calc(@search-height / 2); @search-action-color: var(--td-search-action-color, @brand-color); @search-clear-icon-color: var(--td-search-clear-icon-color, @text-color-placeholder); +@search-result-high-light-color: var(--td-search-result-high-light-color, @brand-color); .@{prefix}-search { display: flex; @@ -85,8 +86,16 @@ } } &__result-item { - &--hightlight { - color: @brand-color; + &--highLight { + color: @search-result-high-light-color; + } + } + + &__result-list &__result-item { + padding-left: 0; + + &::after { + left: 0; } } } diff --git a/src/search/search.wxml b/src/search/search.wxml index bb9ad6cca..7d393e77c 100644 --- a/src/search/search.wxml +++ b/src/search/search.wxml @@ -1,4 +1,5 @@ + - + - + diff --git a/src/search/search.wxs b/src/search/search.wxs index ebb8266ee..ac86989cc 100644 --- a/src/search/search.wxs +++ b/src/search/search.wxs @@ -1,6 +1,6 @@ -var hightLight = function (label, keyword) { - return label.replace(keyword, '' + keyword + ''); +var highLight = function (label, keyword) { + return label.replace(keyword, '' + keyword + ''); }; module.exports = { - hightLight: hightLight, + highLight: highLight, }; From c025cc5cd7c3ccaddac1ef39fce935c3e49e02e4 Mon Sep 17 00:00:00 2001 From: anlyyao Date: Mon, 1 Jul 2024 15:31:35 +0800 Subject: [PATCH 6/7] chore: update api docs --- src/search/README.en-US.md | 58 +++++++++++- src/search/README.md | 56 ++++++------ src/search/props.ts | 141 ++++++++++++++--------------- src/search/type.ts | 179 ++++++++++++++++--------------------- 4 files changed, 231 insertions(+), 203 deletions(-) diff --git a/src/search/README.en-US.md b/src/search/README.en-US.md index 4517dc836..26d0ba14d 100644 --- a/src/search/README.en-US.md +++ b/src/search/README.en-US.md @@ -1,6 +1,62 @@ +## API + +### Search Props + +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 +action | String / Slot | '' | [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N +adjust-position | Boolean | true | \- | N +always-embed | Boolean | false | \- | N +center | Boolean | false | \- | N +clearable | Boolean | true | \- | N +confirm-hold | Boolean | false | \- | N +confirm-type | String | search | options: send/search/next/go/done | N +cursor | Number | - | required | Y +cursor-spacing | Number | 0 | \- | N +disabled | Boolean | false | \- | N +focus | Boolean | false | \- | N +hold-keyboard | Boolean | false | \- | N +label | String | '' | `deprecated` | N +left-icon | String / Slot | 'search' | [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N +maxcharacter | Number | - | \- | N +maxlength | Number | -1 | \- | N +placeholder | String | '' | \- | N +placeholder-class | String | input-placeholder | \- | N +placeholder-style | String | - | required | Y +result-list | Array | [] | Typescript:`Array` | N +right-icon | String / Slot | 'close-circle-filled' | `deprecated`。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N +selection-end | Number | -1 | \- | N +selection-start | Number | -1 | \- | N +shape | String | 'square' | options: square/round | N +type | String | 'text' | options: text/number/idcard/digit/nickname | N +value | String | '' | \- | N + +### Search Events + +name | params | description +-- | -- | -- +action-click | `({})` | \- +blur | `({ value: string })` | \- +change | `({ value: string })` | \- +clear | `({ value: string })` | \- +focus | `({ value: string })` | \- +submit | `({ value: string })` | \- +### Search External Classes + +className | Description +-- | -- +t-class | \- +t-class-action | \- +t-class-clear | \- +t-class-input | \- +t-class-input-container | \- +t-class-left | \- ### CSS Variables + The component provides the following CSS variables, which can be used to customize styles. Name | Default Value | Description -- | -- | -- @@ -14,4 +70,4 @@ Name | Default Value | Description --td-search-padding | 16rpx 24rpx | - --td-search-placeholder-color | @font-gray-3 | - --td-search-square-radius | @radius-default | - ---td-search-text-color | @font-gray-1 | - +--td-search-text-color | @font-gray-1 | - \ No newline at end of file diff --git a/src/search/README.md b/src/search/README.md index 1899966e3..945a641e3 100644 --- a/src/search/README.md +++ b/src/search/README.md @@ -41,36 +41,39 @@ isComponent: true {{ other }} ## API + ### Search Props -名称 | 类型 | 默认值 | 说明 | 必传 +名称 | 类型 | 默认值 | 描述 | 必传 -- | -- | -- | -- | -- -action | String / Slot | '' | 自定义右侧操作按钮文字 | N +style | Object | - | 样式 | N +custom-style | Object | - | 样式,一般用于开启虚拟化组件节点场景 | N +action | String / Slot | '' | 自定义右侧操作按钮文字。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N +adjust-position | Boolean | true | 键盘弹起时,是否自动上推页面 | N +always-embed | Boolean | false | 强制 input 处于同层状态,默认 focus 时 input 会切到非同层状态 (仅在 iOS 下生效) | N center | Boolean | false | 是否居中 | N -disabled | Boolean | false | 是否禁用 | N +clearable | Boolean | true | 是否启用清除控件 | N +confirm-hold | Boolean | false | 点击键盘右下角按钮时是否保持键盘不收起 | N +confirm-type | String | search | 设置键盘右下角按钮的文字,仅在type='text'时生效。
具体释义:
`send` 右下角按钮为“发送”;
`search` 右下角按钮为“搜索”;
`next` 右下角按钮为“下一个”;
`go` 右下角按钮为“前往”;
`done` 右下角按钮为“完成”。
[小程序官方文档](https://developers.weixin.qq.com/miniprogram/dev/component/input.html)。可选项:send/search/next/go/done | N +cursor | Number | - | 必需。指定 focus 时的光标位置 | Y cursor-spacing | Number | 0 | 搜索框聚焦时底部与键盘的距离 | N +disabled | Boolean | false | 是否禁用 | N focus | Boolean | false | 是否聚焦 | N +hold-keyboard | Boolean | false | focus时,点击页面的时候不收起键盘 | N label | String | '' | 已废弃。左侧文本 | N +left-icon | String / Slot | 'search' | 左侧图标。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N maxcharacter | Number | - | 用户最多可以输入的字符个数,一个中文汉字表示两个字符长度。`maxcharacter` 和 `maxlength` 二选一使用 | N maxlength | Number | -1 | 用户最多可以输入的文本长度,一个中文等于一个计数长度。默认为 -1,不限制输入长度。`maxcharacter` 和 `maxlength` 二选一使用 | N -confirm-type | String | search | 设置键盘右下角按钮的文字,仅在type='text'时生效。
具体释义:
`send` 右下角按钮为“发送”;
`search` 右下角按钮为“搜索”;
`next` 右下角按钮为“下一个”;
`go` 右下角按钮为“前往”;
`done` 右下角按钮为“完成”。
[小程序官方文档](https://developers.weixin.qq.com/miniprogram/dev/component/input.html)。可选项:send/search/next/go/done | N -always-embed | Boolean | false | 强制 input 处于同层状态,默认 focus 时 input 会切到非同层状态 (仅在 iOS 下生效) | N -confirm-hold | Boolean | false | 点击键盘右下角按钮时是否保持键盘不收起 | N -cursor | Number | - | 必需。指定 focus 时的光标位置 | Y -result-list | Array | [] | 预览结果列表 | N -selection-start | Number | -1 | 光标起始位置,自动聚集时有效,需与 selection-end 搭配使用 | N -selection-end | Number | -1 | 光标结束位置,自动聚集时有效,需与 selection-start 搭配使用 | N -adjust-position | Boolean | true | 键盘弹起时,是否自动上推页面 | N -hold-keyboard | Boolean | false | focus时,点击页面的时候不收起键盘 | N -placeholder-style | String | - | 必需。指定 placeholder 的样式 | Y -placeholder-class | String | input-placeholder | 指定 placeholder 的样式类 | N -left-icon | String / Slot | 'search' | 左侧图标 | N placeholder | String | '' | 占位符 | N -right-icon | String / Slot | 'close-circle-filled' | 已废弃。右侧图标 | N -clearable | Boolean | true | 是否启用清除控件 | N +placeholder-class | String | input-placeholder | 指定 placeholder 的样式类 | N +placeholder-style | String | - | 必需。指定 placeholder 的样式 | Y +result-list | Array | [] | 预览结果列表。TS 类型:`Array` | N +right-icon | String / Slot | 'close-circle-filled' | 已废弃。右侧图标。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N +selection-end | Number | -1 | 光标结束位置,自动聚集时有效,需与 selection-start 搭配使用 | N +selection-start | Number | -1 | 光标起始位置,自动聚集时有效,需与 selection-end 搭配使用 | N shape | String | 'square' | 搜索框形状。可选项:square/round | N +type | String | 'text' | 拉起键盘的类型。可选项:text/number/idcard/digit/nickname | N value | String | '' | 值 | N -type | String | 'text' | 拉起键盘的类型,可选项:text/number/idcard/digit/nickname | N ### Search Events @@ -82,18 +85,19 @@ change | `({ value: string })` | 值发生变化时触发 clear | `({ value: string })` | 点击清除时触发 focus | `({ value: string })` | 聚焦时触发 submit | `({ value: string })` | 提交时触发 +### Search External Classes -### Search 外部样式类 -类名 | 说明 --- | -- +类名 | 描述 +-- | -- t-class | 根节点样式类 -t-class-input-container | 输入框容器样式类 -t-class-input | 输入框样式类 t-class-action | 操作按钮样式类 -t-class-left | 左侧图标样式类 t-class-clear | 右侧图标样式类 +t-class-input | 输入框样式类 +t-class-input-container | 输入框容器样式类 +t-class-left | 左侧图标样式类 + +### CSS Variables -### CSS 变量 组件提供了下列 CSS 变量,可用于自定义样式。 名称 | 默认值 | 描述 -- | -- | -- @@ -108,4 +112,4 @@ t-class-clear | 右侧图标样式类 --td-search-placeholder-color | @font-gray-3 | - --td-search-result-high-light-color | @brand-color | - --td-search-square-radius | @radius-default | - ---td-search-text-color | @font-gray-1 | - +--td-search-text-color | @font-gray-1 | - \ No newline at end of file diff --git a/src/search/props.ts b/src/search/props.ts index 4202767bb..31721df6c 100644 --- a/src/search/props.ts +++ b/src/search/props.ts @@ -6,138 +6,129 @@ import { TdSearchProps } from './type'; const props: TdSearchProps = { - /** 预览结果列表 */ - resultList: { - type: Array, - value: [], - }, /** 自定义右侧操作按钮文字 */ action: { type: String, value: '', }, - /** 是否居中 */ - center: { + /** 键盘弹起时,是否自动上推页面 */ + adjustPosition: { type: Boolean, - value: false, + value: true, }, - /** 是否禁用 */ - disabled: { + /** 强制 input 处于同层状态,默认 focus 时 input 会切到非同层状态 (仅在 iOS 下生效) */ + alwaysEmbed: { type: Boolean, value: false, }, - /** 组件外部样式类名,分别用于设置组件外层类名、输入框类名、输入框容器类名、右侧 cancel 文本类名、左侧图标类名、右侧图标类型 */ - externalClasses: { - type: Array, - }, - /** 指定光标与键盘的距离,取 input 距离底部的距离和 cursor-spacing 指定的距离的最小值作为光标与键盘的距离 */ - cursorSpacing: { - type: Number, - value: 0, - }, - /** 是否聚焦 */ - focus: { + /** 是否居中 */ + center: { type: Boolean, value: false, }, - /** 左侧文本 */ - label: { - type: String, - value: '', - }, - /** 用户最多可以输入的字符个数,一个中文汉字表示两个字符长度。`maxcharacter` 和 `maxlength` 二选一使用 */ - maxcharacter: { - type: Number, - }, - /** 用户最多可以输入的文本长度,一个中文等于一个计数长度,默认为 -1,不限制输入长度。`maxcharacter` 和 `maxlength` 二选一使用 */ - maxlength: { - type: Number, - value: -1, - }, - /** 设置键盘右下角按钮的文字,仅在type='text'时生效。
具体释义:
`send` 右下角按钮为“发送”;
`search` 右下角按钮为“搜索”;
`next` 右下角按钮为“下一个”;
`go` 右下角按钮为“前往”;
`done` 右下角按钮为“完成”。
[小程序官方文档](https://developers.weixin.qq.com/miniprogram/dev/component/input.html) */ - confirmType: { - type: String, - value: 'search', - }, - /** 强制 input 处于同层状态,默认 focus 时 input 会切到非同层状态 (仅在 iOS 下生效) */ - alwaysEmbed: { + /** 是否启用清除控件 */ + clearable: { type: Boolean, - value: false, + value: true, }, /** 点击键盘右下角按钮时是否保持键盘不收起 */ confirmHold: { type: Boolean, value: false, }, - /** 指定focus时的光标位置 */ + /** 设置键盘右下角按钮的文字,仅在type='text'时生效。
具体释义:
`send` 右下角按钮为“发送”;
`search` 右下角按钮为“搜索”;
`next` 右下角按钮为“下一个”;
`go` 右下角按钮为“前往”;
`done` 右下角按钮为“完成”。
[小程序官方文档](https://developers.weixin.qq.com/miniprogram/dev/component/input.html) */ + confirmType: { + type: String, + value: 'search', + }, + /** 指定 focus 时的光标位置 */ cursor: { type: Number, }, - /** 光标起始位置,自动聚集时有效,需与selection-end搭配使用 */ - selectionStart: { + /** 搜索框聚焦时底部与键盘的距离 */ + cursorSpacing: { type: Number, - value: -1, + value: 0, }, - /** 光标结束位置,自动聚集时有效,需与selection-start搭配使用 */ - selectionEnd: { - type: Number, - value: -1, + /** 是否禁用 */ + disabled: { + type: Boolean, + value: false, }, - /** 键盘弹起时,是否自动上推页面 */ - adjustPosition: { + /** 是否聚焦 */ + focus: { type: Boolean, - value: true, + value: false, }, /** focus时,点击页面的时候不收起键盘 */ holdKeyboard: { type: Boolean, value: false, }, - /** 指定 placeholder 的样式 */ - placeholderStyle: { - type: String, - value: '', - }, - /** 指定 placeholder 的样式类 */ - placeholderClass: { - type: String, - value: '', - }, /** 左侧图标 */ leftIcon: { type: String, value: 'search', }, + /** 用户最多可以输入的字符个数,一个中文汉字表示两个字符长度。`maxcharacter` 和 `maxlength` 二选一使用 */ + maxcharacter: { + type: Number, + }, + /** 用户最多可以输入的文本长度,一个中文等于一个计数长度。默认为 -1,不限制输入长度。`maxcharacter` 和 `maxlength` 二选一使用 */ + maxlength: { + type: Number, + value: -1, + }, /** 占位符 */ placeholder: { type: String, value: '', }, - /** 右侧图标 */ - rightIcon: { + /** 指定 placeholder 的样式类 */ + placeholderClass: { type: String, - value: 'close-circle-filled', + value: 'input-placeholder', + }, + /** 指定 placeholder 的样式 */ + placeholderStyle: { + type: String, + value: '', + }, + /** 预览结果列表 */ + resultList: { + type: Array, + value: [], + }, + /** 光标结束位置,自动聚集时有效,需与 selection-start 搭配使用 */ + selectionEnd: { + type: Number, + value: -1, + }, + /** 光标起始位置,自动聚集时有效,需与 selection-end 搭配使用 */ + selectionStart: { + type: Number, + value: -1, }, /** 搜索框形状 */ shape: { type: String, value: 'square', }, - /** 值 */ - value: { + /** 自定义组件样式 */ + style: { type: String, value: '', }, - /** 是否启用清除控件 */ - clearable: { - type: Boolean, - value: true, - }, - /** 控制拉起的键盘类型 */ + /** 拉起键盘的类型 */ type: { type: String, value: 'text', }, + /** 值 */ + value: { + type: String, + value: '', + }, }; export default props; diff --git a/src/search/type.ts b/src/search/type.ts index 884290c0e..574c24977 100644 --- a/src/search/type.ts +++ b/src/search/type.ts @@ -5,22 +5,6 @@ * */ export interface TdSearchProps { - /** - * 预览结果列表 - * @default [] - */ - resultList: { - type: ArrayConstructor; - value?: []; - }; - /** - * 自定义组件样式 - * @default '' - */ - style?: { - type: StringConstructor; - value?: string; - }; /** * 自定义右侧操作按钮文字 * @default '' @@ -30,169 +14,162 @@ export interface TdSearchProps { value?: string; }; /** - * 是否居中 - * @default false + * 键盘弹起时,是否自动上推页面 + * @default true */ - center?: { + adjustPosition?: { type: BooleanConstructor; value?: boolean; }; /** - * 是否禁用 + * 强制 input 处于同层状态,默认 focus 时 input 会切到非同层状态 (仅在 iOS 下生效) * @default false */ - disabled?: { + alwaysEmbed?: { type: BooleanConstructor; value?: boolean; }; /** - * 组件外部样式类名,分别用于设置组件外层类名、输入框类名、输入框容器类名、右侧 cancel 文本类名、左侧图标类名、右侧图标类型 + * 是否居中 + * @default false */ - externalClasses?: { - type: ArrayConstructor; - value?: ['t-class', 't-class-input', 't-class-input-container', 't-class-cancel', 't-class-left', 't-class-right']; + center?: { + type: BooleanConstructor; + value?: boolean; }; /** - * 指定光标与键盘的距离,取 input 距离底部的距离和 cursor-spacing 指定的距离的最小值作为光标与键盘的距离 - * @default 0 + * 是否启用清除控件 + * @default true */ - cursorSpacing?: { - type: NumberConstructor; - value?: number; + clearable?: { + type: BooleanConstructor; + value?: boolean; }; /** - * 是否聚焦 + * 点击键盘右下角按钮时是否保持键盘不收起 * @default false */ - focus?: { + confirmHold?: { type: BooleanConstructor; value?: boolean; }; /** - * 左侧文本 - * @default '' + * 设置键盘右下角按钮的文字,仅在type='text'时生效。
具体释义:
`send` 右下角按钮为“发送”;
`search` 右下角按钮为“搜索”;
`next` 右下角按钮为“下一个”;
`go` 右下角按钮为“前往”;
`done` 右下角按钮为“完成”。
[小程序官方文档](https://developers.weixin.qq.com/miniprogram/dev/component/input.html) + * @default search */ - label?: { + confirmType?: { type: StringConstructor; - value?: string; + value?: 'send' | 'search' | 'next' | 'go' | 'done'; }; /** - * 用户最多可以输入的字符个数,一个中文汉字表示两个字符长度。`maxcharacter` 和 `maxlength` 二选一使用 + * 指定 focus 时的光标位置 */ - maxcharacter?: { + cursor: { type: NumberConstructor; value?: number; }; /** - * 用户最多可以输入的文本长度,一个中文等于一个计数长度,默认为 -1,不限制输入长度。`maxcharacter` 和 `maxlength` 二选一使用 - * @default -1 + * 搜索框聚焦时底部与键盘的距离 + * @default 0 */ - maxlength?: { + cursorSpacing?: { type: NumberConstructor; value?: number; }; /** - * 设置键盘右下角按钮的文字,仅在type='text'时生效。
具体释义:
`send` 右下角按钮为“发送”;
`search` 右下角按钮为“搜索”;
`next` 右下角按钮为“下一个”;
`go` 右下角按钮为“前往”;
`done` 右下角按钮为“完成”。
[小程序官方文档](https://developers.weixin.qq.com/miniprogram/dev/component/input.html) - * @default search + * 是否禁用 + * @default false */ - confirmType?: { - type: StringConstructor; - value?: 'send' | 'search' | 'next' | 'go' | 'done'; + disabled?: { + type: BooleanConstructor; + value?: boolean; }; /** - * 强制 input 处于同层状态,默认 focus 时 input 会切到非同层状态 (仅在 iOS 下生效) + * 是否聚焦 * @default false */ - alwaysEmbed?: { + focus?: { type: BooleanConstructor; value?: boolean; }; /** - * 点击键盘右下角按钮时是否保持键盘不收起 + * focus时,点击页面的时候不收起键盘 * @default false */ - confirmHold?: { + holdKeyboard?: { type: BooleanConstructor; value?: boolean; }; /** - * 指定focus时的光标位置 + * 左侧图标 + * @default 'search' */ - cursor: { - type: NumberConstructor; - value?: number; + leftIcon?: { + type: StringConstructor; + value?: string; }; /** - * 光标起始位置,自动聚集时有效,需与selection-end搭配使用 - * @default -1 + * 用户最多可以输入的字符个数,一个中文汉字表示两个字符长度。`maxcharacter` 和 `maxlength` 二选一使用 */ - selectionStart?: { + maxcharacter?: { type: NumberConstructor; value?: number; }; /** - * 光标结束位置,自动聚集时有效,需与selection-start搭配使用 + * 用户最多可以输入的文本长度,一个中文等于一个计数长度。默认为 -1,不限制输入长度。`maxcharacter` 和 `maxlength` 二选一使用 * @default -1 */ - selectionEnd?: { + maxlength?: { type: NumberConstructor; value?: number; }; /** - * 键盘弹起时,是否自动上推页面 - * @default true - */ - adjustPosition?: { - type: BooleanConstructor; - value?: boolean; - }; - /** - * focus时,点击页面的时候不收起键盘 - * @default false - */ - holdKeyboard?: { - type: BooleanConstructor; - value?: boolean; - }; - /** - * 指定 placeholder 的样式 + * 占位符 * @default '' */ - placeholderStyle: { + placeholder?: { type: StringConstructor; value?: string; }; /** * 指定 placeholder 的样式类 - * @default '' + * @default input-placeholder */ placeholderClass?: { type: StringConstructor; value?: string; }; /** - * 左侧图标 - * @default 'search' + * 指定 placeholder 的样式 + * @default '' */ - leftIcon?: { + placeholderStyle: { type: StringConstructor; value?: string; }; /** - * 占位符 - * @default '' + * 预览结果列表 + * @default [] */ - placeholder?: { - type: StringConstructor; - value?: string; + resultList?: { + type: ArrayConstructor; + value?: Array; }; /** - * 右侧图标 - * @default 'close' + * 光标结束位置,自动聚集时有效,需与 selection-start 搭配使用 + * @default -1 */ - rightIcon?: { - type: StringConstructor; - value?: string; + selectionEnd?: { + type: NumberConstructor; + value?: number; + }; + /** + * 光标起始位置,自动聚集时有效,需与 selection-end 搭配使用 + * @default -1 + */ + selectionStart?: { + type: NumberConstructor; + value?: number; }; /** * 搜索框形状 @@ -203,26 +180,26 @@ export interface TdSearchProps { value?: 'square' | 'round'; }; /** - * 值 + * 自定义组件样式 * @default '' */ - value?: { + style?: { type: StringConstructor; value?: string; }; /** - * 是否启用清除控件 - * @default true + * 拉起键盘的类型 + * @default 'text' */ - clearable: { - type: BooleanConstructor; - value?: boolean; + type?: { + type: StringConstructor; + value?: 'text' | 'number' | 'idcard' | 'digit' | 'nickname'; }; /** - * 可以控制拉起的键盘类型 - * @default 'text' + * 值 + * @default '' */ - type: { + value?: { type: StringConstructor; value?: string; }; From 335492a4bd43f60272b6610bfaf4d0c9fe7e400e Mon Sep 17 00:00:00 2001 From: anlyyao Date: Mon, 1 Jul 2024 15:51:07 +0800 Subject: [PATCH 7/7] test: update snapshots --- src/search/__test__/__snapshots__/index.test.js.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/search/__test__/__snapshots__/index.test.js.snap b/src/search/__test__/__snapshots__/index.test.js.snap index 01d0fd3cc..9b50f8aec 100644 --- a/src/search/__test__/__snapshots__/index.test.js.snap +++ b/src/search/__test__/__snapshots__/index.test.js.snap @@ -42,7 +42,7 @@ exports[`search Props :base 1`] = ` maxlength="{{-1}}" name="input" placeholder="" - placeholderClass=" t-search__placeholder t-search__placeholder--normal" + placeholderClass="input-placeholder t-search__placeholder t-search__placeholder--normal" placeholderStyle="" selectionEnd="{{-1}}" selectionStart="{{-1}}"