element-plus/packages/select/src/select-dropdown.vue
jeremywu 2280dd5c5e
fix(project): fix/exporting-fix-for-volar (#849)
- Using `defineComponent` to wrap component up for Volar support, this should close #841
- Also made changes for some typing
- Removed `merge.ts` since `Object.assign` are now supported natively
2020-12-06 23:52:47 +08:00

62 lines
1.3 KiB
Vue

<template>
<div
class="el-select-dropdown"
:class="[{ 'is-multiple': isMultiple }, popperClass]"
:style="{ minWidth: minWidth }"
>
<slot></slot>
</div>
</template>
<script lang="ts">
import {
defineComponent,
computed,
onMounted,
onBeforeUnmount,
inject,
ref,
} from 'vue'
import { addResizeListener, removeResizeListener, ResizableElement } from '@element-plus/utils/resize-event'
import {
selectKey,
} from './token'
export default defineComponent({
name: 'ElSelectDropdown',
componentName: 'ElSelectDropdown',
setup() {
const select = inject(selectKey)
// computed
const popperClass = computed(() => select.props.popperClass)
const isMultiple = computed(() => select.props.multiple)
const minWidth = ref('')
function updateMinWidth() {
minWidth.value = select.selectWrapper?.getBoundingClientRect().width + 'px'
}
onMounted(() => {
// TODO: updatePopper
// popper.value.update()
addResizeListener(select.selectWrapper as ResizableElement, updateMinWidth)
})
onBeforeUnmount(() => {
removeResizeListener(select.selectWrapper as ResizableElement, updateMinWidth)
})
return {
minWidth,
popperClass,
isMultiple,
}
},
})
</script>