Merge branch 'next' of https://gitee.com/layui/layui-vue into next

This commit is contained in:
就眠儀式 2022-06-17 23:35:37 +08:00
commit 380ef4c713
3 changed files with 54 additions and 0 deletions

View File

@ -30,3 +30,9 @@
.layui-textarea::-webkit-input-placeholder { .layui-textarea::-webkit-input-placeholder {
line-height: 1.3; line-height: 1.3;
} }
.layui-texterea-show-count {
text-align: right;
color: inherit;
white-space: nowrap;
pointer-events: none;
}

View File

@ -5,6 +5,7 @@ export default {
</script> </script>
<script setup lang="ts"> <script setup lang="ts">
import { computed, useAttrs } from "vue";
import "./index.less"; import "./index.less";
export interface LayTextareaProps { export interface LayTextareaProps {
@ -12,12 +13,15 @@ export interface LayTextareaProps {
modelValue?: string; modelValue?: string;
placeholder?: string; placeholder?: string;
disabled?: boolean; disabled?: boolean;
showCount?: boolean;
} }
const props = defineProps<LayTextareaProps>(); const props = defineProps<LayTextareaProps>();
const emit = defineEmits(["update:modelValue", "input", "focus", "blur"]); const emit = defineEmits(["update:modelValue", "input", "focus", "blur"]);
const attrs = useAttrs();
const onInput = function (event: InputEvent) { const onInput = function (event: InputEvent) {
const inputElement = event.target as HTMLInputElement; const inputElement = event.target as HTMLInputElement;
emit("update:modelValue", inputElement.value); emit("update:modelValue", inputElement.value);
@ -31,11 +35,20 @@ const onFocus = function (event: FocusEvent) {
const onBlur = function () { const onBlur = function () {
emit("blur"); emit("blur");
}; };
const wordCount = computed(() => {
let count = String(props.modelValue?.length ?? 0);
if (attrs.maxlength) {
count += "/" + attrs.maxlength;
}
return count;
});
</script> </script>
<template> <template>
<textarea <textarea
:value="modelValue" :value="modelValue"
v-bind="$attrs"
:placeholder="placeholder" :placeholder="placeholder"
:name="name" :name="name"
:disabled="disabled" :disabled="disabled"
@ -45,4 +58,7 @@ const onBlur = function () {
@focus="onFocus" @focus="onFocus"
@blur="onBlur" @blur="onBlur"
></textarea> ></textarea>
<div v-if="showCount" class="layui-texterea-show-count">
{{ wordCount }}
</div>
</template> </template>

View File

@ -91,6 +91,37 @@ export default {
::: :::
::: title 显示字数
:::
::: demo
<template>
<lay-textarea placeholder="显示字数" v-model="data4" show-count></lay-textarea>
<br>
<lay-textarea placeholder="最大输入长度" v-model="data5" show-count maxlength="10"></lay-textarea>
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
const data4 = ref("");
const data5 = ref("");
return {
data4,
data5
}
}
}
</script>
:::
:::
::: title Textarea 属性 ::: title Textarea 属性
::: :::
@ -100,6 +131,7 @@ export default {
| ----------- | ------------- | -------------- | | ----------- | ------------- | -------------- |
| name | 原始属性 name | -- | | name | 原始属性 name | -- |
| placeholder | 提示信息 | -- | | placeholder | 提示信息 | -- |
| show-count | 显示字数 | `true` `false` |
| disabled | 禁用 | `true` `false` | | disabled | 禁用 | `true` `false` |
| v-model | 值 | -- | | v-model | 值 | -- |