|
1 | 1 | <script lang="ts"> |
2 | | -import type { InputHTMLAttributes } from 'vue' |
| 2 | +import type { InputHTMLAttributes, ComputedRef } from 'vue' |
3 | 3 | import type { VariantProps } from 'tailwind-variants' |
4 | 4 | import type { ComboboxRootProps, ComboboxRootEmits, ComboboxContentProps, ComboboxContentEmits, ComboboxArrowProps } from 'reka-ui' |
5 | 5 | import type { AppConfig } from '@nuxt/schema' |
@@ -103,7 +103,7 @@ export interface InputMenuProps<T extends ArrayOrNested<InputMenuItem> = ArrayOr |
103 | 103 | * Render the menu in a portal. |
104 | 104 | * @defaultValue true |
105 | 105 | */ |
106 | | - portal?: boolean |
| 106 | + portal?: boolean | string | HTMLElement |
107 | 107 | /** |
108 | 108 | * When `items` is an array of objects, select the field to use as the value instead of the object itself. |
109 | 109 | * @defaultValue undefined |
@@ -176,7 +176,7 @@ export interface InputMenuSlots< |
176 | 176 | </script> |
177 | 177 |
|
178 | 178 | <script setup lang="ts" generic="T extends ArrayOrNested<InputMenuItem>, VK extends GetItemKeys<T> | undefined = undefined, M extends boolean = false"> |
179 | | -import { computed, ref, toRef, onMounted, toRaw, nextTick } from 'vue' |
| 179 | +import { computed, ref, toRef, onMounted, toRaw, nextTick, inject } from 'vue' |
180 | 180 | import { ComboboxRoot, ComboboxArrow, ComboboxAnchor, ComboboxInput, ComboboxTrigger, ComboboxPortal, ComboboxContent, ComboboxViewport, ComboboxEmpty, ComboboxGroup, ComboboxLabel, ComboboxSeparator, ComboboxItem, ComboboxItemIndicator, TagsInputRoot, TagsInputItem, TagsInputItemText, TagsInputItemDelete, TagsInputInput, useForwardPropsEmits, useFilter } from 'reka-ui' |
181 | 181 | import { defu } from 'defu' |
182 | 182 | import { isEqual } from 'ohash/utils' |
@@ -354,6 +354,10 @@ function isInputItem(item: InputMenuItem): item is _InputMenuItem { |
354 | 354 | defineExpose({ |
355 | 355 | inputRef |
356 | 356 | }) |
| 357 | +
|
| 358 | +const injectedPortalTarget = inject<ComputedRef<string | HTMLElement> | undefined>('portalTarget') |
| 359 | +const portalTarget = computed(() => typeof props.portal === 'string' ? props.portal : injectedPortalTarget?.value ?? 'body') |
| 360 | +const portalDisabled = computed(() => typeof props.portal === 'boolean' ? !props.portal : false) |
357 | 361 | </script> |
358 | 362 |
|
359 | 363 | <!-- eslint-disable vue/no-template-shadow --> |
@@ -452,7 +456,7 @@ defineExpose({ |
452 | 456 | </ComboboxTrigger> |
453 | 457 | </ComboboxAnchor> |
454 | 458 |
|
455 | | - <ComboboxPortal :disabled="!portal"> |
| 459 | + <ComboboxPortal :disabled="portalDisabled" :to="portalTarget"> |
456 | 460 | <ComboboxContent :class="ui.content({ class: props.ui?.content })" v-bind="contentProps"> |
457 | 461 | <ComboboxEmpty :class="ui.empty({ class: props.ui?.empty })"> |
458 | 462 | <slot name="empty" :search-term="searchTerm"> |
|
0 commit comments