question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Simple actions menu with AList

See original GitHub issue

I want to build a simple actions menu, but using AList is not relevant as we can’t handle click on each list items. How to do that ? Here is my code :

<script lang="ts" setup>
import { ref } from 'vue'

const items = [
  { title: 'Send' },
  { title: 'Edit' },
  { title: 'Delete' },
]

const selected = ref(0)
watch(selected, () => {
  console.log(selected.value)
  // We should handle value with item index ?
})
</script>

<template>
  <ABtn variant="text" class="!text-gray" icon="i-bi-three-dots-vertical" icon-only>
    <AMenu
      trigger="hover"
      placement="bottom-end"
    >
      <AList
        v-model="selected"
        :items="items"
        class="[--a-list-gap:0.25rem]"
      />
    </AMenu>
  </ABtn>
</template>

Also, item 0 is selected at mount time. I don’t want that. If I use const selected = ref(), hovering item don’t trigger background overlay.

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ManUtopiKcommented, Nov 29, 2022

Awesome ! You made a lot of works 🚀 It simplify a lot the process. So, I’ve been rewriting my simple menu with this :

<script lang="ts" setup>
function onSend() {
  console.log('Sended')
}
function onEdit() {
  console.log('Edited')
}
function onDelete() {
  console.log('Deleted')
}
</script>

<template>
  <ABtn>
    <AMenu>
      <AList>
        <AListItem title="Send" /><!-- No @click event : No pointer cursor and item highlight = good -->
        <AListItem title="Send" @click="onSend" /><!-- No pointer cursor and item highlight = bad -->
        <AListItem title="Edit" class="states:10 cursor-pointer" @click="onEdit" /><!-- Looks good :) -->
        <AListItem title="Delete" value="1" @click="onDelete" /><!-- Looks good :) -->
      </AList>
    </AMenu>

    Open Menu
  </ABtn>
</template>

I can get it worked, but we must add custom class or an arbitrary value attribute to display the list item with the cursor pointer and to be highlighted on hover. It’s not very intuitive…

0reactions
ManUtopiKcommented, Dec 14, 2022

Yes, everything seems good to me now !

This works as expected:

<AMenu>
  <AList>
    <AListItem title="Send" /><!-- No @click event : No pointer cursor and item highlight = good -->
    <AListItem title="Send" @click="onSend" /><!-- Good now :) -->
  </AList>
</AMenu>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Defining a list actions menu - IBM
Defining a list actions menu. Add a list actions menu to a person page. A list actions menu contains a set of actions...
Read more >
Use list actions in Shortcuts on iPhone or iPad - Apple Support
Use the List action to create an ordered list of content, by entering text or by inserting variables. When the shortcut is run,...
Read more >
Building a menu using List - a free SwiftUI by Example tutorial
In our app this screen will show us a list of items from a menu, so we're going to use a List view...
Read more >
Menus - Android Developers
The options menu is the primary collection of menu items for an activity. It's where you should place actions that have a global...
Read more >
Menus - Components - Material Design
Menus appear upon interaction with a button, action, or other control. They display a list of choices, with one choice per line. Menu...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found