fabulous-dev / Fabulous

Declarative UI framework for cross-platform mobile & desktop apps, using MVU and F# functional programming
https://fabulous.dev
Apache License 2.0
1.14k stars 121 forks source link

Button doesn't disable if the command is set #815

Closed Blener closed 3 years ago

Blener commented 3 years ago

When a button has the command property set it doesn't get disabled.

let view (model: Model) (dispatch: Msg -> unit) =
        View.ContentPage(
          content = View.StackLayout(padding = Thickness 20.0, verticalOptions = LayoutOptions.Center,
            children = [
                View.Button(text = "Disabled with command", isEnabled = false, command = ignore)
                View.Button(text = "Disabled without command", isEnabled = false)
            ]))

The code above generates this: image

This was using Fabulous 0.57.0 on an Android emulator.

Thanks.

TimLariviere commented 3 years ago

@Blener Hi. Thanks for the report, but it's the default behavior of Xamarin.Forms.

A command comes with its own CanExecute property that overrides IsEnabled. If not explicitly set through commandCanExecute, it will default to true so the button will always be active regardless of isEnabled.

So when using commands in Fabulous, use commandCanExecute to switch between enable and disable instead of IsEnabled.

View.Button(text = "Disabled with command", command = ignore, commandCanExecute = false)
Blener commented 3 years ago

Hi @TimLariviere . My mistake then, sorry for that. Thank you for the help.