Skip to content

Commit

Permalink
fix(components): [input] input width change by clearable (element-plu…
Browse files Browse the repository at this point in the history
  • Loading branch information
MrWeilian committed Nov 8, 2022
1 parent 1b1b62f commit d93f265
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions packages/components/input/src/input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@
<!-- suffix slot -->
<span v-if="suffixVisible" :class="nsInput.e('suffix')">
<span :class="nsInput.e('suffix-inner')">
<el-icon
v-if="renderClear"
:class="[nsInput.e('icon'), nsInput.e('clear')]"
:style="clearStyle"
@mousedown.prevent="NOOP"
@click="clear"
>
<circle-close />
</el-icon>
<template
v-if="!showClear || !showPwdVisible || !isWordLimitVisible"
>
Expand All @@ -78,14 +87,6 @@
<component :is="suffixIcon" />
</el-icon>
</template>
<el-icon
v-if="showClear"
:class="[nsInput.e('icon'), nsInput.e('clear')]"
@mousedown.prevent="NOOP"
@click="clear"
>
<circle-close />
</el-icon>
<el-icon
v-if="showPwdVisible"
:class="[nsInput.e('icon'), nsInput.e('password')]"
Expand Down Expand Up @@ -262,21 +263,12 @@ const textareaStyle = computed<StyleValue>(() => [
const nativeInputValue = computed(() =>
isNil(props.modelValue) ? '' : String(props.modelValue)
)
const showClear = computed(
() =>
props.clearable &&
!inputDisabled.value &&
!props.readonly &&
!!nativeInputValue.value &&
(focused.value || hovering.value)
const showClear = computed(() => !!nativeInputValue.value)
const renderClear = computed(
() => props.clearable && !props.readonly && !inputDisabled.value
)
const showPwdVisible = computed(
() =>
props.showPassword &&
!inputDisabled.value &&
!props.readonly &&
!!nativeInputValue.value &&
(!!nativeInputValue.value || focused.value)
() => props.showPassword && !inputDisabled.value && !props.readonly
)
const isWordLimitVisible = computed(
() =>
Expand All @@ -298,12 +290,16 @@ const suffixVisible = computed(
() =>
!!slots.suffix ||
!!props.suffixIcon ||
showClear.value ||
props.clearable ||
props.showPassword ||
isWordLimitVisible.value ||
(!!validateState.value && needStatusIcon.value)
)
const clearStyle = computed<StyleValue>(() => [
{ visibility: showClear.value ? 'visible' : 'hidden' },
])
const [recordCursor, setCursor] = useCursor(input)
useResizeObserver(textarea, (entries) => {
Expand Down

0 comments on commit d93f265

Please sign in to comment.