Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

components-optiongroup.asciidoc 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. ---
  2. title: OptionGroup
  3. order: 19
  4. layout: page
  5. ---
  6. [[components.optiongroup]]
  7. = [classname]#OptionGroup#
  8. ifdef::web[]
  9. [.sampler]
  10. image:{live-demo-image}[alt="Live Demo", link="http://demo.vaadin.com/sampler/#ui/data-input/multiple-value/option-group"]
  11. endif::web[]
  12. [classname]#OptionGroup# is a selection component that allows selection from a
  13. group of radio buttons in single selection mode. In multiple selection mode, the
  14. items show up as check boxes. The common selection component features are
  15. described in
  16. <<dummy/../../../framework/components/components-selection#components.selection,"Selection Components">>.
  17. [[figure.components.optiongroup]]
  18. .Option Button Group in Single and Multiple Selection Mode
  19. image::img/optiongroup-basic.png[width=45%, scaledwidth=70%]
  20. Option group is by default in single selection mode. Multiple selection is
  21. enabled with [methodname]#setMultiSelect()#.
  22. [source, java]
  23. ----
  24. // A single-select radio button group
  25. OptionGroup<String> single =
  26. new OptionGroup<>("Single Selection");
  27. single.setItems("Single", "Sola", "Yksi");
  28. // A multi-select check box group
  29. OptionGroup<String> multi =
  30. new OptionGroup<>("Multiple Selection");
  31. multi.setMultiSelect(true);
  32. multi.setItems("Many", "Muchos", "Monta");
  33. ----
  34. <<figure.components.optiongroup>> shows the [classname]#OptionGroup# in both
  35. single and multiple selection mode.
  36. You can also create check boxes individually using the [classname]#CheckBox#
  37. class, as described in
  38. <<dummy/../../../framework/components/components-checkbox#components.checkbox,"CheckBox">>.
  39. The advantages of the [classname]#OptionGroup# component are that as it
  40. maintains the individual check box objects, you can get an array of the
  41. currently selected items easily, and that you can easily change the appearance
  42. of a single component.
  43. ifdef::web[]
  44. [[components.optiongroup.disabling]]
  45. == Disabling Items
  46. You can disable individual items in an [classname]#OptionGroup# with
  47. [methodname]#setItemEnabled()#. The user can not select or deselect disabled
  48. items in multi-select mode, but in single-select mode the use can change the
  49. selection from a disabled to an enabled item. The selections can be changed
  50. programmatically regardless of whether an item is enabled or disabled. You can
  51. find out whether an item is enabled with [methodname]#isItemEnabled()#.
  52. [source, java]
  53. ----
  54. // Have an option group with some items
  55. OptionGroup<String> group = new OptionGroup<>("My Disabled Group");
  56. group.setItems("One", "Two", "Three");
  57. // Disable one item
  58. group.setItemEnabled("Two", false);
  59. ----
  60. [[figure.components.optiongroup.disabling]]
  61. .[classname]#OptionGroup# with a Disabled Item
  62. image::img/optiongroup-disabling.png[width=25%, scaledwidth=50%]
  63. Setting an item as disabled turns on the [literal]#++v-disabled++# style for it.
  64. endif::web[]
  65. [[components.optiongroup.css]]
  66. == CSS Style Rules
  67. [source, css]
  68. ----
  69. .v-select-optiongroup {}
  70. .v-select-option.v-checkbox {}
  71. .v-select-option.v-radiobutton {}
  72. ----
  73. The [literal]#++v-select-optiongroup++# is the overall style for the component.
  74. Each check box will have the [literal]#++v-checkbox++# style, borrowed from the
  75. [classname]#CheckBox# component, and each radio button the
  76. [literal]#++v-radiobutton++# style. Both the radio buttons and check boxes will
  77. also have the [literal]#++v-select-option++# style that allows styling
  78. regardless of the option type. Disabled items have additionally the
  79. [literal]#++v-disabled++# style.
  80. ifdef::web[]
  81. [[components.optiongroup.css.horizontal]]
  82. === Horizontal Layout
  83. The options are normally laid out vertically. You can use horizontal layout by
  84. setting [literal]#++display: inline-block++# for the options. The
  85. [literal]#++nowrap++# setting for the overall element prevents wrapping if there
  86. is not enough horizontal space in the layout, or if the horizontal width is
  87. undefined.
  88. [source, css]
  89. ----
  90. /* Lay the options horizontally */
  91. .v-select-optiongroup-horizontal .v-select-option {
  92. display: inline-block;
  93. }
  94. /* Avoid wrapping if the layout is too tight */
  95. .v-select-optiongroup-horizontal {
  96. white-space: nowrap;
  97. }
  98. /* Some extra spacing is needed */
  99. .v-select-optiongroup-horizontal
  100. .v-select-option.v-radiobutton {
  101. padding-right: 10px;
  102. }
  103. ----
  104. Use of the above rules requires setting a custom [literal]#++horizontal++# style
  105. name for the component. The result is shown in
  106. <<figure.components.optiongroup.horizontal>>.
  107. [[figure.components.optiongroup.horizontal]]
  108. .Horizontal [classname]#OptionGroup#
  109. image::img/optiongroup-horizontal.png[width=35%, scaledwidth=50%]
  110. endif::web[]