Files
element-plus/packages/hooks/use-calc-input-width/index.ts
micaiguai 2ccb268e82 fix(components): [select & select-v2] avoid line break when input is empty (#21844)
* fix(components): select

Give some space to the input field

* fix(components): [select]

fix(components): [select] Add the judgement of filterable

* fix(components): [select-v2] Give some space to the input field

Give some space to the input field

* fix(components): [select-v2 & select & input] Create constants/form.ts

Create a form.ts file to store the MINIMUM_INPUT_WIDTH constant
2025-08-22 16:10:21 +08:00

26 lines
668 B
TypeScript

import { computed, ref, shallowRef } from 'vue'
import { useResizeObserver } from '@vueuse/core'
import { MINIMUM_INPUT_WIDTH } from '@element-plus/constants'
export function useCalcInputWidth() {
const calculatorRef = shallowRef<HTMLElement>()
const calculatorWidth = ref(0)
const inputStyle = computed(() => ({
minWidth: `${Math.max(calculatorWidth.value, MINIMUM_INPUT_WIDTH)}px`,
}))
const resetCalculatorWidth = () => {
calculatorWidth.value =
calculatorRef.value?.getBoundingClientRect().width ?? 0
}
useResizeObserver(calculatorRef, resetCalculatorWidth)
return {
calculatorRef,
calculatorWidth,
inputStyle,
}
}