Repository navigation
Platform specific dialog button order, take two - #8599
Conversation
Co-Authored-By: Billy Griffin <[email protected]>
And by really submits I mean it bypasses the onSubmit handlers on the form itself and does an actual post Co-Authored-By: Billy Griffin <[email protected]>
Co-Authored-By: Billy Griffin <[email protected]>
The first focusable element of the preferences dialog should be the tab bar, allowing you to move between tabs with the arrow keys
NaN compared to any number is false, we can use that
tierninho
left a comment
There was a problem hiding this comment.
Initial testing of buttons looks good 👍 . Will do some more testing in beta.
|
@billygriffin Would you say this also closes #5883? |
|
Nice spot @niik, wish I would've seen that issue when it was created so I'd have known about it! 😆 Adding to the body. |
outofambit
left a comment
There was a problem hiding this comment.
this is great! one concern about overriding default focus behavior, but i'm assuming @niik has already thought through that.
| * 4. Any remaining button | ||
| * | ||
| */ | ||
| private focusFirstSuitableChild() { |
There was a problem hiding this comment.
i won't pretend to fully understand the internal logic of this method, but i'm a bit concerned that we're always overriding default focus behavior with it. is there a way we could only use this logic if the dialog is destructive?
There was a problem hiding this comment.
The intention is to always override the default focus behavior because the default logic doesn't fit our needs. The diff has a number of examples of where we've now been able to remove explicit focus calls by individual dialogs to work around shortcomings in the default focus logic (acknowledgements.tsx is a good example). With this we've got a consistent focus logic (albeit custom) that should hopefully suit our needs. Should we discover that a particular dialog suffers from this focus logic (which is certainly possible, I've tested a lot of them but it's possible I missed something) I think we should either see if we can fix the logic in such a way that it works for all dialogs and if that's not possible we should add an opt-out prop for the dialog component that can be explicitly set for that case.
All that said dialogs still have the ability to control focus manually after they've been mounted.
Co-Authored-By: evelyn masso <[email protected]>
this is a workaround for a bug introduced in #8599, where non-dismissable dialogs that use the OkCancelButtonGroup and don't pass an explicit onCancel handler will fail to dismiss
this is a workaround for a bug introduced in #8599, where non-dismissable dialogs that use the OkCancelButtonGroup and don't pass an explicit onCancel handler will fail to dismiss
😅 This looks like a massive PR but most of the changes are straightforward refactors 😅
Closes #7186
Closes #2463
Closes #5883
Description
Ever since the initial implementation of dialogs in Desktop we've been aware of, and had support for, platform-specific button order in dialogs. A good summary of the difference can be found in https://www.nngroup.com/articles/ok-cancel-or-cancel-ok/. Given how complicated our solution to this problem had become (see #7273) @billygriffin and I decided to take a look at solving this problem holistically.
Our solution to the problem up until now was a component called
ButtonGroup, the usage of which looked something like thisThe button order above matches the Windows convention so at runtime the button group would switch the order of the buttons if running on macOS. In order to ensure that we used the Windows convention at compile time we had a static analysis rule which would emit an error if the submit button was not the first child of the ButtonGroup.
This approach worked reasonably well for a while with the exception of it being hard to reason about what the order would end up being at runtime and the fact that there was nothing stopping us from using the submit button as the cancel button.
The real problem with our support had to do with the introduction of the concept of "destructive" choices in dialogs.
Button order
We started out by defining the expected behavior and came up with the following graph.
I.e, contrary to what we've done in the past the destructive property should not alter the order of the buttons, it should, however, affect which button is the primary (or "default").
Our proposed solution to this is a new component called
OkCancelButtonGroupwhich does not let consumers alter the ordering of the buttons and thanks to it owning the rendering of the buttons it's also able to switch which of the buttons should be considered the primary based on whether the dialog is destructive or not.Dialog auto focus
A secondary, follow on, problem to fixing the ordering on Windows was that the left-most button could be the destructive action and since the dialog element automatically focuses the first keyboard-focusable element of the dialog we would end up with dialogs where the destructive button had the initial keyboard focus. That's obviously very dangerous as picking the destructive action is now only a space or enter key away. What we want is for the safe option to have keyboard focus.
To solve this I've introduced some new focus logic in the dialog, the intricacies of which is probably best explained by reading the comments in the
focusFirstSuitableChildmethod of the dialog component.Review notes
A lot of the changes in this PR are boilerplate refactors. The most important areas to look at are as follows
focusFirstSuitableChildmethod indialog.tsxOkCancelButtonGroupcomponentDefaultDialogFootercomponentOther things to note:
AbortMergeWarningandConfirmAbortDialogdialogs were mimicking a warning dialog by including a warning octicon in the dialog contents rather than using thetype='warning'dialog prop. This has been addressed.Screenshots
TODO
button-order.md) - @billygriffindialogs.md) - @niikRelease notes
Notes: [Improved] Dialog button order in destructive dialogs follows platform convention on Windows.