element-plus/packages/components/select/src/select-dropdown.vue

54 lines
1.3 KiB
Vue

<template>
<div
:class="[ns.b('dropdown'), ns.is('multiple', isMultiple), popperClass]"
:style="{ [isFitInputWidth ? 'width' : 'minWidth']: minWidth }"
>
<slot />
</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'
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() {
minWidth.value = `${
select.selectWrapper?.getBoundingClientRect().width
}px`
}
onMounted(() => {
// TODO: updatePopper
// popper.value.update()
updateMinWidth()
useResizeObserver(select.selectWrapper, updateMinWidth)
})
return {
ns,
minWidth,
popperClass,
isMultiple,
isFitInputWidth,
}
},
})
</script>