Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What mouse gesture to delete an item from a List on macOS in SwiftUI?

Tags:

swiftui

I don't understand how to delete or move a item on macOS. What action should I need to do with the mouse to trigger onDelete or onMove events?

 @State var wishList = ["Item 1", "Item 2", "Item3"]

    var body: some View {
        List {
            ForEach(wishList, id:\.self) { item in
                Button(action: {
                }) {
                    Text(item)
                }
            }
            .onDelete { offsets in
            }
            .onMove { source, target in
            }
        }
    }
like image 822
Victor Kushnerov Avatar asked Sep 05 '25 03:09

Victor Kushnerov


2 Answers

  • Move: Click and drag rows.

  • Delete: Swipe with (two fingers on trackpad or one finger on magic mouse), like the way you scroll horizontally.

Note that you should NOT click and drag the row like the way you swipe in iOS simulator. Just a simple mac horizontal scroll is enough.

like image 175
Mojtaba Hosseini Avatar answered Sep 07 '25 20:09

Mojtaba Hosseini


These gestures won't work if you have an ordinary two-button mouse. You will need to make affordances in your UI for people with simpler mice.

like image 33
huwr Avatar answered Sep 07 '25 20:09

huwr