I’m trying to add a TextField to the toolbar using .principal placement, and I want it to either fill the screen width or expand based on the surrounding content. However, it’s not resizing as expected — the TextField only resizes correctly when I provide a hardcoded width value. This behavior was working fine in previous versions of Xcode, but seems to be broken in Xcode 26. Not sure if this is an intentional change or a bug. i am using iOS26 beta and Xcode 26 beta
struct ContentView: View {
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
}
.padding()
.toolbar {
ToolbarItem(placement: .principal) {
HStack {
TextField("Search", text: .constant(""))
.textFieldStyle(.roundedBorder)
.frame(maxWidth: .infinity)
// .frame(width: 300)
Button("cancel") {
}
}
.frame(maxWidth: .infinity)
}
}
}
}
#Preview {
NavigationView {
ContentView()
}
}