Skip to content

Commit

Permalink
feat(Textarea): support readonly (#1100)
Browse files Browse the repository at this point in the history
  • Loading branch information
anlyyao authored Sep 19, 2023
1 parent fefb8bc commit fcab982
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 1 deletion.
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

0 comments on commit fcab982

Please sign in to comment.