I'm using SwiftUI and create a SlideMenu, I want to rename my menu item. I do it by change Text to TextField but the TextField disabled by default. What wrong with TextField, I unable to click on it or is there any way to rename without swap Text <-> TextField?
struct CellView: View {
@State private var isRename = false
@State private var newName: String = ""
var menuItem: MenuItem
var body: some View {
HStack {
Image(systemName: "folder")
.foregroundColor(.accentColor)
if isRename {
TextField(menuItem.name ?? "Unknow name", text: $newName)
}else {
Text(menuItem.name ?? "Unknow name")
}
Spacer()
}
.contextMenu {
Button(action: {
isRename = true
}) {
HStack {
Image(systemName: "pencil")
.foregroundColor(.accentColor)
Text("Rename")
}
}
}
}
}