Skip to content

Platform specific dialog button order, take two - #8599

Merged
outofambit merged 116 commits into
developmentfrom
matters-order
Nov 27, 2019
Merged

outofambit merged 116 commits into
developmentfrom
matters-order

Conversation

@niik

@niik niik commented Nov 7, 2019 •

Copy link
Copy Markdown
Member

😅 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 this

<ButtonGroup>
  <Button type="submit">Ok</Button>
  <Button>Cancel</Button>
</ButtonGroup>

The 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.

button conventions

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 OkCancelButtonGroup which 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 focusFirstSuitableChild method 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

  • the focusFirstSuitableChild method in dialog.tsx
  • the OkCancelButtonGroup component
  • the DefaultDialogFooter component

Other things to note:

  • A lot of custom focusing logic from individual dialogs are now gone thanks to the focus algorithm baked into the dialog itself.
  • The AbortMergeWarning and ConfirmAbortDialog dialogs were mimicking a warning dialog by including a warning octicon in the dialog contents rather than using the type='warning' dialog prop. This has been addressed.

Screenshots

Artboard Copy 2

TODO

  • Finalize button order documentation (button-order.md) - @billygriffin
  • Finalize dialog documentation (dialogs.md) - @niik

Release notes

Notes: [Improved] Dialog button order in destructive dialogs follows platform convention on Windows.

niik and others added 30 commits April 25, 2019 16:40
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
@niik
niik marked this pull request as ready for review November 12, 2019 15:29
@tierninho
tierninho self-requested a review November 14, 2019 01:03
tierninho
tierninho previously approved these changes Nov 14, 2019

@tierninho tierninho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial testing of buttons looks good 👍 . Will do some more testing in beta.

@niik

niik commented Nov 14, 2019

Copy link
Copy Markdown
Member Author

@billygriffin Would you say this also closes #5883?

@billygriffin

Copy link
Copy Markdown
Contributor

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
outofambit self-requested a review November 14, 2019 20:17
outofambit
outofambit previously approved these changes Nov 26, 2019

@outofambit outofambit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is great! one concern about overriding default focus behavior, but i'm assuming @niik has already thought through that.

Comment thread app/src/ui/dialog/dialog.tsx Resolved
Comment thread app/src/ui/dialog/dialog.tsx Resolved
Comment thread app/src/ui/dialog/dialog.tsx Resolved
* 4. Any remaining button
*
*/
private focusFirstSuitableChild() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@outofambit outofambit self-assigned this Nov 26, 2019
Co-Authored-By: evelyn masso <[email protected]>
@niik
niik dismissed stale reviews from outofambit and tierninho via 0fd60ed November 27, 2019 12:35
@niik
niik requested a review from outofambit November 27, 2019 12:49
@outofambit
outofambit merged commit 4eb74a8 into development Nov 27, 2019
@outofambit
outofambit deleted the matters-order branch November 27, 2019 18:59
outofambit added a commit that referenced this pull request Apr 13, 2020
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
outofambit added a commit that referenced this pull request Apr 14, 2020
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants