Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

components-optiongroup.asciidoc 4.5KB

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