form-selectboxes.mdx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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
  87. xmlns="http://www.w3.org/2000/svg"
  88. class="icon"
  89. width="24"
  90. height="24"
  91. viewBox="0 0 24 24"
  92. stroke-width="2"
  93. stroke="currentColor"
  94. fill="none"
  95. stroke-linecap="round"
  96. stroke-linejoin="round"
  97. >
  98. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  99. <circle cx="12" cy="12" r="4" />
  100. <path
  101. 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"
  102. />
  103. </svg>
  104. </span>
  105. </label>
  106. <label class="form-selectgroup-item">
  107. <input type="checkbox" name="name" value="moon" class="form-selectgroup-input" />
  108. <span class="form-selectgroup-label">
  109. <svg
  110. xmlns="http://www.w3.org/2000/svg"
  111. class="icon"
  112. width="24"
  113. height="24"
  114. viewBox="0 0 24 24"
  115. stroke-width="2"
  116. stroke="currentColor"
  117. fill="none"
  118. stroke-linecap="round"
  119. stroke-linejoin="round"
  120. >
  121. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  122. <path
  123. 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"
  124. />
  125. </svg>
  126. </span>
  127. </label>
  128. <label class="form-selectgroup-item">
  129. <input type="checkbox" name="name" value="cloud-rain" class="form-selectgroup-input" />
  130. <span class="form-selectgroup-label">
  131. <svg
  132. xmlns="http://www.w3.org/2000/svg"
  133. class="icon"
  134. width="24"
  135. height="24"
  136. viewBox="0 0 24 24"
  137. stroke-width="2"
  138. stroke="currentColor"
  139. fill="none"
  140. stroke-linecap="round"
  141. stroke-linejoin="round"
  142. >
  143. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  144. <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" />
  145. <path d="M11 13v2m0 3v2m4 -5v2m0 3v2" />
  146. </svg>
  147. </span>
  148. </label>
  149. <label class="form-selectgroup-item">
  150. <input type="checkbox" name="name" value="cloud" class="form-selectgroup-input" />
  151. <span class="form-selectgroup-label">
  152. <svg
  153. xmlns="http://www.w3.org/2000/svg"
  154. class="icon"
  155. width="24"
  156. height="24"
  157. viewBox="0 0 24 24"
  158. stroke-width="2"
  159. stroke="currentColor"
  160. fill="none"
  161. stroke-linecap="round"
  162. stroke-linejoin="round"
  163. >
  164. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  165. <path
  166. 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"
  167. />
  168. </svg>
  169. </span>
  170. </label>
  171. <label class="form-selectgroup-item">
  172. <input type="checkbox" name="name" value="Other" class="form-selectgroup-input" />
  173. <span class="form-selectgroup-label">Other</span>
  174. </label>
  175. </div>
  176. </div>
  177. ```
  178. You can also add text to the element. Look at the example below to see how it works:
  179. ```html example columns={1} centered
  180. <div class="mb-3">
  181. <label class="form-label">Selectgroup with icons and text</label>
  182. <div class="form-selectgroup">
  183. <label class="form-selectgroup-item">
  184. <input type="radio" name="icons" value="home" class="form-selectgroup-input" checked />
  185. <span class="form-selectgroup-label">
  186. <svg
  187. xmlns="http://www.w3.org/2000/svg"
  188. class="icon me-1"
  189. width="24"
  190. height="24"
  191. viewBox="0 0 24 24"
  192. stroke-width="2"
  193. stroke="currentColor"
  194. fill="none"
  195. stroke-linecap="round"
  196. stroke-linejoin="round"
  197. >
  198. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  199. <polyline points="5 12 3 12 12 3 21 12 19 12" />
  200. <path d="M5 12v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-7" />
  201. <path d="M9 21v-6a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v6" />
  202. </svg>
  203. Home
  204. </span>
  205. </label>
  206. <label class="form-selectgroup-item">
  207. <input type="radio" name="icons" value="user" class="form-selectgroup-input" />
  208. <span class="form-selectgroup-label">
  209. <svg
  210. xmlns="http://www.w3.org/2000/svg"
  211. class="icon me-1"
  212. width="24"
  213. height="24"
  214. viewBox="0 0 24 24"
  215. stroke-width="2"
  216. stroke="currentColor"
  217. fill="none"
  218. stroke-linecap="round"
  219. stroke-linejoin="round"
  220. >
  221. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  222. <circle cx="12" cy="7" r="4" />
  223. <path d="M6 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2" />
  224. </svg>
  225. User
  226. </span>
  227. </label>
  228. <label class="form-selectgroup-item">
  229. <input type="radio" name="icons" value="circle" class="form-selectgroup-input" />
  230. <span class="form-selectgroup-label">
  231. <svg
  232. xmlns="http://www.w3.org/2000/svg"
  233. class="icon me-1"
  234. width="24"
  235. height="24"
  236. viewBox="0 0 24 24"
  237. stroke-width="2"
  238. stroke="currentColor"
  239. fill="none"
  240. stroke-linecap="round"
  241. stroke-linejoin="round"
  242. >
  243. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  244. <circle cx="12" cy="12" r="9" />
  245. </svg>
  246. Circle
  247. </span>
  248. </label>
  249. <label class="form-selectgroup-item">
  250. <input type="radio" name="icons" value="square" class="form-selectgroup-input" />
  251. <span class="form-selectgroup-label">
  252. <svg
  253. xmlns="http://www.w3.org/2000/svg"
  254. class="icon me-1"
  255. width="24"
  256. height="24"
  257. viewBox="0 0 24 24"
  258. stroke-width="2"
  259. stroke="currentColor"
  260. fill="none"
  261. stroke-linecap="round"
  262. stroke-linejoin="round"
  263. >
  264. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  265. <rect x="4" y="4" width="16" height="16" rx="2" />
  266. </svg>
  267. Square
  268. </span>
  269. </label>
  270. </div>
  271. </div>
  272. ```
  273. ## Pill selectgroup
  274. 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.
  275. ```html
  276. <div class="form-selectgroup form-selectgroup-pills">...</div>
  277. ```
  278. Look at the example below to see how the pill selectgroup works:
  279. ```html example columns={1} centered
  280. <div class="mb-3">
  281. <label class="form-label">Different style</label>
  282. <div class="form-selectgroup form-selectgroup-pills">
  283. <label class="form-selectgroup-item">
  284. <input type="checkbox" name="name" value="HTML" class="form-selectgroup-input" checked />
  285. <span class="form-selectgroup-label">HTML</span>
  286. </label>
  287. <label class="form-selectgroup-item">
  288. <input type="checkbox" name="name" value="CSS" class="form-selectgroup-input" />
  289. <span class="form-selectgroup-label">CSS</span>
  290. </label>
  291. <label class="form-selectgroup-item">
  292. <input type="checkbox" name="name" value="PHP" class="form-selectgroup-input" />
  293. <span class="form-selectgroup-label">PHP</span>
  294. </label>
  295. <label class="form-selectgroup-item">
  296. <input type="checkbox" name="name" value="JavaScript" class="form-selectgroup-input" />
  297. <span class="form-selectgroup-label">JavaScript</span>
  298. </label>
  299. </div>
  300. </div>
  301. ```
  302. ## Advanced selectboxes
  303. 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.
  304. ```html example height="30rem" centered columns="1" plugins="payments"
  305. <div class="mb-3">
  306. <label class="form-label">Payment method</label>
  307. <div class="form-selectgroup form-selectgroup-boxes d-flex flex-column">
  308. <label class="form-selectgroup-item flex-fill">
  309. <input type="radio" name="form-payment" value="visa" class="form-selectgroup-input" />
  310. <div class="form-selectgroup-label d-flex align-items-center p-3">
  311. <div class="me-3">
  312. <span class="form-selectgroup-check"></span>
  313. </div>
  314. <div>
  315. <span class="payment payment-provider-visa payment-xs me-2"></span>
  316. ending in <strong>7998</strong>
  317. </div>
  318. </div>
  319. </label>
  320. <label class="form-selectgroup-item flex-fill">
  321. <input
  322. type="radio"
  323. name="form-payment"
  324. value="mastercard"
  325. class="form-selectgroup-input"
  326. checked
  327. />
  328. <div class="form-selectgroup-label d-flex align-items-center p-3">
  329. <div class="me-3">
  330. <span class="form-selectgroup-check"></span>
  331. </div>
  332. <div>
  333. <span class="payment payment-provider-mastercard payment-xs me-2"></span>
  334. ending in <strong>2807</strong>
  335. </div>
  336. </div>
  337. </label>
  338. <label class="form-selectgroup-item flex-fill">
  339. <input type="radio" name="form-payment" value="paypal" class="form-selectgroup-input" />
  340. <div class="form-selectgroup-label d-flex align-items-center p-3">
  341. <div class="me-3">
  342. <span class="form-selectgroup-check"></span>
  343. </div>
  344. <div>
  345. <span class="payment payment-provider-paypal payment-xs me-2"></span>
  346. </div>
  347. </div>
  348. </label>
  349. </div>
  350. </div>
  351. ```
  352. ```html
  353. <label class="form-selectgroup-item flex-fill">
  354. <input
  355. type="radio"
  356. name="form-payment"
  357. value="mastercard"
  358. class="form-selectgroup-input"
  359. checked
  360. />
  361. <div class="form-selectgroup-label d-flex align-items-center p-3">
  362. <div class="me-3">
  363. <span class="form-selectgroup-check"></span>
  364. </div>
  365. <div>
  366. <span class="payment payment-provider-mastercard payment-xs me-2"></span>
  367. ending in <strong>2807</strong>
  368. </div>
  369. </div>
  370. </label>
  371. ```