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

fix(Input): defaultValue 未使用 #2393

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/input/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export default class Input extends SuperComponent {

lifetimes = {
ready() {
const { value } = this.properties;
this.updateValue(value == null ? '' : value);
const { value, defaultValue } = this.properties;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

组件库有提供 controlledProps 来实现组件的受控与非受控属性,可以直接使用,参考一下其他表单组件~

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

抱歉,我不是很明白您的意思,我是看文档中有 default-value 这个属性,并且标明了是 非受控属性,请问我应该如何使用它呢?

image

Copy link
Collaborator

@anlyyao anlyyao Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

抱歉,我不是很明白您的意思,我是看文档中有 default-value 这个属性,并且标明了是 非受控属性,请问我应该如何使用它呢?

image

表单组件大多有受控和非受控,使用上可以具体参考switch组件 line32,https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/switch/switch.ts

this.updateValue(value == null ? defaultValue : value);
},
};

Expand Down
1 change: 1 addition & 0 deletions src/input/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const props: TdInputProps = {
defaultValue: {
type: String,
optionalTypes: [Number],
value: '',
},
/** input 的类型。<br />具体释义:<br />`text` 文本输入键盘;<br />`number` 数字输入键盘;<br />`idcard` 身份证输入键盘;<br />`digit` 带小数点的数字键盘;<br />`safe-password` 密码安全输入键盘 <a href="https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/safe-password.html">指引</a>;<br />`nickname` 昵称输入键盘。<br />[小程序官方文档](https://developers.weixin.qq.com/miniprogram/dev/component/input.html) */
type: {
Expand Down
Loading