How to extend or create SubmitLabel type

Hello everyone, I found a way to change the submit button of the keyboard, using .submitLabel (.send); for instance, on a TextField element it would look like this:

TextField("PlaceholderText", text: $placeholderVariable).submitLabel( .send)

I also found the documentation here where it shows how many options one can choose from for the submit button’s label.
What I see in the documentation, is that there is no “Add” label - which I would like to use - and that submitLabel takes a SubmitLabel type.
Does anyone know how I can extend the SubmitLabel struct to create a new SubmitLabel type that will have “Add” as label for the submit button of the keyboard?
Thank you!

There is another way to add a Button to a keyboard by using the .toolbar like this:

.toolbar {
    ToolbarItemGroup(placement: .keyboard) {
        Spacer()

        Button("Done") {
            model.addItem()
        }
    }
}

This adds the Button to a line above the keyboard and is really useful when the keyboard type is changed and there is no return button such as in the case of a Numeric keyboard. It’s an implicit HStack so in the code above, the button is pushed to the right.

1 Like