Files
element-plus/docs/examples/select-v2/custom-footer.vue
Noblet Ouways 2f17df1209 style(eslint-config): newline before import type (#21036)
* perf: change to import-x

* feat: add rules

* chore: fix rule

* chore: fix

* chore: fix

* chore: fix

* style: `pnpm lint:fix`

* Revert "style: `pnpm lint:fix`"

This reverts commit db0116a288299c507e3cfc4d7a22e2207265d920.

* Revert "chore: fix"

This reverts commit 69c82a90c01525e38180be4c21e8ef5602512318.

* chore: fix

* style: `pnpm lint:fix`

* fix: lint

* chore: `pnpm format`
2025-06-16 15:37:12 +08:00

83 lines
1.8 KiB
Vue

<template>
<el-select-v2
ref="select"
v-model="value"
:options="options"
placeholder="Select"
style="width: 240px"
>
<template #footer>
<el-button v-if="!isAdding" text bg size="small" @click="onAddOption">
Add an option
</el-button>
<div v-else class="select-footer">
<el-input
v-model="optionName"
class="option-input"
placeholder="input option name"
size="small"
/>
<div>
<el-button type="primary" size="small" @click="onConfirm">
confirm
</el-button>
<el-button size="small" @click="clear">cancel</el-button>
</div>
</div>
</template>
</el-select-v2>
</template>
<script lang="ts" setup>
import { nextTick, ref } from 'vue'
import { ElSelectV2 } from 'element-plus'
import type { CheckboxValueType } from 'element-plus'
const initials = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
const select = ref<InstanceType<typeof ElSelectV2>>()
const isAdding = ref(false)
const value = ref<CheckboxValueType[]>([])
const optionName = ref('')
const options = ref(
Array.from({ length: 1000 }).map((_, idx) => ({
value: `Option ${idx + 1}`,
label: `${initials[idx % 10]}${idx}`,
}))
)
const onAddOption = () => {
isAdding.value = true
}
const onConfirm = () => {
if (optionName.value) {
options.value.push({
label: optionName.value,
value: optionName.value,
})
clear()
nextTick(() => {
select.value?.scrollTo(options.value.length - 1)
})
}
}
const clear = () => {
optionName.value = ''
isAdding.value = false
}
</script>
<style>
.select-footer {
display: flex;
flex-direction: column;
.option-input {
width: 100%;
margin-bottom: 8px;
}
}
</style>