'TextField in Table behavior
I'm trying to use the new SwiftUI Table
with TextField
's in each row.
However, the behavior of the text field's is weird, for 3 reasons:
- Clicking on a text field takes about 1 second for the focus to occur
- Anything that is not selected inside of a text field appears invisible until you change the text (only on dark mode?)
- You can only click on the part of the text field with text, otherwise no focus occurs
Reproduction:
- Ensure that macOS Montery Beta 1/2 & Xcode 13 Beta 1/2 are installed
- Create a new blank SwiftUI project, and set its deployment target to 12.0
- Paste the following code:
struct ContentView: View {
@State var data = [TestStruct(text: "Test"), TestStruct(text: "Bla"), TestStruct(text: "FooBar")]
@State var selection = Set<TestStruct.ID>()
var body: some View {
Table($data, selection: $selection) {
TableColumn("Col") { $item in
TextField("Placeholder", text: $item.text)
}
}
}
}
struct TestStruct: Identifiable {
var id = UUID()
var text: String
}
- Test it out by clicking one of the text fields (only works if you click the part with visible text)
Is anybody able to reproduce the behavior listed above, and are there any possible solutions? Or is this a bug with SwiftUI?
Any help is greatly appreciated.
Solution 1:[1]
I got the same issue. It seems to be related to the number of items in the table. I've also asked the question on the apple developer forum with a small example to see if someone there can help.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | oreman |