Files
element-plus/packages/components/select/src/select-dropdown.vue
一只前端汪 3d7fcdadab fix(components): [select/v2] width of drop-down panel exceeds the input (#21910)
* fix(components): [select/V2] width of dropdown panel exceeds the input

* fix(components): [select/V2] width of drop-down panel exceeds the input

* fix: select constants

* fix: select

---------

Co-authored-by: 2586740555 <15972343+CYJ090915@user.noreply.gitee.com>
2025-08-29 15:10:36 +08:00

64 lines
1.6 KiB
Vue

<template>
<div
:class="[ns.b('dropdown'), ns.is('multiple', isMultiple), popperClass]"
:style="{ [isFitInputWidth ? 'width' : 'minWidth']: minWidth }"
>
<div v-if="$slots.header" :class="ns.be('dropdown', 'header')">
<slot name="header" />
</div>
<slot />
<div v-if="$slots.footer" :class="ns.be('dropdown', 'footer')">
<slot name="footer" />
</div>
</div>
</template>
<script lang="ts">
import { computed, defineComponent, inject, onMounted, ref } from 'vue'
import { useResizeObserver } from '@vueuse/core'
import { useNamespace } from '@element-plus/hooks'
import { selectKey } from './token'
import { BORDER_HORIZONTAL_WIDTH } from '@element-plus/constants'
export default defineComponent({
name: 'ElSelectDropdown',
componentName: 'ElSelectDropdown',
setup() {
const select = inject(selectKey)!
const ns = useNamespace('select')
// computed
const popperClass = computed(() => select.props.popperClass)
const isMultiple = computed(() => select.props.multiple)
const isFitInputWidth = computed(() => select.props.fitInputWidth)
const minWidth = ref('')
function updateMinWidth() {
const offsetWidth = select.selectRef?.offsetWidth
if (offsetWidth) {
minWidth.value = `${offsetWidth - BORDER_HORIZONTAL_WIDTH}px`
} else {
minWidth.value = ''
}
}
onMounted(() => {
// TODO: updatePopper
// popper.value.update()
updateMinWidth()
useResizeObserver(select.selectRef, updateMinWidth)
})
return {
ns,
minWidth,
popperClass,
isMultiple,
isFitInputWidth,
}
},
})
</script>