🌀(component): 优化 tag-input 组件 disabled 状态优化

This commit is contained in:
就眠儀式 2022-12-07 22:24:42 +08:00
parent 70b35e8dca
commit cf3695af6b
6 changed files with 58 additions and 44 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@layui/layui-vue", "name": "@layui/layui-vue",
"version": "1.7.10", "version": "1.7.11",
"author": "就眠儀式", "author": "就眠儀式",
"license": "MIT", "license": "MIT",
"description": "a component library for Vue 3 base on layui-vue", "description": "a component library for Vue 3 base on layui-vue",

View File

@ -266,17 +266,22 @@ const update = () => {
}; };
const horizontalScroll = (e: WheelEvent) => { const horizontalScroll = (e: WheelEvent) => {
e.preventDefault() e.preventDefault();
const navSize = getNavSize(); const navSize = getNavSize();
const containerSize = navRef.value![`offset${sizeName.value}`]; const containerSize = navRef.value![`offset${sizeName.value}`];
const currentOffset = navOffset.value; const currentOffset = navOffset.value;
const scrollNextSize = scrollNextRef.value?.[`offset${sizeName.value}`] ?? 0; const scrollNextSize = scrollNextRef.value?.[`offset${sizeName.value}`] ?? 0;
const direction = Math.abs(e.deltaX) >= Math.abs(e.deltaY) ? e.deltaX : e.deltaY const direction =
const distance = 50 * (direction > 0 ? 1 : -1) Math.abs(e.deltaX) >= Math.abs(e.deltaY) ? e.deltaX : e.deltaY;
const newOffset = Math.max(currentOffset + distance, 0) const distance = 50 * (direction > 0 ? 1 : -1);
if ((navSize - currentOffset <= containerSize - scrollNextSize && direction > 0)) return; const newOffset = Math.max(currentOffset + distance, 0);
navOffset.value = newOffset if (
} navSize - currentOffset <= containerSize - scrollNextSize &&
direction > 0
)
return;
navOffset.value = newOffset;
};
const renderTabIcon = (attrs: Record<string, unknown>) => { const renderTabIcon = (attrs: Record<string, unknown>) => {
const tab = attrs.tabData as TabData; const tab = attrs.tabData as TabData;

View File

@ -108,6 +108,9 @@
.layui-tag-input-inner-input { .layui-tag-input-inner-input {
height: @@height - (@@inner-padding + @tag-input-boeder)* 2; height: @@height - (@@inner-padding + @tag-input-boeder)* 2;
vertical-align: middle; vertical-align: middle;
&:disabled {
background: transparent;
}
} }
.layui-tag-input-inner { .layui-tag-input-inner {

View File

@ -300,22 +300,22 @@ defineExpose({
</template> </template>
</LayToopTip> </LayToopTip>
</template> </template>
<input <input
ref="inputRefEl" ref="inputRefEl"
class="layui-tag-input-inner-input" class="layui-tag-input-inner-input"
:style="inputStyle" :style="inputStyle"
:disabled="(disabled || disabledInput)" :disabled="disabled || disabledInput"
:placeholder="placeholder" :placeholder="placeholder"
:readonly="readonly" :readonly="readonly"
@keydown.enter="handleEnter" @keydown.enter="handleEnter"
@keyup="handleBackspaceKeyUp" @keyup="handleBackspaceKeyUp"
@input="handleInput" @input="handleInput"
@focus="handleFocus" @focus="handleFocus"
@blur="handleBlur" @blur="handleBlur"
@compositionstart="handleComposition" @compositionstart="handleComposition"
@compositionupdate="handleComposition" @compositionupdate="handleComposition"
@compositionend="handleComposition" @compositionend="handleComposition"
/> />
</span> </span>
<span <span
v-if="allowClear && tagData?.length && !disabled" v-if="allowClear && tagData?.length && !disabled"

View File

@ -7,7 +7,7 @@ export default {
<script setup lang="ts"> <script setup lang="ts">
import { LayIcon } from "@layui/icons-vue"; import { LayIcon } from "@layui/icons-vue";
import { computed, ref, watch } from "vue"; import { computed, ref, watch } from "vue";
import {isObject } from "@vueuse/shared" import { isObject } from "@vueuse/shared";
import "./index.less"; import "./index.less";
export interface TextareaProps { export interface TextareaProps {
@ -18,7 +18,7 @@ export interface TextareaProps {
showCount?: boolean; showCount?: boolean;
allowClear?: boolean; allowClear?: boolean;
maxlength?: number; maxlength?: number;
autosize?: boolean | { minHeight: number, maxHeight: number }; autosize?: boolean | { minHeight: number; maxHeight: number };
} }
const props = defineProps<TextareaProps>(); const props = defineProps<TextareaProps>();
@ -82,18 +82,24 @@ const wordCount = computed(() => {
return count; return count;
}); });
watch([() => props.modelValue, textareaRef], () => { watch(
if (!textareaRef.value || !props.autosize) return; [() => props.modelValue, textareaRef],
const height: number = textareaRef.value?.scrollHeight + 2; // () => {
if (isObject(props.autosize)) { if (!textareaRef.value || !props.autosize) return;
const { minHeight, maxHeight } = props.autosize; const height: number = textareaRef.value?.scrollHeight + 2; //
if (height < minHeight || height > maxHeight) return; if (isObject(props.autosize)) {
const { minHeight, maxHeight } = props.autosize;
if (height < minHeight || height > maxHeight) return;
}
textareaRef.value!.style.height = "1px";
textareaRef.value!.style.height = `${
textareaRef.value?.scrollHeight + 2
}px`;
},
{
immediate: true,
} }
textareaRef.value!.style.height = '1px' );
textareaRef.value!.style.height = `${textareaRef.value?.scrollHeight + 2}px`
}, {
immediate: true,
})
</script> </script>
<template> <template>

View File

@ -40,18 +40,18 @@ export const isArrayChildren = (
export function convertSlotName(vm: ComponentInternalInstance, name: string) { export function convertSlotName(vm: ComponentInternalInstance, name: string) {
const camelCaseName = camelCase(name); const camelCaseName = camelCase(name);
const kebabCaseName = kebabCase(name); const kebabCaseName = kebabCase(name);
return vm.slots[camelCaseName] return vm.slots[camelCaseName]
? camelCaseName ? camelCaseName
: vm.slots[kebabCaseName] : vm.slots[kebabCaseName]
? kebabCaseName ? kebabCaseName
: name : name;
} }
export function camelCase(str: string) { export function camelCase(str: string) {
return str.replace(/-(\w)/g, (_, c) => (c ? c.toUpperCase() : '')) return str.replace(/-(\w)/g, (_, c) => (c ? c.toUpperCase() : ""));
} }
export function kebabCase(key: string) { export function kebabCase(key: string) {
const result = key.replace(/([A-Z])/g, ' $1').trim(); const result = key.replace(/([A-Z])/g, " $1").trim();
return result.split(' ').join('-').toLowerCase() return result.split(" ").join("-").toLowerCase();
} }