Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(input): support number type #3600

Merged
merged 3 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/auto-complete/auto-complete.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { computed, ref, defineComponent, toRefs, nextTick } from 'vue';
import props from './props';
import { TdAutoCompleteProps } from './type';
import Input, { InputProps, TdInputProps } from '../input';
import Input, { InputProps, StrInputProps } from '../input';
import Popup, { PopupProps } from '../popup';
import useCommonClassName from '../hooks/useCommonClassName';
import AutoCompleteOptionList from './option-list';
Expand Down Expand Up @@ -52,7 +52,7 @@ export default defineComponent({
return classes;
});

const onInputChange: TdInputProps['onChange'] = (value, context) => {
const onInputChange: StrInputProps['onChange'] = (value, context) => {
setTValue(value, context);
};

Expand All @@ -65,15 +65,15 @@ export default defineComponent({
return tProps;
});

const onInnerFocus: InputProps['onFocus'] = (value, context) => {
const onInnerFocus: StrInputProps['onFocus'] = (value, context) => {
popupVisible.value = true;
props.onFocus?.({ ...context, value });
nextTick(() => {
optionListRef.value?.addKeyboardListener();
});
};

const onInnerBlur: InputProps['onBlur'] = (value, context) => {
const onInnerBlur: StrInputProps['onBlur'] = (value, context) => {
props.onBlur?.({ ...context, value });
};

Expand All @@ -85,7 +85,7 @@ export default defineComponent({
props.onCompositionstart?.({ ...context, value });
};

const onInnerEnter: InputProps['onEnter'] = (value, context) => {
const onInnerEnter: StrInputProps['onEnter'] = (value, context) => {
props.onEnter?.({ ...context, value });
};

Expand Down
4 changes: 2 additions & 2 deletions src/input-number/useInputNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
largeNumberToFixed,
} from '../_common/js/input-number/number';
import { useFormDisabled } from '../form/hooks';
import { TdInputProps } from '../input';
import { StrInputProps } from '../input';

/**
* 独立一个组件 Hook 方便用户直接使用相关逻辑 自定义任何样式的数字输入框
Expand Down Expand Up @@ -159,7 +159,7 @@ export default function useInputNumber(props: TdInputNumberProps) {
setTValue(r.newValue, { type: 'add', e });
};

const onInnerInputChange: TdInputProps['onChange'] = (inputValue, { e }) => {
const onInnerInputChange: StrInputProps['onChange'] = (inputValue, { e }) => {
// 千分位处理
const val = formatThousandths(inputValue);

Expand Down
2 changes: 1 addition & 1 deletion src/input/__tests__/vitest-input.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ describe('Input Component', () => {
wrapper.find('input').trigger('focus');
await wrapper.vm.$nextTick();
expect(onFocusFn).toHaveBeenCalled(1);
expect(onFocusFn.mock.calls[0][0]).toBe('');
expect(onFocusFn.mock.calls[0][0]).toBe(undefined);
expect(onFocusFn.mock.calls[0][1].e.type).toBe('focus');
});

Expand Down
8 changes: 6 additions & 2 deletions src/input/_example/base.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<t-input v-model="input" placeholder="请输入内容(有默认值)" @enter="onEnter" @change="onChange" />

<!-- label/suffix/suffixIcon 支持同名插槽 -->
<t-input label="价格:" suffix="元" @focus="onFocus" @blur="onBlur" />
<t-input label="价格:" suffix="元" type="number" @change="onNumberChange" @focus="onFocus" @blur="onBlur" />

<t-input label="姓名:" placeholder="按后置图标进行搜索">
<t-input placeholder="Search Input" clearable>
<template #suffixIcon>
<search-icon :style="{ cursor: 'pointer' }" />
</template>
Expand All @@ -33,4 +33,8 @@ const onFocus = (val, ctx) => {
const onBlur = (val, ctx) => {
console.log('blur:', val, ctx);
};

const onNumberChange = (val, ctx) => {
console.log(val, ctx);
};
</script>
8 changes: 6 additions & 2 deletions src/input/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import _Input from './input';
import _InputGroup from './input-group';
import withInstall from '../utils/withInstall';
import { TdInputProps } from './type';
import { InputValue, TdInputProps } from './type';

import './style';

export * from './type';
export type InputProps = TdInputProps;
export type InputProps<T = InputValue> = TdInputProps<T>;
export type InputBlurEventParams = Parameters<InputProps['onBlur']>;
export type InputFocusEventParams = Parameters<InputProps['onFocus']>;
export type StrInputProps = TdInputProps<string>;
export type NumberInputProps = TdInputProps<number>;

export const Input = withInstall(_Input);
export const InputGroup = withInstall(_InputGroup);
Expand Down
75 changes: 38 additions & 37 deletions src/input/input.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,44 @@

name | type | default | description | required
-- | -- | -- | -- | --
align | String | left | options: left/center/right | N
allowInputOverMax | Boolean | false | \- | N
autoWidth | Boolean | false | \- | N
autocomplete | String | undefined | \- | N
autofocus | 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-vue-next/tree/develop/src/input/type.ts) | N
inputClass | String / Object / Array | - | Typescript:`ClassName`。[see more ts definition](https://github.com/Tencent/tdesign-vue-next/blob/develop/src/common.ts) | N
label | String / Slot / Function | - | Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-vue-next/blob/develop/src/common.ts) | 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
autoWidth | Boolean | false | input width is fit to input content | 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: string) => string`。[see more ts definition](https://github.com/Tencent/tdesign-vue-next/tree/develop/src/input/type.ts) | N
inputClass | String / Object / Array | - | add className to the element with `t-input` class。Typescript:`ClassName`。[see more ts definition](https://github.com/Tencent/tdesign-vue-next/blob/develop/src/common.ts) | N
label | String / Slot / Function | - | text on the left of input。Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-vue-next/blob/develop/src/common.ts) | N
maxcharacter | Number | - | \- | N
maxlength | Number / String | - | \- | N
maxlength | String / Number | - | \- | N
name | String | - | \- | N
placeholder | String | undefined | \- | N
prefixIcon | Slot / Function | - | Typescript:`TNode`。[see more ts definition](https://github.com/Tencent/tdesign-vue-next/blob/develop/src/common.ts) | N
readonly | Boolean | false | \- | N
showClearIconOnEmpty | Boolean | false | \- | N
showClearIconOnEmpty | Boolean | false | show clear icon on empty input value | N
showLimitNumber | Boolean | false | show limit number text on the right | N
size | String | medium | options: small/medium/large。Typescript:`SizeEnum`。[see more ts definition](https://github.com/Tencent/tdesign-vue-next/blob/develop/src/common.ts) | N
size | String | medium | make input to be different size。options: small/medium/large。Typescript:`SizeEnum`。[see more ts definition](https://github.com/Tencent/tdesign-vue-next/blob/develop/src/common.ts) | 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-vue-next/blob/develop/src/common.ts) | N
suffixIcon | Slot / Function | - | Typescript:`TNode`。[see more ts definition](https://github.com/Tencent/tdesign-vue-next/blob/develop/src/common.ts) | N
tips | String / Slot / Function | - | Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-vue-next/blob/develop/src/common.ts) | N
type | String | text | options: text/number/url/tel/password/search/submit/hidden | N
value | String | '' | `v-model` and `v-model:value` is supported。Typescript:`InputValue` `type InputValue = string`。[see more ts definition](https://github.com/Tencent/tdesign-vue-next/tree/develop/src/input/type.ts) | N
defaultValue | String | '' | uncontrolled property。Typescript:`InputValue` `type InputValue = string`。[see more ts definition](https://github.com/Tencent/tdesign-vue-next/tree/develop/src/input/type.ts) | N
onBlur | Function | | Typescript:`(value: InputValue, context: { e: FocusEvent }) => void`<br/> | N
onChange | Function | | Typescript:`(value: InputValue, context?: { e?: InputEvent \| MouseEvent \| CompositionEvent; trigger: 'input' \| 'initial' \| 'clear' }) => void`<br/> | N
suffix | String / Slot / Function | - | suffix content before suffixIcon。Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-vue-next/blob/develop/src/common.ts) | N
suffixIcon | Slot / Function | - | suffix icon of input。Typescript:`TNode`。[see more ts definition](https://github.com/Tencent/tdesign-vue-next/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-vue-next/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:`T` `type InputValue = string \| number`。[see more ts definition](https://github.com/Tencent/tdesign-vue-next/tree/develop/src/input/type.ts) | N
defaultValue | String / Number | - | input value。uncontrolled property。Typescript:`T` `type InputValue = string \| number`。[see more ts definition](https://github.com/Tencent/tdesign-vue-next/tree/develop/src/input/type.ts) | N
onBlur | Function | | Typescript:`(value: T, context: { e: FocusEvent }) => void`<br/> | N
onChange | Function | | Typescript:`(value: T, context?: { e?: InputEvent \| MouseEvent \| CompositionEvent; trigger: 'input' \| 'initial' \| 'clear' }) => void`<br/>trigger on input value changed | N
onClear | Function | | Typescript:`(context: { e: MouseEvent }) => void`<br/> | N
onClick | Function | | Typescript:`(context: { e: MouseEvent }) => void`<br/> | N
onCompositionend | Function | | Typescript:`(value: InputValue, context: { e: CompositionEvent }) => void`<br/>trigger on compositionend | N
onCompositionstart | Function | | Typescript:`(value: InputValue, context: { e: CompositionEvent }) => void`<br/>trigger on compositionstart | N
onEnter | Function | | Typescript:`(value: InputValue, context: { e: KeyboardEvent }) => void`<br/> | N
onFocus | Function | | Typescript:`(value: InputValue, context: { e: FocusEvent }) => void`<br/> | N
onKeydown | Function | | Typescript:`(value: InputValue, context: { e: KeyboardEvent }) => void`<br/> | N
onKeypress | Function | | Typescript:`(value: InputValue, context: { e: KeyboardEvent }) => void`<br/> | N
onKeyup | Function | | Typescript:`(value: InputValue, context: { e: KeyboardEvent }) => void`<br/> | N
onCompositionend | Function | | Typescript:`(value: string, context: { e: CompositionEvent }) => void`<br/>trigger on compositionend | N
onCompositionstart | Function | | Typescript:`(value: string, context: { e: CompositionEvent }) => void`<br/>trigger on compositionstart | N
onEnter | Function | | Typescript:`(value: T, context: { e: KeyboardEvent }) => void`<br/> | N
onFocus | Function | | Typescript:`(value: T, context: { e: FocusEvent }) => void`<br/> | N
onKeydown | Function | | Typescript:`(value: T, context: { e: KeyboardEvent }) => void`<br/> | N
onKeypress | Function | | Typescript:`(value: T, context: { e: KeyboardEvent }) => void`<br/> | N
onKeyup | Function | | Typescript:`(value: T, context: { e: KeyboardEvent }) => void`<br/> | N
onMouseenter | Function | | Typescript:`(context: { e: MouseEvent }) => void`<br/>trigger on mouseenter | N
onMouseleave | Function | | Typescript:`(context: { e: MouseEvent }) => void`<br/>trigger on mouseleave | N
onPaste | Function | | Typescript:`(context: { e: ClipboardEvent; pasteValue: string }) => void`<br/> | N
Expand All @@ -52,17 +53,17 @@ onWheel | Function | | Typescript:`(context: { e: WheelEvent }) => void`<br/>

name | params | description
-- | -- | --
blur | `(value: InputValue, context: { e: FocusEvent })` | \-
change | `(value: InputValue, context?: { e?: InputEvent \| MouseEvent \| CompositionEvent; trigger: 'input' \| 'initial' \| 'clear' })` | \-
blur | `(value: T, context: { e: FocusEvent })` | \-
change | `(value: T, context?: { e?: InputEvent \| MouseEvent \| CompositionEvent; trigger: 'input' \| 'initial' \| 'clear' })` | trigger on input value changed
clear | `(context: { e: MouseEvent })` | \-
click | `(context: { e: MouseEvent })` | \-
compositionend | `(value: InputValue, context: { e: CompositionEvent })` | trigger on compositionend
compositionstart | `(value: InputValue, context: { e: CompositionEvent })` | trigger on compositionstart
enter | `(value: InputValue, context: { e: KeyboardEvent })` | \-
focus | `(value: InputValue, context: { e: FocusEvent })` | \-
keydown | `(value: InputValue, context: { e: KeyboardEvent })` | \-
keypress | `(value: InputValue, context: { e: KeyboardEvent })` | \-
keyup | `(value: InputValue, context: { e: KeyboardEvent })` | \-
compositionend | `(value: string, context: { e: CompositionEvent })` | trigger on compositionend
compositionstart | `(value: string, context: { e: CompositionEvent })` | trigger on compositionstart
enter | `(value: T, context: { e: KeyboardEvent })` | \-
focus | `(value: T, context: { e: FocusEvent })` | \-
keydown | `(value: T, context: { e: KeyboardEvent })` | \-
keypress | `(value: T, context: { e: KeyboardEvent })` | \-
keyup | `(value: T, context: { e: KeyboardEvent })` | \-
mouseenter | `(context: { e: MouseEvent })` | trigger on mouseenter
mouseleave | `(context: { e: MouseEvent })` | trigger on mouseleave
paste | `(context: { e: ClipboardEvent; pasteValue: string })` | \-
Expand Down
Loading