Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions docs/content/docs/2.components/context-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,43 @@ slots:
:div{class="flex items-center justify-center rounded-md border border-dashed border-accented text-sm aspect-video w-72"}[Right click here]
::

### Unmount :badge{label="Soon" class="align-text-top"}

Use the `unmount-on-hide` prop to prevent the ContextMenu's content and its sub menus from being unmounted when it is closed. Defaults to `true`.

::component-code
---
prettier: true
collapse: true
ignore:
- items
- ui.content
external:
- items
externalTypes:
- ContextMenuItem[]
props:
unmountOnHide: false
items:
- label: System
icon: i-lucide-monitor
- label: Light
icon: i-lucide-sun
- label: Dark
icon: i-lucide-moon
ui:
content: 'w-48'
slots:
default: |

<div class="flex items-center justify-center rounded-md border border-dashed border-accented text-sm aspect-video w-72">
Right click here
</div>
---

:div{class="flex items-center justify-center rounded-md border border-dashed border-accented text-sm aspect-video w-72"}[Right click here]
::

## Examples

### With checkbox items
Expand Down
35 changes: 35 additions & 0 deletions docs/content/docs/2.components/dropdown-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,41 @@ slots:
:u-button{label="Open" icon="i-lucide-menu" color="neutral" variant="outline"}
::

### Unmount :badge{label="Soon" class="align-text-top"}

Use the `unmount-on-hide` prop to prevent the DropdownMenu's content and its sub menus from being unmounted when it is closed. Defaults to `true`.

::component-code
---
prettier: true
collapse: true
ignore:
- items
- ui.content
external:
- items
externalTypes:
- DropdownMenuItem[]
props:
unmountOnHide: false
items:
- label: Profile
icon: i-lucide-user
- label: Billing
icon: i-lucide-credit-card
- label: Settings
icon: i-lucide-cog
ui:
content: 'w-48'
slots:
default: |

<UButton label="Open" icon="i-lucide-menu" color="neutral" variant="outline" />
---

:u-button{label="Open" icon="i-lucide-menu" color="neutral" variant="outline"}
::

## Examples

### With checkbox items
Expand Down
29 changes: 29 additions & 0 deletions docs/content/docs/2.components/input-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,35 @@ props:
---
::

### Unmount :badge{label="Soon" class="align-text-top"}

Use the `unmount-on-hide` prop to prevent the content from being unmounted when the InputMenu is closed. Defaults to `true`.

::component-code
---
prettier: true
ignore:
- items
- modelValue
- unmountOnHide
external:
- items
- modelValue
props:
modelValue: 'Backlog'
unmountOnHide: false
items:
- Backlog
- Todo
- In Progress
- Done
---
::

::note
This prop has no effect when `mode` is set to `autocomplete`.
::

### Color

Use the `color` prop to change the ring color when the InputMenu is focused.
Expand Down
31 changes: 31 additions & 0 deletions docs/content/docs/2.components/popover.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,37 @@ name: 'popover-dismissible-example'
---
::

### Unmount :badge{label="Soon" class="align-text-top"}

Use the `unmount-on-hide` prop to prevent the Popover's content from being unmounted when it is closed. Defaults to `true`.

::component-code
---
prettier: true
ignore:
- title
props:
unmountOnHide: false
slots:
default: |

<UButton label="Open" color="neutral" variant="subtle" />

content: |

<Placeholder class="size-48 m-4 inline-flex" />
---

:u-button{label="Open" color="neutral" variant="subtle"}

#content
:placeholder{class="size-48 m-4 inline-flex"}
::

::note
This prop only applies to the `click` mode. The `hover` mode uses the Reka UI `HoverCard` which has no such option.
::

## Examples

### Control open state
Expand Down
27 changes: 27 additions & 0 deletions docs/content/docs/2.components/select-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,33 @@ props:
---
::

### Unmount :badge{label="Soon" class="align-text-top"}

Use the `unmount-on-hide` prop to prevent the content from being unmounted when the SelectMenu is closed. Defaults to `true`.

::component-code
---
prettier: true
ignore:
- items
- modelValue
- class
- unmountOnHide
external:
- items
- modelValue
props:
modelValue: 'Backlog'
unmountOnHide: false
items:
- Backlog
- Todo
- In Progress
- Done
class: 'w-48'
---
::

### Color

Use the `color` prop to change the ring color when the SelectMenu is focused.
Expand Down
7 changes: 4 additions & 3 deletions src/runtime/components/ContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface ContextMenuItem extends Omit<LinkProps, 'type' | 'raw' | 'custo
[key: string]: any
}

export interface ContextMenuProps<T extends ArrayOrNested<ContextMenuItem> = ArrayOrNested<ContextMenuItem>> extends Omit<ContextMenuRootProps, 'dir' | 'unmountOnHide'> {
export interface ContextMenuProps<T extends ArrayOrNested<ContextMenuItem> = ArrayOrNested<ContextMenuItem>> extends Omit<ContextMenuRootProps, 'dir'> {
/**
* @defaultValue 'md'
*/
Expand Down Expand Up @@ -127,7 +127,8 @@ const _props = withDefaults(defineProps<ContextMenuProps<T>>(), {
modal: true,
externalIcon: true,
labelKey: 'label',
descriptionKey: 'description'
descriptionKey: 'description',
unmountOnHide: true
})
const emits = defineEmits<ContextMenuEmits>()
const slots = defineSlots<ContextMenuSlots<T>>()
Expand All @@ -136,7 +137,7 @@ const props = useComponentProps<ContextMenuProps<T>>('contextMenu', _props)

const appConfig = useAppConfig() as ContextMenu['AppConfig']

const rootProps = useForwardProps(props, ['open', 'pressOpenDelay', 'modal'], emits)
const rootProps = useForwardProps(props, ['open', 'pressOpenDelay', 'modal', 'unmountOnHide'], emits)
const contentProps = toRef(() => props.content)
const getProxySlots = () => omit(slots, ['default'])

Expand Down
7 changes: 4 additions & 3 deletions src/runtime/components/DropdownMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export interface DropdownMenuItem extends Omit<LinkProps, 'type' | 'raw' | 'cust
[key: string]: any
}

export interface DropdownMenuProps<T extends ArrayOrNested<DropdownMenuItem> = ArrayOrNested<DropdownMenuItem>> extends Omit<DropdownMenuRootProps, 'dir' | 'unmountOnHide'> {
export interface DropdownMenuProps<T extends ArrayOrNested<DropdownMenuItem> = ArrayOrNested<DropdownMenuItem>> extends Omit<DropdownMenuRootProps, 'dir'> {
/**
* @defaultValue 'md'
*/
Expand Down Expand Up @@ -161,7 +161,8 @@ const _props = withDefaults(defineProps<DropdownMenuProps<T>>(), {
labelKey: 'label',
descriptionKey: 'description',
filter: false,
ignoreFilter: false
ignoreFilter: false,
unmountOnHide: true
})
const emits = defineEmits<DropdownMenuEmits>()
const slots = defineSlots<DropdownMenuSlots<T>>()
Expand All @@ -172,7 +173,7 @@ const props = useComponentProps<DropdownMenuProps<T>>('dropdownMenu', _props)

const appConfig = useAppConfig() as DropdownMenu['AppConfig']

const rootProps = useForwardProps(props, ['defaultOpen', 'open', 'modal'], emits)
const rootProps = useForwardProps(props, ['defaultOpen', 'open', 'modal', 'unmountOnHide'], emits)
const contentProps = toRef(() => defu(props.content, { side: 'bottom', sideOffset: 8, collisionPadding: 8 }) as DropdownMenuContentProps)
const arrowProps = toRef(() => defu(props.arrow, { rounded: true }) as DropdownMenuArrowProps)
const getProxySlots = () => omit(slots, ['default'])
Expand Down
28 changes: 25 additions & 3 deletions src/runtime/components/DropdownMenuContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ type DropdownMenuContentSlots<
</script>

<script setup lang="ts" generic="T extends ArrayOrNested<DropdownMenuItem>">
import { computed, ref, toRef } from 'vue'
import { computed, ref, toRef, useTemplateRef, watch } from 'vue'
import { defu } from 'defu'
import { DropdownMenuPortal, DropdownMenuContent, DropdownMenuItem as RekaDropdownMenuItem, DropdownMenuGroup, DropdownMenuSeparator, DropdownMenuCheckboxItem, DropdownMenuItemIndicator, DropdownMenuLabel, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuFilter, useForwardPropsEmits } from 'reka-ui'
import { DropdownMenuPortal, DropdownMenuContent, DropdownMenuItem as RekaDropdownMenuItem, DropdownMenuGroup, DropdownMenuSeparator, DropdownMenuCheckboxItem, DropdownMenuItemIndicator, DropdownMenuLabel, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuFilter, injectDropdownMenuRootContext, useForwardPropsEmits } from 'reka-ui'
import { reactiveOmit, createReusableTemplate } from '@vueuse/core'
import { useAppConfig } from '#imports'
import { FieldGroupReset } from '../composables/useFieldGroup'
Expand Down Expand Up @@ -97,6 +97,27 @@ const searchTerm = computed({
})

const inputProps = toRef(() => defu(props.filter, { placeholder: t('dropdownMenu.search'), variant: 'none' }) as Omit<InputProps, 'modelValue' | 'defaultValue'>)
const inputRef = useTemplateRef('inputRef')

// With `unmountOnHide: false` the content stays mounted while closed, so the input's
// `autofocus` only runs on the first open. Focus it again on each open, after Reka's own focus.
function onOpenAutoFocus(event: Event) {
if (!props.filter || inputProps.value.autofocus === false || event.defaultPrevented) {
return
}

setTimeout(() => inputRef.value?.inputRef?.focus(), inputProps.value.autofocusDelay ?? 0)
}

// A sub menu's search lives in this component, which stays mounted with the root content
// when `unmountOnHide` is `false`. Reset it when the menu opens again, as a remount would.
if (props.sub) {
watch(injectDropdownMenuRootContext().open, (open) => {
if (open) {
_searchTerm.value = ''
}
})
}

const portalProps = usePortal(toRef(() => props.portal))
const contentProps = useForwardPropsEmits(reactiveOmit(props, 'sub', 'items', 'portal', 'labelKey', 'descriptionKey', 'checkedIcon', 'loadingIcon', 'externalIcon', 'size', 'filter', 'filterFields', 'ignoreFilter', 'searchTerm', 'class', 'ui', 'uiOverride'), emits)
Expand Down Expand Up @@ -168,9 +189,10 @@ const hasFilteredItems = computed(() => filteredGroups.value.some(group => group

<DropdownMenu.Portal v-bind="portalProps">
<FieldGroupReset>
<component :is="sub ? DropdownMenu.SubContent : DropdownMenu.Content" data-slot="content" :class="ui.content({ class: [uiOverride?.content, props.class] })" v-bind="contentProps">
<component :is="sub ? DropdownMenu.SubContent : DropdownMenu.Content" data-slot="content" :class="ui.content({ class: [uiOverride?.content, props.class] })" v-bind="contentProps" @open-auto-focus="onOpenAutoFocus">
<DropdownMenu.Filter v-if="!!filter" v-model="searchTerm" as-child>
<UInput
ref="inputRef"
autofocus
autocomplete="off"
:size="size"
Expand Down
5 changes: 3 additions & 2 deletions src/runtime/components/InputMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type IsClearUsed<M extends boolean, C extends boolean | object> = M extends fals
? (C extends true ? null : C extends object ? null : never)
: never

export interface InputMenuProps<T extends ArrayOrNested<InputMenuItem> = ArrayOrNested<InputMenuItem>, VK extends GetItemKeys<T> | undefined = undefined, M extends boolean = false, Mod extends Omit<ModelModifiers, 'lazy'> = Omit<ModelModifiers, 'lazy'>, C extends boolean | object = false> extends Pick<ComboboxRootProps<T>, 'open' | 'defaultOpen' | 'disabled' | 'name' | 'resetSearchTermOnBlur' | 'resetSearchTermOnSelect' | 'resetModelValueOnClear' | 'highlightOnHover' | 'loop' | 'openOnClick' | 'openOnFocus' | 'by'>, UseComponentIconsProps, /** @vue-ignore */ Omit<InputHTMLAttributes, 'disabled' | 'name' | 'type' | 'placeholder' | 'autofocus' | 'maxlength' | 'minlength' | 'pattern' | 'size' | 'min' | 'max' | 'step'> {
export interface InputMenuProps<T extends ArrayOrNested<InputMenuItem> = ArrayOrNested<InputMenuItem>, VK extends GetItemKeys<T> | undefined = undefined, M extends boolean = false, Mod extends Omit<ModelModifiers, 'lazy'> = Omit<ModelModifiers, 'lazy'>, C extends boolean | object = false> extends Pick<ComboboxRootProps<T>, 'open' | 'defaultOpen' | 'disabled' | 'name' | 'resetSearchTermOnBlur' | 'resetSearchTermOnSelect' | 'resetModelValueOnClear' | 'highlightOnHover' | 'loop' | 'openOnClick' | 'openOnFocus' | 'unmountOnHide' | 'by'>, UseComponentIconsProps, /** @vue-ignore */ Omit<InputHTMLAttributes, 'disabled' | 'name' | 'type' | 'placeholder' | 'autofocus' | 'maxlength' | 'minlength' | 'pattern' | 'size' | 'min' | 'max' | 'step'> {
/**
* The element or component this component should render as.
* @defaultValue 'div'
Expand Down Expand Up @@ -286,6 +286,7 @@ const _props = withDefaults(defineProps<InputMenuProps<T, VK, M, Mod, C>>(), {
resetSearchTermOnBlur: true,
resetSearchTermOnSelect: true,
resetModelValueOnClear: true,
unmountOnHide: true,
virtualize: false,
mode: 'combobox'
})
Expand All @@ -304,7 +305,7 @@ const isAutocomplete = computed(() => props.mode === 'autocomplete')
// `multiple` doesn't apply in autocomplete mode.
const isMultiple = computed(() => !!props.multiple && !isAutocomplete.value)

const comboboxRootProps = useForwardProps(props, ['as', 'modelValue', 'defaultValue', 'open', 'defaultOpen', 'required', 'multiple', 'resetSearchTermOnBlur', 'resetSearchTermOnSelect', 'resetModelValueOnClear', 'highlightOnHover', 'loop', 'openOnClick', 'openOnFocus', 'by'], emits)
const comboboxRootProps = useForwardProps(props, ['as', 'modelValue', 'defaultValue', 'open', 'defaultOpen', 'required', 'multiple', 'resetSearchTermOnBlur', 'resetSearchTermOnSelect', 'resetModelValueOnClear', 'highlightOnHover', 'loop', 'openOnClick', 'openOnFocus', 'unmountOnHide', 'by'], emits)
const autocompleteRootProps = useForwardProps(props, ['as', 'modelValue', 'defaultValue', 'open', 'defaultOpen', 'required', 'resetSearchTermOnBlur', 'highlightOnHover', 'loop', 'openOnClick', 'openOnFocus'], emits)
const rootProps = computed(() => isAutocomplete.value ? autocompleteRootProps.value : comboboxRootProps.value)
const Component = computed(() => isAutocomplete.value ? Autocomplete : Combobox)
Expand Down
7 changes: 4 additions & 3 deletions src/runtime/components/Popover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { ComponentConfig } from '../types/tv'
type Popover = ComponentConfig<typeof theme, AppConfig, 'popover'>
type PopoverMode = 'click' | 'hover'

export interface PopoverProps<M extends PopoverMode = PopoverMode> extends Omit<PopoverRootProps, 'unmountOnHide'>, Pick<HoverCardRootProps, 'openDelay' | 'closeDelay' | 'enableTouch'> {
export interface PopoverProps<M extends PopoverMode = PopoverMode> extends PopoverRootProps, Pick<HoverCardRootProps, 'openDelay' | 'closeDelay' | 'enableTouch'> {
/**
* The display mode of the popover.
* @defaultValue 'click'
Expand Down Expand Up @@ -81,7 +81,8 @@ const _props = withDefaults(defineProps<PopoverProps<M>>(), {
mode: 'click' as never,
openDelay: 0,
closeDelay: 0,
dismissible: true
dismissible: true,
unmountOnHide: true
})
const emits = defineEmits<PopoverEmits>()
const slots = defineSlots<PopoverSlots<M>>()
Expand All @@ -90,7 +91,7 @@ const props = useComponentProps<PopoverProps<M>>('popover', _props)

const appConfig = useAppConfig() as Popover['AppConfig']

const rootProps = useForwardProps(props, props.mode === 'hover' ? ['defaultOpen', 'open', 'openDelay', 'closeDelay', 'enableTouch'] : ['defaultOpen', 'open', 'modal'], emits)
const rootProps = useForwardProps(props, props.mode === 'hover' ? ['defaultOpen', 'open', 'openDelay', 'closeDelay', 'enableTouch'] : ['defaultOpen', 'open', 'modal', 'unmountOnHide'], emits)
const portalProps = usePortal(toRef(() => props.portal))
const contentProps = toRef(() => defu(props.content, { side: 'bottom', sideOffset: 8, collisionPadding: 8 }) as PopoverContentProps)
const contentEvents = computed(() => {
Expand Down
Loading
Loading