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(Textarea): support readonly #1100

Merged
merged 1 commit into from
Sep 19, 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
5 changes: 5 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ export type CSSSelector = string;
export interface KeysType {
value?: string;
label?: string;
disabled?: string;
}

export interface TreeKeysType extends KeysType {
children?: string;
}

export interface HTMLElementAttributes {
Expand Down
2 changes: 2 additions & 0 deletions src/textarea/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export default {
type: String,
default: undefined,
},
/** 只读状态 */
readonly: Boolean,
/** 文本框值 */
value: {
type: [String, Number] as PropType<TdTextareaProps['value']>,
Expand Down
1 change: 1 addition & 0 deletions src/textarea/textarea.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ maxcharacter | Number | - | \- | N
maxlength | Number | - | \- | N
name | String | - | \- | N
placeholder | String | undefined | \- | N
readonly | Boolean | false | \- | N
value | String / Number | - | `v-model` and `v-model:value` is supported。Typescript:`TextareaValue` `type TextareaValue = string`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/textarea/type.ts) | N
defaultValue | String / Number | - | uncontrolled property。Typescript:`TextareaValue` `type TextareaValue = string`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/textarea/type.ts) | N
onBlur | Function | | Typescript:`(value: TextareaValue, context: { e: FocusEvent }) => void`<br/> | N
Expand Down
1 change: 1 addition & 0 deletions src/textarea/textarea.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ maxcharacter | Number | - | 用户最多可以输入的字符个数,一个中
maxlength | Number | - | 用户最多可以输入的字符个数 | N
name | String | - | 名称,HTML 元素原生属性 | N
placeholder | String | undefined | 占位符 | N
readonly | Boolean | false | 只读状态 | N
value | String / Number | - | 文本框值。支持语法糖 `v-model` 或 `v-model:value`。TS 类型:`TextareaValue` `type TextareaValue = string`。[详细类型定义](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/textarea/type.ts) | N
defaultValue | String / Number | - | 文本框值。非受控属性。TS 类型:`TextareaValue` `type TextareaValue = string`。[详细类型定义](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/textarea/type.ts) | N
onBlur | Function | | TS 类型:`(value: TextareaValue, context: { e: FocusEvent }) => void`<br/>失去焦点时触发 | N
Expand Down
4 changes: 3 additions & 1 deletion src/textarea/textarea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
:maxlength="maxlength"
:disabled="disabled"
:placeholder="placeholder"
:readonly="readonly"
@focus="handleFocus"
@blur="handleBlur"
@input="handleInput"
Expand All @@ -26,7 +27,7 @@
</template>

<script lang="ts">
import { computed, ref, onMounted, defineComponent, getCurrentInstance, toRefs, nextTick, watch } from 'vue';
import { computed, ref, onMounted, defineComponent, getCurrentInstance, toRefs, nextTick, watch, readonly } from 'vue';
import { renderTNode, TNode, getCharacterLength, useVModel } from '../shared';
import config from '../config';
import TextareaProps from './props';
Expand Down Expand Up @@ -64,6 +65,7 @@ export default defineComponent({
`${componentName}__wrapper-inner`,
{
[`${componentName}--disabled`]: disabled.value,
[`${componentName}--readonly`]: props.readonly,
},
]);
const internalInstance = getCurrentInstance();
Expand Down
5 changes: 5 additions & 0 deletions src/textarea/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ export interface TdTextareaProps {
* 占位符
*/
placeholder?: string;
/**
* 只读状态
* @default false
*/
readonly?: boolean;
/**
* 文本框值
*/
Expand Down