mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
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:
@@ -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() {
|
||||
|
||||
@@ -792,7 +792,7 @@ const useSelect = (props: SelectV2Props, emit: SelectV2EmitFn) => {
|
||||
states.isBeforeHide = false
|
||||
return nextTick(() => {
|
||||
if (~indexRef.value) {
|
||||
scrollToItem(states.hoveringIndex)
|
||||
scrollToItem(indexRef.value)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user