From eacd447917f127a5ba6dbd237b135239ecedf446 Mon Sep 17 00:00:00 2001 From: liweijie0812 <674416404@qq.com> Date: Sun, 28 Apr 2024 11:39:54 +0800 Subject: [PATCH] refactor(input): sfc to tsx (#1342) * refactor(input): sfc to tsx * test: snap update * fix: tips --- .../__test__/__snapshots__/demo.test.jsx.snap | 64 +- .../__test__/__snapshots__/demo.test.jsx.snap | 186 ++--- .../__test__/__snapshots__/demo.test.jsx.snap | 724 +++++++----------- src/input/__test__/index.test.jsx | 12 +- src/input/index.ts | 2 +- src/input/input.en-US.md | 45 +- src/input/input.md | 11 +- src/input/input.tsx | 214 ++++++ src/input/input.vue | 218 ------ src/input/props.ts | 13 +- src/input/type.ts | 9 +- 11 files changed, 612 insertions(+), 886 deletions(-) create mode 100644 src/input/input.tsx delete mode 100644 src/input/input.vue diff --git a/src/dialog/__test__/__snapshots__/demo.test.jsx.snap b/src/dialog/__test__/__snapshots__/demo.test.jsx.snap index eb0bdd52c..298d84ea2 100644 --- a/src/dialog/__test__/__snapshots__/demo.test.jsx.snap +++ b/src/dialog/__test__/__snapshots__/demo.test.jsx.snap @@ -855,17 +855,13 @@ exports[`Dialog > Dialog inputVue demo works fine 1`] = ` >
-
- -
+
@@ -886,11 +882,11 @@ exports[`Dialog > Dialog inputVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
- +
@@ -1007,17 +1003,13 @@ exports[`Dialog > Dialog inputVue demo works fine 1`] = ` 告知当前状态、信息和解决方法等,描述文案尽可能控制在三行内

-
- -
+
@@ -1038,11 +1030,11 @@ exports[`Dialog > Dialog inputVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
- +
@@ -1703,17 +1695,13 @@ exports[`Dialog > Dialog mobileVue demo works fine 1`] = ` >
-
- -
+
@@ -1734,11 +1722,11 @@ exports[`Dialog > Dialog mobileVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
- +
@@ -1855,17 +1843,13 @@ exports[`Dialog > Dialog mobileVue demo works fine 1`] = ` 告知当前状态、信息和解决方法等,描述文案尽可能控制在三行内

-
- -
+
@@ -1886,11 +1870,11 @@ exports[`Dialog > Dialog mobileVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
- +
diff --git a/src/form/__test__/__snapshots__/demo.test.jsx.snap b/src/form/__test__/__snapshots__/demo.test.jsx.snap index c2ca539e7..0666e1966 100644 --- a/src/form/__test__/__snapshots__/demo.test.jsx.snap +++ b/src/form/__test__/__snapshots__/demo.test.jsx.snap @@ -32,17 +32,13 @@ exports[`Form > Form horizontalVue demo works fine 1`] = ` >
-
- -
+
@@ -63,11 +59,11 @@ exports[`Form > Form horizontalVue demo works fine 1`] = ` placeholder="请输入内容" type="text" /> - - - + + +
- +
@@ -108,17 +104,13 @@ exports[`Form > Form horizontalVue demo works fine 1`] = ` >
-
- -
+
@@ -139,8 +131,8 @@ exports[`Form > Form horizontalVue demo works fine 1`] = ` placeholder="请输入内容" type="password" /> - - + +
@@ -161,7 +153,7 @@ exports[`Form > Form horizontalVue demo works fine 1`] = `
- +
@@ -345,17 +337,13 @@ exports[`Form > Form horizontalVue demo works fine 1`] = ` >
-
- -
+
@@ -376,11 +364,11 @@ exports[`Form > Form horizontalVue demo works fine 1`] = ` placeholder="请输入内容" type="text" /> - - - + + +
- +
Form horizontalVue demo works fine 1`] = ` >
-
- -
+
@@ -809,11 +793,11 @@ exports[`Form > Form horizontalVue demo works fine 1`] = ` placeholder="请输入内容" type="text" /> - - - + + +
- +
Form mobileVue demo works fine 1`] = ` >
-
- -
+
@@ -1791,11 +1771,11 @@ exports[`Form > Form mobileVue demo works fine 1`] = ` placeholder="请输入内容" type="text" /> - - - + + +
- +
@@ -1836,17 +1816,13 @@ exports[`Form > Form mobileVue demo works fine 1`] = ` >
-
- -
+
@@ -1867,8 +1843,8 @@ exports[`Form > Form mobileVue demo works fine 1`] = ` placeholder="请输入内容" type="password" /> - - + +
@@ -1889,7 +1865,7 @@ exports[`Form > Form mobileVue demo works fine 1`] = `
- +
@@ -2073,17 +2049,13 @@ exports[`Form > Form mobileVue demo works fine 1`] = ` >
-
- -
+
@@ -2104,11 +2076,11 @@ exports[`Form > Form mobileVue demo works fine 1`] = ` placeholder="请输入内容" type="text" /> - - - + + +
- +
Form mobileVue demo works fine 1`] = ` >
-
- -
+
@@ -2537,11 +2505,11 @@ exports[`Form > Form mobileVue demo works fine 1`] = ` placeholder="请输入内容" type="text" /> - - - + + +
- +
Form verticalVue demo works fine 1`] = ` >
-
- -
+
@@ -3388,11 +3352,11 @@ exports[`Form > Form verticalVue demo works fine 1`] = ` placeholder="请输入内容" type="text" /> - - - + + +
- +
@@ -3431,17 +3395,13 @@ exports[`Form > Form verticalVue demo works fine 1`] = ` >
-
- -
+
@@ -3462,8 +3422,8 @@ exports[`Form > Form verticalVue demo works fine 1`] = ` placeholder="请输入内容" type="password" /> - - + +
@@ -3484,7 +3444,7 @@ exports[`Form > Form verticalVue demo works fine 1`] = `
- +
@@ -3664,17 +3624,13 @@ exports[`Form > Form verticalVue demo works fine 1`] = ` >
-
- -
+
@@ -3695,11 +3651,11 @@ exports[`Form > Form verticalVue demo works fine 1`] = ` placeholder="请输入内容" type="text" /> - - - + + +
- +
Form verticalVue demo works fine 1`] = ` >
-
- -
+
@@ -4126,11 +4078,11 @@ exports[`Form > Form verticalVue demo works fine 1`] = ` placeholder="请输入内容" type="text" /> - - - + + +
- +
Input alignVue demo works fine 1`] = ` >
-
- -
+
@@ -36,24 +32,20 @@ exports[`Input > Input alignVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
- +
-
- -
+
@@ -74,24 +66,20 @@ exports[`Input > Input alignVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
- +
-
- -
+
@@ -112,11 +100,11 @@ exports[`Input > Input alignVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
- +
@@ -125,17 +113,13 @@ exports[`Input > Input alignVue demo works fine 1`] = ` exports[`Input > Input bannerVue demo works fine 1`] = `
-
- -
+
@@ -156,11 +140,11 @@ exports[`Input > Input bannerVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
- +
`; @@ -171,16 +155,12 @@ exports[`Input > Input baseVue demo works fine 1`] = ` >
-
- -
+
@@ -201,24 +181,20 @@ exports[`Input > Input baseVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
- +
-
- -
+
@@ -239,24 +215,20 @@ exports[`Input > Input baseVue demo works fine 1`] = ` placeholder="请输入文字(选填)" type="text" /> - - - + + +
- +
-
- -
+
@@ -277,11 +249,11 @@ exports[`Input > Input baseVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
- +
@@ -300,17 +272,13 @@ exports[`Input > Input borderedVue demo works fine 1`] = ` 标签文字
-
- -
+
@@ -331,8 +299,8 @@ exports[`Input > Input borderedVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - + +
@@ -353,7 +321,7 @@ exports[`Input > Input borderedVue demo works fine 1`] = `
- +
@@ -365,17 +333,13 @@ exports[`Input > Input customVue demo works fine 1`] = ` data-v-16c31aae="" >
-
- -
+
@@ -396,11 +360,11 @@ exports[`Input > Input customVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
- +
@@ -408,16 +372,12 @@ exports[`Input > Input customVue demo works fine 1`] = ` exports[`Input > Input labelVue demo works fine 1`] = `
-
- -
+
@@ -438,27 +398,23 @@ exports[`Input > Input labelVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
- +
`; exports[`Input > Input layoutVue demo works fine 1`] = `
-
- -
+
@@ -479,8 +435,8 @@ exports[`Input > Input layoutVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - + +
@@ -500,7 +456,7 @@ exports[`Input > Input layoutVue demo works fine 1`] = `
- +
`; @@ -511,16 +467,12 @@ exports[`Input > Input maxLengthVue demo works fine 1`] = ` >
-
- -
+
@@ -541,9 +493,9 @@ exports[`Input > Input maxLengthVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
Input maxLengthVue demo works fine 1`] = `
-
- -
+
@@ -583,9 +531,9 @@ exports[`Input > Input maxLengthVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
Input mobileVue demo works fine 1`] = `
-
- -
+
@@ -665,24 +609,20 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
- +
-
- -
+
@@ -703,24 +643,20 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` placeholder="请输入文字(选填)" type="text" /> - - - + + +
- +
-
- -
+
@@ -741,11 +677,11 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
- +
@@ -771,16 +707,12 @@ exports[`Input > Input mobileVue demo works fine 1`] = `
-
- -
+
@@ -801,9 +733,9 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
Input mobileVue demo works fine 1`] = `
-
- -
+
@@ -843,9 +771,9 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
Input mobileVue demo works fine 1`] = `
-
- -
+
@@ -907,8 +831,8 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - + +
@@ -928,20 +852,16 @@ exports[`Input > Input mobileVue demo works fine 1`] = `
- +
-
- -
+
@@ -962,7 +882,7 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` placeholder="请输入手机号码" type="text" /> - +
@@ -985,22 +905,18 @@ exports[`Input > Input mobileVue demo works fine 1`] = `
- +
- +
-
- -
+
@@ -1021,8 +937,8 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - + +
@@ -1042,7 +958,7 @@ exports[`Input > Input mobileVue demo works fine 1`] = `
- +
@@ -1068,7 +984,7 @@ exports[`Input > Input mobileVue demo works fine 1`] = `
Input mobileVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
- +
Input mobileVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
- +
@@ -1192,16 +1108,12 @@ exports[`Input > Input mobileVue demo works fine 1`] = `
-
- -
+
@@ -1221,8 +1133,8 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` name="" type="password" /> - - + +
@@ -1242,20 +1154,16 @@ exports[`Input > Input mobileVue demo works fine 1`] = `
- +
-
- -
+
@@ -1276,7 +1184,7 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` placeholder="输入验证码" type="text" /> - +
@@ -1336,22 +1244,18 @@ exports[`Input > Input mobileVue demo works fine 1`] = `
- +
- +
-
- -
+
@@ -1372,7 +1276,7 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` placeholder="输入手机号码" type="text" /> - +
@@ -1392,22 +1296,18 @@ exports[`Input > Input mobileVue demo works fine 1`] = `
- +
- +
-
- -
+
@@ -1428,28 +1328,24 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` placeholder="0.00" type="text" /> - +
- +
- +
-
- -
+
@@ -1470,15 +1366,15 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` placeholder="填写个数" type="text" /> - +
- +
- +
@@ -1508,16 +1404,12 @@ exports[`Input > Input mobileVue demo works fine 1`] = `
-
- -
+
@@ -1538,9 +1430,9 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
Input mobileVue demo works fine 1`] = `
-
- -
+
@@ -1580,11 +1468,11 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` name="" type="text" /> - - - + + +
- +
@@ -1609,16 +1497,12 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` >
-
- -
+
@@ -1639,11 +1523,11 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
- +
@@ -1672,16 +1556,12 @@ exports[`Input > Input mobileVue demo works fine 1`] = `
-
- -
+
@@ -1702,24 +1582,20 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
- +
-
- -
+
@@ -1740,24 +1616,20 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
- +
-
- -
+
@@ -1778,11 +1650,11 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
- +
@@ -1807,16 +1679,12 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` >
-
- -
+
@@ -1837,8 +1705,8 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - + +
@@ -1858,7 +1726,7 @@ exports[`Input > Input mobileVue demo works fine 1`] = `
- +
@@ -1882,17 +1750,13 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` >
-
- -
+
@@ -1913,11 +1777,11 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
- +
@@ -1951,17 +1815,13 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` 标签文字
-
- -
+
@@ -1982,8 +1842,8 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - + +
@@ -2004,7 +1864,7 @@ exports[`Input > Input mobileVue demo works fine 1`] = `
- +
@@ -2033,17 +1893,13 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` data-v-16c31aae="" >
-
- -
+
@@ -2064,11 +1920,11 @@ exports[`Input > Input mobileVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
- +
@@ -2084,7 +1940,7 @@ exports[`Input > Input prefixVue demo works fine 1`] = ` >
Input prefixVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
- +
Input prefixVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
- +
@@ -2195,16 +2051,12 @@ exports[`Input > Input specialVue demo works fine 1`] = ` >
-
- -
+
@@ -2224,8 +2076,8 @@ exports[`Input > Input specialVue demo works fine 1`] = ` name="" type="password" /> - - + +
@@ -2245,20 +2097,16 @@ exports[`Input > Input specialVue demo works fine 1`] = `
- +
-
- -
+
@@ -2279,7 +2127,7 @@ exports[`Input > Input specialVue demo works fine 1`] = ` placeholder="输入验证码" type="text" /> - +
@@ -2339,22 +2187,18 @@ exports[`Input > Input specialVue demo works fine 1`] = `
- +
- +
-
- -
+
@@ -2375,7 +2219,7 @@ exports[`Input > Input specialVue demo works fine 1`] = ` placeholder="输入手机号码" type="text" /> - +
@@ -2395,22 +2239,18 @@ exports[`Input > Input specialVue demo works fine 1`] = `
- +
- +
-
- -
+
@@ -2431,28 +2271,24 @@ exports[`Input > Input specialVue demo works fine 1`] = ` placeholder="0.00" type="text" /> - +
- +
- +
-
- -
+
@@ -2473,15 +2309,15 @@ exports[`Input > Input specialVue demo works fine 1`] = ` placeholder="填写个数" type="text" /> - +
- +
- +
@@ -2494,16 +2330,12 @@ exports[`Input > Input statusVue demo works fine 1`] = ` >
-
- -
+
@@ -2524,9 +2356,9 @@ exports[`Input > Input statusVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - - + + +
Input statusVue demo works fine 1`] = `
-
- -
+
@@ -2566,11 +2394,11 @@ exports[`Input > Input statusVue demo works fine 1`] = ` name="" type="text" /> - - - + + +
- +
@@ -2583,16 +2411,12 @@ exports[`Input > Input suffixVue demo works fine 1`] = ` >
-
- -
+
@@ -2613,8 +2437,8 @@ exports[`Input > Input suffixVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - + +
@@ -2634,20 +2458,16 @@ exports[`Input > Input suffixVue demo works fine 1`] = `
- +
-
- -
+
@@ -2668,7 +2488,7 @@ exports[`Input > Input suffixVue demo works fine 1`] = ` placeholder="请输入手机号码" type="text" /> - +
@@ -2691,22 +2511,18 @@ exports[`Input > Input suffixVue demo works fine 1`] = `
- +
- +
-
- -
+
@@ -2727,8 +2543,8 @@ exports[`Input > Input suffixVue demo works fine 1`] = ` placeholder="请输入文字" type="text" /> - - + +
@@ -2748,7 +2564,7 @@ exports[`Input > Input suffixVue demo works fine 1`] = `
- +
diff --git a/src/input/__test__/index.test.jsx b/src/input/__test__/index.test.jsx index e47b00cd3..436098eb1 100644 --- a/src/input/__test__/index.test.jsx +++ b/src/input/__test__/index.test.jsx @@ -1,7 +1,7 @@ import { nextTick, ref, onMounted } from 'vue'; import { mount } from '@vue/test-utils'; import { describe, it, expect, vi } from 'vitest'; -import Input from '../input.vue'; +import Input from '../input'; import { CloseCircleFilledIcon, InfoCircleFilledIcon, AppIcon } from 'tdesign-icons-vue-next'; @@ -110,16 +110,6 @@ describe('Input.vue', async () => { expect(input.element.getAttribute('autocomplete')).toBe('On'); }); - it(': size', async () => { - const sizeList = ['', 'small', 'meddium', 'large']; - sizeList.forEach((size, index) => { - const wrapper = mount(() => ); - if (size) { - expect(wrapper.classes()).toContain(`t-input--size-${size}`); - } - }); - }); - it(': layout', async () => { const layoutList = ['', 'vertical', 'horizontal']; layoutList.forEach((layout, index) => { diff --git a/src/input/index.ts b/src/input/index.ts index 92764832a..888f98a92 100644 --- a/src/input/index.ts +++ b/src/input/index.ts @@ -1,5 +1,5 @@ import { withInstall, WithInstallType } from '../shared'; -import Input from './input.vue'; +import Input from './input'; import './style'; import { TdInputProps } from './type'; diff --git a/src/input/input.en-US.md b/src/input/input.en-US.md index 16e1b5a80..5d583e44e 100644 --- a/src/input/input.en-US.md +++ b/src/input/input.en-US.md @@ -2,36 +2,37 @@ :: BASE_DOC :: ## API + ### Input Props name | type | default | description | required -- | -- | -- | -- | -- -align | String | left | options:left/center/right | N -allowInputOverMax | Boolean | false | \- | N -autocomplete | String | undefined | \- | N -autofocus | Boolean | false | \- | N -borderless | Boolean | false | \- | N -clearable | Boolean | false | \- | N -disabled | Boolean | - | \- | N -format | Function | - | Typescript:`InputFormatType` `type InputFormatType = (value: InputValue) => string`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/input/type.ts) | N -label | String / Slot / Function | - | Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N -layout | String | horizontal | options:vertical/horizontal | N +align | String | left | text align type。options: left/center/right | N +allowInputOverMax | Boolean | false | allow to continue input on value length is over `maxlength` or `maxcharacter` | N +autocomplete | String | undefined | attribute of input element, [see here](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete) | N +autofocus | Boolean | false | autofocus on first rendered | N +borderless | Boolean | false | input without border | N +clearable | Boolean | false | show clear icon, clicked to clear input value | N +disabled | Boolean | - | make input to be disabled | N +format | Function | - | input value formatter, `type=number` does not work. if you need to format number, `InputNumber` Component might be better。Typescript:`InputFormatType` `type InputFormatType = (value: InputValue) => string`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/input/type.ts) | N +label | String / Slot / Function | - | text on the left of input。Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N +layout | String | horizontal | options: vertical/horizontal | N maxcharacter | Number | - | \- | N maxlength | Number | - | \- | N name | String | - | \- | N placeholder | String | undefined | \- | N prefixIcon | Slot / Function | - | Typescript:`TNode`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N readonly | Boolean | false | \- | N -size | String | small | options:small/medium。Typescript:`'medium' \| 'small'` | N -status | String | undefined | options:default/success/warning/error | N -suffix | String / Slot / Function | - | Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N -suffixIcon | Slot / Function | - | Typescript:`TNode`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N -tips | String / Slot / Function | - | Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N -type | String | text | options:text/number/url/tel/password/search/submit/hidden | N -value | String / Number | '' | `v-model` and `v-model:value` is supported。Typescript:`InputValue` `type InputValue = string`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/input/type.ts) | N -defaultValue | String / Number | '' | uncontrolled property。Typescript:`InputValue` `type InputValue = string`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/input/type.ts) | N +size | String | small | `deprecated`。options: small/medium。Typescript:`'medium' \| 'small'` | N +status | String | undefined | options: default/success/warning/error | N +suffix | String / Slot / Function | - | suffix content before suffixIcon。Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N +suffixIcon | Slot / Function | - | suffix icon of input。Typescript:`TNode`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N +tips | String / Slot / Function | - | tips on the bottom of input, different `status` can make tips to be different color。Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N +type | String | text | type attribute of input element. if you are using `type=number`, `InputNumber` Component might be better。options: text/number/url/tel/password/search/submit/hidden | N +value | String / Number | '' | input value。`v-model` and `v-model:value` is supported。Typescript:`InputValue` `type InputValue = string`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/input/type.ts) | N +defaultValue | String / Number | '' | input value。uncontrolled property。Typescript:`InputValue` `type InputValue = string`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/input/type.ts) | N onBlur | Function | | Typescript:`(value: InputValue, context: { e: FocusEvent }) => void`
| N -onChange | Function | | Typescript:`(value: InputValue, context?: { e?: InputEvent \| MouseEvent \| CompositionEvent; trigger: 'input' \| 'initial' \| 'clear' }) => void`
| N +onChange | Function | | Typescript:`(value: InputValue, context?: { e?: InputEvent \| MouseEvent \| CompositionEvent; trigger: 'input' \| 'initial' \| 'clear' }) => void`
trigger on input value changed | N onClear | Function | | Typescript:`(context: { e: MouseEvent }) => void`
| N onFocus | Function | | Typescript:`(value: InputValue, context: { e: FocusEvent }) => void`
| N onValidate | Function | | Typescript:`(context: { error?: 'exceed-maximum' \| 'below-minimum' }) => void`
trigger on text length being over max length or max character | N @@ -41,13 +42,13 @@ onValidate | Function | | Typescript:`(context: { error?: 'exceed-maximum' \| name | params | description -- | -- | -- blur | `(value: InputValue, context: { e: FocusEvent })` | \- -change | `(value: InputValue, context?: { e?: InputEvent \| MouseEvent \| CompositionEvent; trigger: 'input' \| 'initial' \| 'clear' })` | \- +change | `(value: InputValue, context?: { e?: InputEvent \| MouseEvent \| CompositionEvent; trigger: 'input' \| 'initial' \| 'clear' })` | trigger on input value changed clear | `(context: { e: MouseEvent })` | \- focus | `(value: InputValue, context: { e: FocusEvent })` | \- validate | `(context: { error?: 'exceed-maximum' \| 'below-minimum' })` | trigger on text length being over max length or max character +### CSS 变量 -### CSS Variables The component provides the following CSS variables, which can be used to customize styles. Name | Default Value | Description -- | -- | -- @@ -70,4 +71,4 @@ Name | Default Value | Description --td-input-suffix-text-color | @font-gray-1 | - --td-input-vertical-padding | 16px | - --td-input-warning-text-color | @warning-color | - ---td-input-warning-tips-color | @warning-color | - +--td-input-warning-tips-color | @warning-color | - \ No newline at end of file diff --git a/src/input/input.md b/src/input/input.md index c55cea368..d35bb4fcc 100644 --- a/src/input/input.md +++ b/src/input/input.md @@ -1,9 +1,10 @@ :: BASE_DOC :: ## API + ### Input Props -名称 | 类型 | 默认值 | 说明 | 必传 +名称 | 类型 | 默认值 | 描述 | 必传 -- | -- | -- | -- | -- align | String | left | 文本内容位置,居左/居中/居右。可选项:left/center/right | N allowInputOverMax | Boolean | false | 超出 `maxlength` 或 `maxcharacter` 之后是否允许继续输入 | N @@ -33,7 +34,7 @@ onBlur | Function | | TS 类型:`(value: InputValue, context: { e: FocusEvent onChange | Function | | TS 类型:`(value: InputValue, context?: { e?: InputEvent \| MouseEvent \| CompositionEvent; trigger: 'input' \| 'initial' \| 'clear' }) => void`
输入框值发生变化时触发。`trigger=initial` 表示传入的数据不符合预期,组件自动处理后触发 change 告知父组件。如:初始值长度超过 `maxlength` 限制 | N onClear | Function | | TS 类型:`(context: { e: MouseEvent }) => void`
清空按钮点击时触发 | N onFocus | Function | | TS 类型:`(value: InputValue, context: { e: FocusEvent }) => void`
获得焦点时触发 | N -onValidate | Function | | 【暂不支持】TS 类型:`(context: { error?: 'exceed-maximum' \| 'below-minimum' }) => void`
字数超出限制时触发 | N +onValidate | Function | | TS 类型:`(context: { error?: 'exceed-maximum' \| 'below-minimum' }) => void`
【暂不支持】字数超出限制时触发 | N ### Input Events @@ -43,10 +44,10 @@ blur | `(value: InputValue, context: { e: FocusEvent })` | 失去焦点时触发 change | `(value: InputValue, context?: { e?: InputEvent \| MouseEvent \| CompositionEvent; trigger: 'input' \| 'initial' \| 'clear' })` | 输入框值发生变化时触发。`trigger=initial` 表示传入的数据不符合预期,组件自动处理后触发 change 告知父组件。如:初始值长度超过 `maxlength` 限制 clear | `(context: { e: MouseEvent })` | 清空按钮点击时触发 focus | `(value: InputValue, context: { e: FocusEvent })` | 获得焦点时触发 -validate | `(context: { error?: 'exceed-maximum' \| 'below-minimum' })` | 字数超出限制时触发 - +validate | `(context: { error?: 'exceed-maximum' \| 'below-minimum' })` | 【暂不支持】字数超出限制时触发 ### CSS 变量 + 组件提供了下列 CSS 变量,可用于自定义样式。 名称 | 默认值 | 描述 -- | -- | -- @@ -69,4 +70,4 @@ validate | `(context: { error?: 'exceed-maximum' \| 'below-minimum' })` | 字数 --td-input-suffix-text-color | @font-gray-1 | - --td-input-vertical-padding | 16px | - --td-input-warning-text-color | @warning-color | - ---td-input-warning-tips-color | @warning-color | - +--td-input-warning-tips-color | @warning-color | - \ No newline at end of file diff --git a/src/input/input.tsx b/src/input/input.tsx new file mode 100644 index 000000000..b328f0fe7 --- /dev/null +++ b/src/input/input.tsx @@ -0,0 +1,214 @@ +import { PropType, ref, computed, defineComponent, toRefs, nextTick, watch } from 'vue'; +import { CloseCircleFilledIcon as TCloseCircleFilledIcon } from 'tdesign-icons-vue-next'; +import { useFocus } from '@vueuse/core'; +import config from '../config'; +import InputProps from './props'; +import { InputValue, TdInputProps } from './type'; +import { getCharacterLength, useDefault, extendAPI } from '../shared'; +import { useFormDisabled } from '../form/hooks'; +import { usePrefixClass } from '@/hooks/useClass'; +import { useTNodeJSX } from '@/hooks/tnode'; + +const { prefix } = config; +const name = `${prefix}-input`; + +export default defineComponent({ + name, + props: { + ...InputProps, + labelAlign: { + type: String, + default: 'top', + }, + pattern: { + type: String, + }, + inputmode: { + type: String as PropType<'search' | 'text' | 'none' | 'url' | 'tel' | 'email' | 'numeric' | 'decimal'>, + validator(val: string): boolean { + if (!val) return true; + return ['search', 'text', 'none', 'url', 'tel', 'email', 'numeric', 'decimal'].includes(val); + }, + }, + }, + setup(props, context) { + const readerTNodeJSX = useTNodeJSX(); + const inputClass = usePrefixClass('input'); + const isDisabled = useFormDisabled(); + + const inputRef = ref(); + const { autofocus } = toRefs(props); + const [innerValue] = useDefault(props, context.emit, 'value', 'change'); + + const status = props.status || 'default'; + + const { focused } = useFocus(inputRef, { initialValue: props.autofocus }); + + const inputClasses = computed(() => [ + `${inputClass.value}__control`, + { + [`${inputClass.value}--${props.align}`]: props.align !== 'left', + [`${inputClass.value}--${status}`]: status, + [`${inputClass.value}__control--disabled`]: isDisabled.value, + }, + ]); + + const rootClasses = computed(() => [ + inputClass.value, + { + [`${inputClass.value}--layout-${props.layout}`]: props.layout, + [`${inputClass.value}--center`]: props.labelAlign === 'center', + [`${inputClass.value}--border`]: !props.borderless, + }, + ]); + + const setInputValue = (v: InputValue = '') => { + const input = inputRef.value as HTMLInputElement; + const sV = String(v); + if (!input) { + return; + } + if (input.value !== sV) { + input.value = sV; + } + }; + + const handleInput = (e: Event) => { + // 中文输入的时候inputType是insertCompositionText所以中文输入的时候禁止触发。 + if (e instanceof InputEvent) { + const checkInputType = e.inputType && e.inputType === 'insertCompositionText'; + if (e.isComposing || checkInputType) return; + } + inputValueChangeHandle(e); + }; + + const inputValueChangeHandle = (e: Event) => { + const { value } = e.target as HTMLInputElement; + const { allowInputOverMax, maxcharacter } = props; + if (!allowInputOverMax && maxcharacter && maxcharacter > 0 && !Number.isNaN(maxcharacter)) { + const { length = 0, characters = '' } = getCharacterLength(value, maxcharacter) as { + length: number; + characters: string; + }; + innerValue.value = characters; + } else { + innerValue.value = value; + } + nextTick(() => setInputValue(innerValue.value)); + }; + + const focus = () => { + focused.value = true; + }; + + const blur = () => { + focused.value = false; + // inputRef.value?.blur(); + }; + + extendAPI({ focus, blur }); + + const handleClear = (e: MouseEvent) => { + innerValue.value = ''; + focused.value = true; + props.onClear?.({ e }); + }; + const handleFocus = (e: FocusEvent) => { + props.onFocus?.(innerValue.value, { e }); + }; + const handleBlur = (e: FocusEvent) => { + props.onBlur?.(innerValue.value, { e }); + }; + + const handleCompositionend = (e: CompositionEvent) => { + inputValueChangeHandle(e); + }; + + watch(autofocus, (autofocus, prevAutofocus) => { + if (autofocus === true) { + nextTick(() => { + focused.value = true; + }); + } + }); + + return () => { + const readerPrefix = () => { + const prefixIcon = readerTNodeJSX('prefixIcon'); + const label = readerTNodeJSX('label'); + + return ( +
+ {prefixIcon &&
{prefixIcon}
} +
{label}
+
+ ); + }; + const readerClearable = () => { + if (props.clearable && innerValue.value && innerValue.value.length > 0) { + return ( +
+ +
+ ); + } + return null; + }; + const readerSuffix = () => { + const suffix = readerTNodeJSX('suffix'); + if (!suffix) { + return null; + } + return
{suffix}
; + }; + + const readerSuffixIcon = () => { + const suffixIcon = readerTNodeJSX('suffixIcon'); + if (!suffixIcon) { + return null; + } + return
{suffixIcon}
; + }; + + const readerTips = () => { + const tips = readerTNodeJSX('tips'); + if (!tips) { + return null; + } + return
{tips}
; + }; + + return ( +
+ {readerPrefix()} +
+
+ + {readerClearable()} + {readerSuffix()} + {readerSuffixIcon()} +
+ {readerTips()} +
+
+ ); + }; + }, +}); diff --git a/src/input/input.vue b/src/input/input.vue deleted file mode 100644 index 1f2e6efbc..000000000 --- a/src/input/input.vue +++ /dev/null @@ -1,218 +0,0 @@ - - - diff --git a/src/input/props.ts b/src/input/props.ts index 80375a15c..289010ecf 100644 --- a/src/input/props.ts +++ b/src/input/props.ts @@ -32,7 +32,7 @@ export default { clearable: Boolean, /** 是否禁用输入框 */ disabled: Boolean, - /** 指定输入框展示值的格式 */ + /** 【暂不支持】指定输入框展示值的格式 */ format: { type: Function as PropType, }, @@ -73,15 +73,6 @@ export default { }, /** 只读状态 */ readonly: Boolean, - /** 已废弃。输入框尺寸 */ - size: { - type: String as PropType, - default: 'small' as TdInputProps['size'], - validator(val: TdInputProps['size']): boolean { - if (!val) return true; - return ['small', 'medium'].includes(val); - }, - }, /** 输入框状态。默认情况会由组件内部根据实际情况呈现,如果文本过长引起的状态变化 */ status: { type: String as PropType, @@ -134,6 +125,6 @@ export default { onClear: Function as PropType, /** 获得焦点时触发 */ onFocus: Function as PropType, - /** 字数超出限制时触发 */ + /** 【暂不支持】字数超出限制时触发 */ onValidate: Function as PropType, }; diff --git a/src/input/type.ts b/src/input/type.ts index e90f65c49..c30a8da28 100644 --- a/src/input/type.ts +++ b/src/input/type.ts @@ -41,7 +41,7 @@ export interface TdInputProps { */ disabled?: boolean; /** - * 指定输入框展示值的格式 + * 【暂不支持】指定输入框展示值的格式 */ format?: InputFormatType; /** @@ -79,11 +79,6 @@ export interface TdInputProps { * @default false */ readonly?: boolean; - /** - * 已废弃。输入框尺寸 - * @default small - */ - size?: 'medium' | 'small'; /** * 输入框状态。默认情况会由组件内部根据实际情况呈现,如果文本过长引起的状态变化 */ @@ -140,7 +135,7 @@ export interface TdInputProps { */ onFocus?: (value: InputValue, context: { e: FocusEvent }) => void; /** - * 字数超出限制时触发 + * 【暂不支持】字数超出限制时触发 */ onValidate?: (context: { error?: 'exceed-maximum' | 'below-minimum' }) => void; }