3434 </div >
3535 <teleport to =" body" v-if =" teleportToBody && showDropdown" >
3636 <div ref =" dropdownEl" :style =" getDropdownPosition" :class =" {'shadow-none': isTop}"
37- class =" fixed z-50 w-full bg-white shadow-lg dark:shadow-black dark:bg-gray-700
37+ class =" fixed z-[5] w-full bg-white shadow-lg dark:shadow-black dark:bg-gray-700
3838 dark:border-gray-600 rounded-md py-1 text-base ring-1 ring-black ring-opacity-5 overflow-auto focus:outline-none sm:text-sm max-h-48" >
3939 <div
4040 v-for =" item in filteredItems"
@@ -202,6 +202,23 @@ watch(
202202 }
203203);
204204
205+ const handleScroll = () => {
206+ if (showDropdown .value && inputEl .value ) {
207+ const rect = inputEl .value .getBoundingClientRect ();
208+ const style = {
209+ left: ` ${rect .left }px ` ,
210+ top: isTop .value && dropdownHeight .value
211+ ? ` ${rect .top - dropdownHeight .value - 8 }px `
212+ : ` ${rect .bottom + 8 }px ` ,
213+ width: ` ${rect .width }px `
214+ };
215+
216+ if (dropdownEl .value ) {
217+ Object .assign (dropdownEl .value .style , style );
218+ }
219+ }
220+ };
221+
205222onMounted (() => {
206223 updateFromProps ();
207224
@@ -214,7 +231,11 @@ onMounted(() => {
214231 });
215232
216233 addClickListener ();
217-
234+
235+ // Add scroll listeners if teleportToBody is true
236+ if (props .teleportToBody ) {
237+ window .addEventListener (' scroll' , handleScroll , true );
238+ }
218239});
219240
220241const filteredItems = computed (() => {
@@ -268,6 +289,10 @@ const toogleItem = (item) => {
268289
269290onUnmounted (() => {
270291 removeClickListener ();
292+ // Remove scroll listeners if teleportToBody is true
293+ if (props .teleportToBody ) {
294+ window .removeEventListener (' scroll' , handleScroll , true );
295+ }
271296});
272297
273298const getDropdownPosition = computed (() => {
0 commit comments