You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VisuallyDistinguishPrimaryActions.asciidoc 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. ---
  2. title: Visually Distinguish Primary Actions
  3. order: 66
  4. layout: page
  5. ---
  6. [[visually-distinguish-primary-actions]]
  7. = Visually distinguish primary actions
  8. Most forms and dialogs have at least two actions that can be performed,
  9. such as _Submit/Cancel_, _Save/Revert_ or _Yes/No_. Quite often, there
  10. are more, such as a login form with the actions _“Sign in”_,
  11. _“Register”_, and _“Forgot password”_. Usually, one of these actions is
  12. by far the most commonly used, and as such, the most likely one the user
  13. is going to be looking for.
  14. If all actions are represented by identical buttons (save for the
  15. caption), identifying the primary button can be quite slow, and the risk
  16. of selecting the wrong action by mistake (especially when in a hurry) is
  17. substantial:
  18. image:img/sign%20in%20-%20no%20distinction.png[Sign in - no distinction]
  19. By visually distinguishing primary actions, e.g. by color, size or
  20. shape, the user can quickly and accurately find them even in a crowded,
  21. cluttered UI. A typical approach is to use a stronger (more saturated)
  22. color with greater contrast for the primary actions, and a grayer, lower
  23. contrast color for the secondary actions:
  24. image:img/sign%20in%20-%20primary%20distinguished.png[Sign in - distinguished]
  25. Sometimes a view can have more than one primary action simultaneously
  26. available, although usually in different parts of the view. Google
  27. handles this quite elegantly by systematically styling _creation_
  28. primary buttons (such as _Compose_ in Gmail and _Create_ in Drive) in
  29. *red*, and other primary buttons (such as search) in *blue*, while
  30. leaving secondary buttons *gray*:
  31. image:img/google%20drive.png[Google drive]
  32. Choose colors wisely, though – red, for instance, means _“no”_, _"stop"_
  33. or _“danger”_ in most cultures, so using that for _“Yes”_ or _“Submit”_
  34. might send the user mixed signals. You might also want to take into
  35. account the effects of color blindness (affecting approximately 10% of
  36. men and 1% of women), especially if your user base is going to be tens
  37. of thousands of people.
  38. Setting a different visual style for primary action buttons is very easy
  39. to do in Vaadin by using the *BUTTON_DEFAULT* stylename in any of the
  40. built-in themes like Reindeer or Chameleon:
  41. [source,java]
  42. ....
  43. Button btnSignIn = new Button("Sign in");
  44. btnSignIn.addStyleName(Reindeer.BUTTON_DEFAULT);
  45. ....
  46. Another common approach, mainly used on the web, is to use text links
  47. instead of buttons for secondary or tertiary actions. This has a
  48. significantly stronger effect than color or size, and should only be
  49. used for significantly less common actions, such as a password reset
  50. request, not for the _“No”_ option in a _Yes/No_ dialog, for instance:
  51. image:img/sign%20in%20-%20all%20different.png[Sign in - all different]
  52. This is just as easy in Vaadin. Just use the *BUTTON_LINK* stylename
  53. defined in the base theme (and inherited in all built in themes), and
  54. your Button will look like a normal text-hyperlink.
  55. [source,java]
  56. ....
  57. Button btnForgotPwd = new Button("Forgot password?");
  58. btnForgotPwd.addStyleName(Reindeer.BUTTON_LINK);
  59. ....
  60. (Note that the separate *Link* component should not be used for server
  61. actions, since you can't bind a ClickListener to a Link.)
  62. [[consider-binding-the-enter-key-to-the-primary-action]]
  63. Consider binding the Enter key to the primary action
  64. ++++++++++++++++++++++++++++++++++++++++++++++++++++
  65. Especially in short, often used forms, such as a login form, it is
  66. usually a good idea to bind the Enter key to the primary action. This
  67. relieves the user from having to move his hand from the keyboard to the
  68. mouse.
  69. [source,java]
  70. ....
  71. Button btnSignIn = new Button("Sign in");
  72. btnSignIn.addStyleName(Reindeer.BUTTON_DEFAULT);
  73. btnSignIn.setClickShortcut(KeyCode.ENTER);
  74. ....
  75. If the primary action is something that really mustn’t be invoked by
  76. mistake or without properly thinking about it first, however, it’s
  77. probably better not to bind it to a keyboard shortcut, to avoid
  78. accidental invocations. Another reason to abstain from a keyboard
  79. shortcut is if the form contains an input field in which Enter can be
  80. used for something, such as a multi-line text area (where Enter creates
  81. a line break).