# How can I make a button that imitates DefaultButton and CancelButton?

Both DefaultButton and CancelButton are very convenient, in that they allow one to use FEPrivateFindAndClickDefaultButton and FEPrivateFindAndClickCancelButton. Unfortunately DefaultButton doesn't allow me to use custom appearances. How can I get that behavior?

• According to the documentation, DefaultButton should have the same options as Button. It seems that the Appearance option should work. You should report to WRI to see if it is a bug. – Edmund Aug 8 '17 at 21:10

The trick is in the Appearance list. I found this here:

FileNameJoin@{
PacletFind["CloudObject"][[1]]["Location"],
"Kernel",
"Dialogs.m"
}


The appearances use listed default / hover / pressed / disabled appearances a la this question. There's another appearance option called "ButtonType" which can be set to "Cancel" or "Default" to get the desired behavior. e.g.:

Append[
FrontEndResource["NotebookTemplatingExpressions",
"ButtonDefaultAppearance"],
"ButtonType" -> "Default"
]


I use this, for example, here

This works, of course, because CreateDialog sticks this into a dialog by default:

NotebookEventActions -> {"ReturnKeyDown" :>
FEEvaluate[FEPrivateFindAndClickDefaultButton[]], {"MenuCommand",
"EvaluateCells"} :>
FEEvaluate[FEPrivateFindAndClickDefaultButton[]], {"MenuCommand",
"HandleShiftReturn"} :>
FEEvaluate[FEPrivateFindAndClickDefaultButton[]], {"MenuCommand",
"EvaluateNextCell"} :>
FEEvaluate[FEPrivateFindAndClickDefaultButton[]],
"EscapeKeyDown" :> (FEEvaluate[
FEPrivateFindAndClickCancelButton[]]; DialogReturn[$Failed]), "WindowClose" :> (FEEvaluate[FEPrivateFindAndClickCancelButton[]]; DialogReturn[$Failed])}


And then we can imitate that like so:

CreateDocument[
{
"https://www.wolframcloud.com/objects/b3m2a1/home/main.html",
Appearance ->
{
"Default" -> None,
"ButtonType" -> "Default"
}
],
Appearance ->
{
"Default" -> None,
"ButtonType" -> "Cancel"
}
]
},
NotebookEventActions -> {"ReturnKeyDown" :>
FEEvaluate[
"EvaluateCells"} :>
FEEvaluate[
FEEvaluate[
FEEvaluate[FEPrivateFindAndClickDefaultButton[]],
"EscapeKeyDown" :> (FEEvaluate[
FEPrivateFindAndClickCancelButton[]]; DialogReturn[$Failed]), "WindowClose" :> (FEEvaluate[ FEPrivateFindAndClickCancelButton[]]; DialogReturn[$Failed])}

Where just pressing Enter or Cancel presses those Hyperlinks.