Files
element-plus/packages/hooks/use-calc-input-width/index.ts
qiang d416dd74b0 feat(components): [input-tag] new component (#18885)
* feat(components): [input-tag] add input-tag component

* feat: styles

* test: add test

* docs: add docs

* docs: updata

* docs: uopdata

* docs: updata

* fix: optimize the style when input too long text

* feat: add draggable attribute

* fix: regain focus after dragged

* fix: regain focus on dragend

* refactor: useDragTag

* fix: style of disabled

* refactor: rename event name

* refactor: move useCalcInputWidth to hooks

* feat: add aria-label
2024-11-29 10:50:21 +08:00

26 lines
639 B
TypeScript

import { computed, ref, shallowRef } from 'vue'
import { useResizeObserver } from '@vueuse/core'
export function useCalcInputWidth() {
const calculatorRef = shallowRef<HTMLElement>()
const calculatorWidth = ref(0)
const MINIMUM_INPUT_WIDTH = 11
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,
}
}