🐛(textarea): 修复拼字阶段触发 update:modelValue 的问题

This commit is contained in:
就眠儀式 2022-11-03 22:33:53 +08:00
parent e8078f76b1
commit 4a42c6c162
3 changed files with 20 additions and 5 deletions

View File

@ -73,7 +73,7 @@ var timer: any;
const getOption = (nodes: VNode[], newOptions: any[]) => {
nodes?.map((item) => {
let component = item.type as Component;
if(item.type.toString() == "Symbol(Fragment)") {
if (item.type.toString() == "Symbol(Fragment)") {
getOption(item.children as VNode[], newOptions);
} else {
if (component.name == LaySelectOption.name) {

View File

@ -25,7 +25,7 @@ import {
reactive,
h,
createTextVNode,
Fragment
Fragment,
} from "vue";
import { useResizeObserver } from "@vueuse/core";
import { TabData, TabInjectKey, TabPosition } from "./interface";
@ -47,7 +47,7 @@ const tabMap = reactive(new Map<number, TabData>());
const setItemInstanceBySlot = function (nodes: VNode[]) {
nodes?.map((item) => {
let component = item.type as Component;
if(item.type.toString() == "Symbol(Fragment)") {
if (item.type.toString() == "Symbol(Fragment)") {
setItemInstanceBySlot(item.children as VNode[]);
} else {
if (component.name == tabItem.name) {

View File

@ -6,7 +6,7 @@ export default {
<script setup lang="ts">
import { LayIcon } from "@layui/icons-vue";
import { computed } from "vue";
import { computed, ref } from "vue";
import "./index.less";
export interface TextareaProps {
@ -31,11 +31,15 @@ interface TextareaEmits {
}
const emit = defineEmits<TextareaEmits>();
const composing = ref(false);
const onInput = function (event: Event) {
const inputElement = event.target as HTMLInputElement;
emit("update:modelValue", inputElement.value);
emit("input", inputElement.value);
if (composing.value) {
return;
}
emit("update:modelValue", inputElement.value);
};
const onFocus = function (event: Event) {
@ -56,6 +60,15 @@ const onClear = function () {
emit("clear");
};
const onCompositionstart = () => {
composing.value = true;
};
const onCompositionend = (event: Event) => {
composing.value = false;
onInput(event);
};
const hasContent = computed(() => (props.modelValue as string)?.length > 0);
const wordCount = computed(() => {
@ -77,6 +90,8 @@ const wordCount = computed(() => {
:disabled="disabled"
:maxlength="maxlength"
:class="{ 'layui-textarea-disabled': disabled }"
@compositionstart="onCompositionstart"
@compositionend="onCompositionend"
@input="onInput"
@focus="onFocus"
@change="onChange"