@@ -191,6 +191,23 @@ export default {
191191 }
192192 // When a valid value is selected, show all options
193193 return this .options
194+ },
195+ apiOptionsCount () {
196+ if (this .defaultOption ) {
197+ const defaultOptionValue = this .defaultOption [this .optionValueKey ]
198+ return this .options .filter (option => option[this .optionValueKey ] !== defaultOptionValue).length
199+ }
200+ return this .options .length
201+ },
202+ preselectedMatchValue () {
203+ // Extract the first value from preselectedOptionValue if it's an array, otherwise return the value itself
204+ if (! this .preselectedOptionValue ) return null
205+ return Array .isArray (this .preselectedOptionValue ) ? this .preselectedOptionValue [0 ] : this .preselectedOptionValue
206+ },
207+ preselectedMatch () {
208+ // Find the matching option for the preselected value
209+ if (! this .preselectedMatchValue ) return null
210+ return this .options .find (entry => entry[this .optionValueKey ] === this .preselectedMatchValue ) || null
194211 }
195212 },
196213 watch: {
@@ -246,13 +263,10 @@ export default {
246263 this .resetPreselectedOptionValue ()
247264 return
248265 }
249- const matchValue = Array .isArray (this .preselectedOptionValue ) ? this .preselectedOptionValue [0 ] : this .preselectedOptionValue
250- const match = this .options .find (entry => entry[this .optionValueKey ] === matchValue)
251- if (! match) {
266+ if (! this .preselectedMatch ) {
252267 this .successiveFetches ++
253268 // Exclude defaultOption from count when comparing with totalCount
254- const apiOptionsCount = this .getApiOptionsCount ()
255- if (apiOptionsCount < this .totalCount ) {
269+ if (this .apiOptionsCount < this .totalCount ) {
256270 this .fetchItems ()
257271 } else {
258272 this .resetPreselectedOptionValue ()
@@ -274,14 +288,6 @@ export default {
274288 this .preselectedOptionValue = null
275289 this .successiveFetches = 0
276290 },
277- getApiOptionsCount () {
278- // Return count of options excluding the locally added defaultOption
279- if (this .defaultOption ) {
280- const defaultOptionValue = this .defaultOption [this .optionValueKey ]
281- return this .options .filter (option => option[this .optionValueKey ] !== defaultOptionValue).length
282- }
283- return this .options .length
284- },
285291 autoSelectFirstOptionIfNeeded () {
286292 if (! this .selectFirstOption || this .hasAutoSelectedFirst ) {
287293 return
@@ -331,8 +337,7 @@ export default {
331337 onScroll (e ) {
332338 const nearBottom = e .target .scrollTop + e .target .clientHeight >= e .target .scrollHeight - 10
333339 // Exclude defaultOption from count when comparing with totalCount
334- const apiOptionsCount = this .getApiOptionsCount ()
335- const hasMore = apiOptionsCount < this .totalCount
340+ const hasMore = this .apiOptionsCount < this .totalCount
336341 if (nearBottom && hasMore && ! this .loading ) {
337342 this .fetchItems ()
338343 }
0 commit comments