form-selectboxes.mdx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. ---
  2. title: Form selectgroup
  3. summary: Use selectgroup to make your form more intuitive by providing users with a set of options to choose from. You can add simple selectgroup with a label, use icons only or icons with labels. Alternatively, you can use pill selectgroup if they go well with your design.
  4. description: Improve form UX with select groups.
  5. ---
  6. ## Simple selectgroup
  7. To create a simple selectgroup, use the `.form-selectgroup` class. You should add a label to the selectgroup by using the `.form-selectgroup-item` class for the input element and the `.form-selectgroup-label` class for the label.
  8. ```html
  9. <label class="form-selectgroup-item">
  10. <input type="checkbox" name="name" value="..." class="form-selectgroup-input" checked />
  11. <span class="form-selectgroup-label">...</span>
  12. </label>
  13. ```
  14. Look at the example below to see how the simple selectgroup works:
  15. ```html example columns={1} centered
  16. <div>
  17. <div class="form-selectgroup">
  18. <label class="form-selectgroup-item">
  19. <input type="radio" name="name" value="HTML" class="form-selectgroup-input" checked />
  20. <span class="form-selectgroup-label">HTML</span>
  21. </label>
  22. <label class="form-selectgroup-item">
  23. <input type="radio" name="name" value="CSS" class="form-selectgroup-input" />
  24. <span class="form-selectgroup-label">CSS</span>
  25. </label>
  26. <label class="form-selectgroup-item">
  27. <input type="radio" name="name" value="PHP" class="form-selectgroup-input" />
  28. <span class="form-selectgroup-label">PHP</span>
  29. </label>
  30. <label class="form-selectgroup-item">
  31. <input type="radio" name="name" value="JavaScript" class="form-selectgroup-input" />
  32. <span class="form-selectgroup-label">JavaScript</span>
  33. </label>
  34. </div>
  35. </div>
  36. ```
  37. ## Multiple choices
  38. You can also create a selectgroup with multiple choices. To do this, change the `type` attribute of the input element to `checkbox`.
  39. ```html
  40. <label class="form-selectgroup-item">
  41. <input type="checkbox" name="name" value="..." class="form-selectgroup-input" checked />
  42. <span class="form-selectgroup-label">...</span>
  43. </label>
  44. ```
  45. Look at the example below to see how the multiple choices selectgroup works:
  46. ```html example columns={1} centered
  47. <div>
  48. <div class="form-selectgroup">
  49. <label class="form-selectgroup-item">
  50. <input type="checkbox" name="name" value="HTML" class="form-selectgroup-input" checked />
  51. <span class="form-selectgroup-label">HTML</span>
  52. </label>
  53. <label class="form-selectgroup-item">
  54. <input type="checkbox" name="name" value="CSS" class="form-selectgroup-input" />
  55. <span class="form-selectgroup-label">CSS</span>
  56. </label>
  57. <label class="form-selectgroup-item">
  58. <input type="checkbox" name="name" value="PHP" class="form-selectgroup-input" />
  59. <span class="form-selectgroup-label">PHP</span>
  60. </label>
  61. <label class="form-selectgroup-item">
  62. <input type="checkbox" name="name" value="JavaScript" class="form-selectgroup-input" />
  63. <span class="form-selectgroup-label">JavaScript</span>
  64. </label>
  65. </div>
  66. </div>
  67. ```
  68. ## Icon input
  69. To create an icon input, use the `.form-selectgroup` class. You should add a label to the selectgroup by using the `.form-selectgroup-item` class for the input element and the `.form-selectgroup-label` class for the label. You can use the `.icon` class to style the icon.
  70. ```html
  71. <label class="form-selectgroup-item">
  72. <input type="checkbox" name="name" value="sun" class="form-selectgroup-input" checked />
  73. <span class="form-selectgroup-label">
  74. <svg class="icon" width="24" height="24">...</svg>
  75. </span>
  76. </label>
  77. ```
  78. We recommend you use Tabler Icons for the best experience. You can find over <IconsCount rounded /> free icons in the [Tabler Icons](https://tabler-icons.io/) library. Just copy the SVG code and paste it into your project.
  79. ```html example columns={1} centered
  80. <div class="mb-3">
  81. <label class="form-label">Icon input</label>
  82. <div class="form-selectgroup">
  83. <label class="form-selectgroup-item">
  84. <input type="checkbox" name="name" value="sun" class="form-selectgroup-input" checked />
  85. <span class="form-selectgroup-label">
  86. <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  87. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  88. <circle cx="12" cy="12" r="4" />
  89. <path d="M3 12h1m8 -9v1m8 8h1m-9 8v1m-6.4 -15.4l.7 .7m12.1 -.7l-.7 .7m0 11.4l.7 .7m-12.1 -.7l-.7 .7" />
  90. </svg>
  91. </span>
  92. </label>
  93. <label class="form-selectgroup-item">
  94. <input type="checkbox" name="name" value="moon" class="form-selectgroup-input" />
  95. <span class="form-selectgroup-label">
  96. <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  97. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  98. <path d="M12 3c.132 0 .263 0 .393 0a7.5 7.5 0 0 0 7.92 12.446a9 9 0 1 1 -8.313 -12.454z" />
  99. </svg>
  100. </span>
  101. </label>
  102. <label class="form-selectgroup-item">
  103. <input type="checkbox" name="name" value="cloud-rain" class="form-selectgroup-input" />
  104. <span class="form-selectgroup-label">
  105. <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  106. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  107. <path d="M7 18a4.6 4.4 0 0 1 0 -9a5 4.5 0 0 1 11 2h1a3.5 3.5 0 0 1 0 7" />
  108. <path d="M11 13v2m0 3v2m4 -5v2m0 3v2" />
  109. </svg>
  110. </span>
  111. </label>
  112. <label class="form-selectgroup-item">
  113. <input type="checkbox" name="name" value="cloud" class="form-selectgroup-input" />
  114. <span class="form-selectgroup-label">
  115. <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  116. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  117. <path d="M6.657 18c-2.572 0 -4.657 -2.007 -4.657 -4.483c0 -2.475 2.085 -4.482 4.657 -4.482c.393 -1.762 1.794 -3.2 3.675 -3.773c1.88 -.572 3.956 -.193 5.444 .996c1.488 1.19 2.162 3.007 1.77 4.769h.99c1.913 0 3.464 1.56 3.464 3.486c0 1.927 -1.551 3.487 -3.465 3.487h-11.878" />
  118. </svg>
  119. </span>
  120. </label>
  121. <label class="form-selectgroup-item">
  122. <input type="checkbox" name="name" value="Other" class="form-selectgroup-input" />
  123. <span class="form-selectgroup-label">Other</span>
  124. </label>
  125. </div>
  126. </div>
  127. ```
  128. You can also add text to the element. Look at the example below to see how it works:
  129. ```html example columns={1} centered
  130. <div class="mb-3">
  131. <label class="form-label">Selectgroup with icons and text</label>
  132. <div class="form-selectgroup">
  133. <label class="form-selectgroup-item">
  134. <input type="radio" name="icons" value="home" class="form-selectgroup-input" checked />
  135. <span class="form-selectgroup-label">
  136. <svg xmlns="http://www.w3.org/2000/svg" class="icon me-1" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  137. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  138. <polyline points="5 12 3 12 12 3 21 12 19 12" />
  139. <path d="M5 12v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-7" />
  140. <path d="M9 21v-6a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v6" />
  141. </svg> Home
  142. </span>
  143. </label>
  144. <label class="form-selectgroup-item">
  145. <input type="radio" name="icons" value="user" class="form-selectgroup-input" />
  146. <span class="form-selectgroup-label">
  147. <svg xmlns="http://www.w3.org/2000/svg" class="icon me-1" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  148. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  149. <circle cx="12" cy="7" r="4" />
  150. <path d="M6 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2" />
  151. </svg> User
  152. </span>
  153. </label>
  154. <label class="form-selectgroup-item">
  155. <input type="radio" name="icons" value="circle" class="form-selectgroup-input" />
  156. <span class="form-selectgroup-label">
  157. <svg xmlns="http://www.w3.org/2000/svg" class="icon me-1" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  158. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  159. <circle cx="12" cy="12" r="9" />
  160. </svg> Circle
  161. </span>
  162. </label>
  163. <label class="form-selectgroup-item">
  164. <input type="radio" name="icons" value="square" class="form-selectgroup-input" />
  165. <span class="form-selectgroup-label">
  166. <svg xmlns="http://www.w3.org/2000/svg" class="icon me-1" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  167. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  168. <rect x="4" y="4" width="16" height="16" rx="2" />
  169. </svg> Square
  170. </span>
  171. </label>
  172. </div>
  173. </div>
  174. ```
  175. ## Pill selectgroup
  176. If you want to use pill selectgroup, use the `.form-selectgroup-pills` class. All the other classes are the same as in the simple selectgroup.
  177. ```html
  178. <div class="form-selectgroup form-selectgroup-pills">
  179. ...
  180. </div>
  181. ```
  182. Look at the example below to see how the pill selectgroup works:
  183. ```html example columns={1} centered
  184. <div class="mb-3">
  185. <label class="form-label">Different style</label>
  186. <div class="form-selectgroup form-selectgroup-pills">
  187. <label class="form-selectgroup-item">
  188. <input type="checkbox" name="name" value="HTML" class="form-selectgroup-input" checked />
  189. <span class="form-selectgroup-label">HTML</span>
  190. </label>
  191. <label class="form-selectgroup-item">
  192. <input type="checkbox" name="name" value="CSS" class="form-selectgroup-input" />
  193. <span class="form-selectgroup-label">CSS</span>
  194. </label>
  195. <label class="form-selectgroup-item">
  196. <input type="checkbox" name="name" value="PHP" class="form-selectgroup-input" />
  197. <span class="form-selectgroup-label">PHP</span>
  198. </label>
  199. <label class="form-selectgroup-item">
  200. <input type="checkbox" name="name" value="JavaScript" class="form-selectgroup-input" />
  201. <span class="form-selectgroup-label">JavaScript</span>
  202. </label>
  203. </div>
  204. </div>
  205. ```
  206. ## Advanced selectboxes
  207. Use more advanced selectboxes to display the range of available options. You can choose selectboxes with radio buttons, if you want users to select only one option or with checkboxes, if they are allowed to choose multiple options.
  208. ```html example height="30rem" centered columns="1" plugins="payments"
  209. <div class="mb-3">
  210. <label class="form-label">Payment method</label>
  211. <div class="form-selectgroup form-selectgroup-boxes d-flex flex-column">
  212. <label class="form-selectgroup-item flex-fill">
  213. <input type="radio" name="form-payment" value="visa" class="form-selectgroup-input" />
  214. <div class="form-selectgroup-label d-flex align-items-center p-3">
  215. <div class="me-3">
  216. <span class="form-selectgroup-check"></span>
  217. </div>
  218. <div>
  219. <span class="payment payment-provider-visa payment-xs me-2"></span>
  220. ending in <strong>7998</strong>
  221. </div>
  222. </div>
  223. </label>
  224. <label class="form-selectgroup-item flex-fill">
  225. <input type="radio" name="form-payment" value="mastercard" class="form-selectgroup-input" checked />
  226. <div class="form-selectgroup-label d-flex align-items-center p-3">
  227. <div class="me-3">
  228. <span class="form-selectgroup-check"></span>
  229. </div>
  230. <div>
  231. <span class="payment payment-provider-mastercard payment-xs me-2"></span>
  232. ending in <strong>2807</strong>
  233. </div>
  234. </div>
  235. </label>
  236. <label class="form-selectgroup-item flex-fill">
  237. <input type="radio" name="form-payment" value="paypal" class="form-selectgroup-input" />
  238. <div class="form-selectgroup-label d-flex align-items-center p-3">
  239. <div class="me-3">
  240. <span class="form-selectgroup-check"></span>
  241. </div>
  242. <div>
  243. <span class="payment payment-provider-paypal payment-xs me-2"></span>
  244. </div>
  245. </div>
  246. </label>
  247. </div>
  248. </div>
  249. ```
  250. ```html
  251. <label class="form-selectgroup-item flex-fill">
  252. <input type="radio" name="form-payment" value="mastercard" class="form-selectgroup-input" checked />
  253. <div class="form-selectgroup-label d-flex align-items-center p-3">
  254. <div class="me-3">
  255. <span class="form-selectgroup-check"></span>
  256. </div>
  257. <div>
  258. <span class="payment payment-provider-mastercard payment-xs me-2"></span>
  259. ending in <strong>2807</strong>
  260. </div>
  261. </div>
  262. </label>
  263. ```