fix(components): [select-v2] avoid invalid positioning when using filterable and default-first-option (#22725)

* fix: avoid invalid positioning

* fix: update

* fix: update

* test: add test case

* test: update
This commit is contained in:
Rainbow
2025-11-12 06:07:23 +08:00
committed by GitHub
parent 0723ec60ed
commit c03171e52d
2 changed files with 30 additions and 1 deletions

View File

@@ -145,6 +145,7 @@ const createSelect = (
:scrollbar-always-on="scrollbarAlwaysOn"
:teleported="teleported"
:tabindex="tabindex"
:default-first-option="defaultFirstOption"
${
options.methods && options.methods.filterMethod
? `:filter-method="filterMethod"`
@@ -196,6 +197,7 @@ const createSelect = (
popperAppendToBody: undefined,
teleported: undefined,
tabindex: undefined,
defaultFirstOption: false,
...(options.data && options.data()),
}
},
@@ -1583,6 +1585,33 @@ describe('Select', () => {
expect(result).toBeTruthy()
})
it('the scroll position of the dropdown should be correct when use filterable and default-first-option', async () => {
const options = Array.from({ length: 1000 }).map((_, idx) => ({
value: 999 - idx,
label: `options ${999 - idx}`,
}))
const wrapper = createSelect({
data() {
return {
value: 500,
options,
filterable: true,
defaultFirstOption: true,
}
},
})
await nextTick()
await wrapper.find(`.${WRAPPER_CLASS_NAME}`).trigger('click')
const optionsDoms = Array.from(
document.querySelectorAll(`.${OPTION_ITEM_CLASS_NAME}`)
)
const result = optionsDoms.some((option) => {
const text = option.textContent
return text === 'options 500'
})
expect(result).toBeTruthy()
})
it('emptyText error show', async () => {
const wrapper = createSelect({
data() {

View File

@@ -792,7 +792,7 @@ const useSelect = (props: SelectV2Props, emit: SelectV2EmitFn) => {
states.isBeforeHide = false
return nextTick(() => {
if (~indexRef.value) {
scrollToItem(states.hoveringIndex)
scrollToItem(indexRef.value)
}
})
}