Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NavigationMenu/DropdownMenu/ContextMenu] Generic type doesn't work when passing links as [][] #2140

Closed
benjamincanac opened this issue Mar 20, 2024 · 5 comments · Fixed by #3331
Assignees
Labels
bug Something isn't working typescript v3 #1289

Comments

@benjamincanac
Copy link
Member

No description provided.

@benjamincanac benjamincanac added the bug Something isn't working label Mar 20, 2024
@benjamincanac benjamincanac transferred this issue from another repository Mar 27, 2024
@benjamincanac benjamincanac changed the title [NavigationMenu] Generic type doesn't work when passing links as [][] [NavigationMenu/DropdownMenu] Generic type doesn't work when passing links as [][] Mar 28, 2024
@mauroerta
Copy link
Contributor

Hello @benjamincanac , I'd like to help you with this issue, can I ask you for additional details? I'm not sure I got what the bug is / what I need to fix exactly, is it only related to links given as items, for example something like this?

// ...
const items = [
 [{ link: '/link/to/somewhere', label: 'Some Text' }]
]
</script>

<template>
    <NavigationMenu :items="items" />
 // ....

@benjamincanac
Copy link
Member Author

The issue is when passing items as array of arrays, the generic item type T is not working.

  1. Example with simple array:

CleanShot 2024-04-30 at 23 35 00@2x

  1. Example with array of array:

CleanShot 2024-04-30 at 23 35 14@2x

We can see in the second example that the inferred type for item is the full NavigationMenuItem but not the generic type.

<script setup lang="ts">
const items = [[{
  label: 'Item',
  myfield: 'myfield'
}]]
</script>

<template>
  <UNavigationMenu :items="items">
    <template #item="{ item }">
      {{ item.myfield }}
    </template>
  </UNavigationMenu>
</template>

I have no idea how to fix that at the moment so any help is appreciated. Let me know if you need additional informations 😊

@benjamincanac benjamincanac added the v3 #1289 label Jul 18, 2024
@benjamincanac benjamincanac transferred this issue from benjamincanac/ui3 Sep 6, 2024
@benjamincanac
Copy link
Member Author

@yassilah Given the awesome work you did on generic types, would you have an idea on how to solve this as well?

@yassilah
Copy link
Contributor

Here's how I would do it (it works but there were already type errors in the file so I left it as it):

https://github.com/yassilah/ui/blob/fix/navigation-menu-items/src/runtime/components/NavigationMenu.vue#L88-L110

@yassilah
Copy link
Contributor

I can also make a PR for this one and add type tests. I would wait for #2471 to be merged and re-use the SelectItems<T> type helper here too (I would probably rename it to MaybeArrayOfArray<T> so it's more generic and can be used for other components too)

@benjamincanac benjamincanac changed the title [NavigationMenu/DropdownMenu] Generic type doesn't work when passing links as [][] [NavigationMenu/DropdownMenu/ContextMenu] Generic type doesn't work when passing links as [][] Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working typescript v3 #1289
Projects
None yet
4 participants