iOS 14 menu picker style's label becomes dim sometimes when changing

Viewed 2056

I have a Picker in my SwiftUI View with the new MenuPickerStyle.

Menu picker label becomes dim on changing

As you can see, the label of the picker is same of the options, and it becomes dim when changing from one option to another.

It looks like it is not tappable, but when tapping it does the required job.

Here's my code. It is just a very simple picker implementation.

struct MenuPicker: View {
    
    @State var selection: String = "one"
    
    var array: [String] = ["one", "two", "three", "four", "five"]

    var body: some View {
        Picker(selection: $selection, label: Text(selection).frame(width: 100), content: {
            ForEach(array, id: \.self, content: { word in
                Text(word).tag(word)
            })
        })
        .pickerStyle(MenuPickerStyle())
        .padding()
        .background(Color(.systemBackground).edgesIgnoringSafeArea(.all))
        .cornerRadius(5)
    }
}

struct ContentView: View {
    
    var body: some View {
        ZStack {
            Color.gray
            MenuPicker()
        }
    }
}
1 Answers

It looks like it's a bug with:

public init(selection: Binding<SelectionValue>, label: Label, @ViewBuilder content: () -> Content)

You can try replacing it with:

public init(_ titleKey: LocalizedStringKey, selection: Binding<SelectionValue>, @ViewBuilder content: () -> Content)

Here is a workaround (you can only use String as the label):

Picker(selection, selection: $selection) {
    ForEach(array, id: \.self) { word in
        Text(word).tag(word)
    }
}
.frame(width: 100)
.animation(nil)
.pickerStyle(MenuPickerStyle())
Related