Skip to content

Commit

Permalink
Fix drop-down menu (#11744)
Browse files Browse the repository at this point in the history
Fixes #11741

The styles of floating-ui were not applied, because any style is [not applied to a slot in general](https://stackoverflow.com/questions/47317479/styling-vue-slot).

(cherry picked from commit d53b85b)
  • Loading branch information
farmaazon authored and jdunkerley committed Dec 3, 2024
1 parent 8ff0691 commit d407a1e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
8 changes: 3 additions & 5 deletions app/gui/src/project-view/components/DropdownMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
import MenuButton from '@/components/MenuButton.vue'
import SizeTransition from '@/components/SizeTransition.vue'
import SvgIcon from '@/components/SvgIcon.vue'
import { useUnrefHTMLElement } from '@/composables/events'
import { injectInteractionHandler } from '@/providers/interactionHandler'
import { endOnClickOutside } from '@/util/autoBlur'
import { shift, useFloating, type Placement } from '@floating-ui/vue'
import { ref, shallowRef, useTemplateRef, type VueElement } from 'vue'
import { ref, shallowRef } from 'vue'
const open = defineModel<boolean>('open', { default: false })
const props = defineProps<{
Expand All @@ -16,8 +15,7 @@ const props = defineProps<{
}>()
const rootElement = shallowRef<HTMLElement>()
const menuPanel = useTemplateRef<Element | VueElement | undefined | null>('menuPanel')
const floatElement = useUnrefHTMLElement(menuPanel)
const floatElement = shallowRef<HTMLElement>()
const hovered = ref(false)
injectInteractionHandler().setWhen(
Expand Down Expand Up @@ -51,7 +49,7 @@ const { floatingStyles } = useFloating(rootElement, floatElement, {
class="arrow"
/>
<SizeTransition height :duration="100">
<slot v-if="open" ref="menuPanel" name="menu" :style="floatingStyles" />
<div v-if="open" ref="floatElement" :style="floatingStyles"><slot name="menu" /></div>
</SizeTransition>
</div>
</template>
Expand Down
11 changes: 0 additions & 11 deletions app/gui/src/project-view/composables/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
toValue,
watch,
watchEffect,
type ComputedRef,
type Ref,
type ShallowRef,
type WatchSource,
Expand Down Expand Up @@ -185,16 +184,6 @@ export function unrefElement(
return result
}

/** Returns a reactive value for the input element's root, if it is an HTML element. */
export function useUnrefHTMLElement(
element: Ref<Element | undefined | null | VueInstance>,
): ComputedRef<HTMLElement | undefined> {
return computed(() => {
const elementValue = unrefElement(element)
return elementValue instanceof HTMLElement ? elementValue : undefined
})
}

interface ResizeObserverData {
refCount: number
boundRectUsers: number
Expand Down

0 comments on commit d407a1e

Please sign in to comment.