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 controlled #633

Merged
merged 1 commit into from
Mar 9, 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
1 change: 0 additions & 1 deletion demo/pages/Input/index.axml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
placeholder="请输入内容"
allowClear
onChange="handleChange"
onClear="clear"
/>

<button onTap="clear" inline size="small">clear</button>
Expand Down
1 change: 1 addition & 0 deletions src/Input/InputBlur/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface InputBlurProps extends IBaseProps {
selectionStart: number;
selectionEnd: number;
cursor: number;
controlled: boolean;
maxLength: number;
inputClassName: string;
inputStyle: string;
Expand Down
1 change: 1 addition & 0 deletions src/Input/Textarea/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface TextareaProps extends IBaseProps {
autoHeight: boolean;
showCount: boolean;
allowClear: boolean;
controlled: boolean;
enableNative: boolean;
maxLength: number;
inputClassName: string;
Expand Down
1 change: 1 addition & 0 deletions src/Input/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ toc: 'content'
| 属性 | 说明 | 类型 | 默认值 |
| -----|-----|-----|-----|
| className | 类名| string | - |
| controlled | 有键盘输入问题,可使用 controlled="{{false}}" | boolean | - |
| defaultValue | 初始值 | string | - |
| disabled | 是否禁用 | boolean | false |
| maxLength | 最大长度 | number | 140 |
Expand Down
1 change: 1 addition & 0 deletions src/Input/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface InputProps extends IBaseProps {
enableNative: boolean;
confirmType: string;
confirmHold: string;
controlled: boolean;
alwaysSystem: boolean;
selectionStart: number;
selectionEnd: number;
Expand Down
3 changes: 3 additions & 0 deletions src/mixins/value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ export default ({
return equal(this.getValue(prevData), this.getValue());
},
isControlled() {
if ('controlled' in this.props) {
return this.props.controlled;
}
return valueKey in this.props;
},
updateControlled() {
Expand Down