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): add props textareaAttrs for textarea #3303

Merged
merged 2 commits into from
Sep 20, 2024
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: 1 addition & 0 deletions packages/web-vue/components/textarea/README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ description: Multi-line plain text edit control, suitable for a paragraph of opi
|auto-size|Whether to make the textarea adapt to the height of the content|`boolean \| { minRows?: number; maxRows?: number }`|`false`||
|word-length|Calculation method of word length|`(value: string) => number`|`-`||
|word-slice|Character interception method, used together with wordLength|`(value: string, maxLength: number) => string`|`-`|2.12.0|
|textarea-attrs|Attributes passed to textarea|`Record<string, any>`|`-`||
### `<textarea>` Events

|Event Name|Description|Parameters|
Expand Down
1 change: 1 addition & 0 deletions packages/web-vue/components/textarea/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ description: 多行纯文本编辑控件,适用于评论或反馈表单中的
|auto-size|是否让文本框自适应内容高度|`boolean \| { minRows?: number; maxRows?: number }`|`false`||
|word-length|字符长度的计算方法|`(value: string) => number`|`-`||
|word-slice|字符截取方法,同 wordLength 一起使用|`(value: string, maxLength: number) => string`|`-`|2.12.0|
|textarea-attrs|透传给 textarea 的属性|`Record<string, any>`|`-`||
### `<textarea>` Events

|事件名|描述|参数|
Expand Down
21 changes: 20 additions & 1 deletion packages/web-vue/components/textarea/textarea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<resize-observer @resize="handleResize">
<textarea
ref="textareaRef"
v-bind="getTextareaAttrs($attrs)"
v-bind="mergeTextareaAttrs"
:disabled="mergedDisabled"
:class="prefixCls"
:style="textareaStyle"
Expand Down Expand Up @@ -163,6 +163,13 @@ export default defineComponent({
wordSlice: {
type: Function as PropType<(value: string, maxLength: number) => string>,
},
/**
* @zh 透传给 textarea 的属性
* @en Attributes passed to textarea
*/
textareaAttrs: {
type: Object as PropType<Record<string, any>>,
},
},
emits: {
'update:modelValue': (value: string) => true,
Expand Down Expand Up @@ -385,6 +392,17 @@ export default defineComponent({
omit(attrs, INPUT_EVENTS);
const getTextareaAttrs = (attr: Record<string, any>) =>
pick(attrs, INPUT_EVENTS);
const textareaAttrs = getTextareaAttrs(attrs);
const mergeTextareaAttrs = computed(() => {
const attrs = {
...textareaAttrs,
...props.textareaAttrs,
};
if (mergedError.value) {
attrs['aria-invalid'] = true;
}
return attrs;
});

const wrapperCls = computed(() => [
`${prefixCls}-wrapper`,
Expand Down Expand Up @@ -499,6 +517,7 @@ export default defineComponent({
valueLength,
computedMaxLength,
mergedDisabled,
mergeTextareaAttrs,
getWrapperAttrs,
getTextareaAttrs,
handleInput,
Expand Down
Loading