segmented-control.mdx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. ---
  2. title: Segmented Control
  3. summary: A segmented control is a set of two or more segments, each of which functions as a mutually exclusive button. A segmented control is used to display a set of mutually exclusive options.
  4. ---
  5. To create a segmented control, use the `nav` element with the `nav-segmented` class. Inside the `nav` element, add `button` or `a` elements with the `nav-link` class. The `nav-link` class is used to style the buttons as links.
  6. ```html
  7. <nav class="nav nav-segmented" role="tablist">
  8. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="true" aria-current="page">
  9. First
  10. </button>
  11. ...
  12. </nav>
  13. ```
  14. See the example below to see how the segmented control looks.
  15. ```html example centered background="white"
  16. <nav class="nav nav-segmented" role="tablist">
  17. <button
  18. class="nav-link active"
  19. role="tab"
  20. data-bs-toggle="tab"
  21. aria-selected="true"
  22. aria-current="page"
  23. >
  24. First
  25. </button>
  26. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  27. Second
  28. </button>
  29. <button
  30. class="nav-link"
  31. disabled
  32. role="tab"
  33. data-bs-toggle="tab"
  34. aria-selected="false"
  35. tabindex="-1"
  36. >
  37. Disabled
  38. </button>
  39. </nav>
  40. ```
  41. ## Full width
  42. To make the segmented control full width, add the `w-100` class to the `nav` element. It will take up the full width of its parent container.
  43. ```html
  44. <nav class="nav nav-segmented w-100" role="tablist">...</nav>
  45. ```
  46. The results can be seen in the example below.
  47. ```html example vcentered background="white"
  48. <nav class="nav nav-segmented w-100" role="tablist">
  49. <button
  50. class="nav-link active"
  51. role="tab"
  52. data-bs-toggle="tab"
  53. aria-selected="true"
  54. aria-current="page"
  55. >
  56. Daily
  57. </button>
  58. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  59. Weekly
  60. </button>
  61. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  62. Monthly
  63. </button>
  64. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  65. Quarterly
  66. </button>
  67. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  68. Yearly
  69. </button>
  70. </nav>
  71. ```
  72. ## With emojis
  73. You can also use emojis in the segmented control. To do this, add the emoji inside the `button` element.
  74. ```html example centered background="white"
  75. <nav class="nav nav-segmented nav-1" role="tablist">
  76. <button
  77. class="nav-link active"
  78. role="tab"
  79. data-bs-toggle="tab"
  80. aria-selected="true"
  81. aria-current="page"
  82. >
  83. πŸ‘¦
  84. </button>
  85. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  86. πŸ‘¦πŸΏ
  87. </button>
  88. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  89. πŸ‘¦πŸΎ
  90. </button>
  91. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  92. πŸ‘¦πŸ½
  93. </button>
  94. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  95. πŸ‘¦πŸΌ
  96. </button>
  97. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  98. πŸ‘¦πŸ»
  99. </button>
  100. </nav>
  101. ```
  102. ## With icons
  103. You can also use icons in the segmented control. To do this, add the icon inside the `button` element.
  104. ```html example centered background="white"
  105. <nav class="nav nav-segmented" role="tablist">
  106. <button
  107. class="nav-link active"
  108. role="tab"
  109. data-bs-toggle="tab"
  110. aria-selected="true"
  111. aria-current="page"
  112. >
  113. <!-- Download SVG icon from http://tabler.io/icons/icon/list -->
  114. <svg
  115. xmlns="http://www.w3.org/2000/svg"
  116. width="24"
  117. height="24"
  118. viewBox="0 0 24 24"
  119. fill="none"
  120. stroke="currentColor"
  121. stroke-width="2"
  122. stroke-linecap="round"
  123. stroke-linejoin="round"
  124. class="icon nav-link-icon icon-2"
  125. >
  126. <path d="M9 6l11 0"></path>
  127. <path d="M9 12l11 0"></path>
  128. <path d="M9 18l11 0"></path>
  129. <path d="M5 6l0 .01"></path>
  130. <path d="M5 12l0 .01"></path>
  131. <path d="M5 18l0 .01"></path>
  132. </svg>
  133. List
  134. </button>
  135. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  136. <!-- Download SVG icon from http://tabler.io/icons/icon/layout -->
  137. <svg
  138. xmlns="http://www.w3.org/2000/svg"
  139. width="24"
  140. height="24"
  141. viewBox="0 0 24 24"
  142. fill="none"
  143. stroke="currentColor"
  144. stroke-width="2"
  145. stroke-linecap="round"
  146. stroke-linejoin="round"
  147. class="icon nav-link-icon icon-2"
  148. >
  149. <path d="M4 4m0 2a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v1a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2z"></path>
  150. <path
  151. d="M4 13m0 2a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v3a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2z"
  152. ></path>
  153. <path
  154. d="M14 4m0 2a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2z"
  155. ></path>
  156. </svg>
  157. Kanban
  158. </button>
  159. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  160. <!-- Download SVG icon from http://tabler.io/icons/icon/calendar -->
  161. <svg
  162. xmlns="http://www.w3.org/2000/svg"
  163. width="24"
  164. height="24"
  165. viewBox="0 0 24 24"
  166. fill="none"
  167. stroke="currentColor"
  168. stroke-width="2"
  169. stroke-linecap="round"
  170. stroke-linejoin="round"
  171. class="icon nav-link-icon icon-2"
  172. >
  173. <path
  174. d="M4 7a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12z"
  175. ></path>
  176. <path d="M16 3v4"></path>
  177. <path d="M8 3v4"></path>
  178. <path d="M4 11h16"></path>
  179. <path d="M11 15h1"></path>
  180. <path d="M12 15v3"></path>
  181. </svg>
  182. Calendar
  183. </button>
  184. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  185. <!-- Download SVG icon from http://tabler.io/icons/icon/files -->
  186. <svg
  187. xmlns="http://www.w3.org/2000/svg"
  188. width="24"
  189. height="24"
  190. viewBox="0 0 24 24"
  191. fill="none"
  192. stroke="currentColor"
  193. stroke-width="2"
  194. stroke-linecap="round"
  195. stroke-linejoin="round"
  196. class="icon nav-link-icon icon-2"
  197. >
  198. <path d="M15 3v4a1 1 0 0 0 1 1h4"></path>
  199. <path d="M18 17h-7a2 2 0 0 1 -2 -2v-10a2 2 0 0 1 2 -2h4l5 5v7a2 2 0 0 1 -2 2z"></path>
  200. <path d="M16 17v2a2 2 0 0 1 -2 2h-7a2 2 0 0 1 -2 -2v-10a2 2 0 0 1 2 -2h2"></path>
  201. </svg>
  202. Files
  203. </button>
  204. </nav>
  205. ```
  206. ## Vertical direction
  207. To create a vertical segmented control, add the `nav-segmented-vertical` class to the `nav` element.
  208. ```html
  209. <nav class="nav nav-segmented-vertical" role="tablist">...</nav>
  210. ```
  211. The results can be seen in the example below.
  212. ```html example centered background="white"
  213. <nav class="nav nav-segmented nav-segmented-vertical" role="tablist">
  214. <button
  215. class="nav-link active"
  216. role="tab"
  217. data-bs-toggle="tab"
  218. aria-selected="true"
  219. aria-current="page"
  220. >
  221. <!-- Download SVG icon from http://tabler.io/icons/icon/list -->
  222. <svg
  223. xmlns="http://www.w3.org/2000/svg"
  224. width="24"
  225. height="24"
  226. viewBox="0 0 24 24"
  227. fill="none"
  228. stroke="currentColor"
  229. stroke-width="2"
  230. stroke-linecap="round"
  231. stroke-linejoin="round"
  232. class="icon nav-link-icon icon-2"
  233. >
  234. <path d="M9 6l11 0"></path>
  235. <path d="M9 12l11 0"></path>
  236. <path d="M9 18l11 0"></path>
  237. <path d="M5 6l0 .01"></path>
  238. <path d="M5 12l0 .01"></path>
  239. <path d="M5 18l0 .01"></path>
  240. </svg>
  241. List
  242. </button>
  243. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  244. <!-- Download SVG icon from http://tabler.io/icons/icon/layout -->
  245. <svg
  246. xmlns="http://www.w3.org/2000/svg"
  247. width="24"
  248. height="24"
  249. viewBox="0 0 24 24"
  250. fill="none"
  251. stroke="currentColor"
  252. stroke-width="2"
  253. stroke-linecap="round"
  254. stroke-linejoin="round"
  255. class="icon nav-link-icon icon-2"
  256. >
  257. <path d="M4 4m0 2a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v1a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2z"></path>
  258. <path
  259. d="M4 13m0 2a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v3a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2z"
  260. ></path>
  261. <path
  262. d="M14 4m0 2a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2z"
  263. ></path>
  264. </svg>
  265. Kanban
  266. </button>
  267. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  268. <!-- Download SVG icon from http://tabler.io/icons/icon/calendar -->
  269. <svg
  270. xmlns="http://www.w3.org/2000/svg"
  271. width="24"
  272. height="24"
  273. viewBox="0 0 24 24"
  274. fill="none"
  275. stroke="currentColor"
  276. stroke-width="2"
  277. stroke-linecap="round"
  278. stroke-linejoin="round"
  279. class="icon nav-link-icon icon-2"
  280. >
  281. <path
  282. d="M4 7a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12z"
  283. ></path>
  284. <path d="M16 3v4"></path>
  285. <path d="M8 3v4"></path>
  286. <path d="M4 11h16"></path>
  287. <path d="M11 15h1"></path>
  288. <path d="M12 15v3"></path>
  289. </svg>
  290. Calendar
  291. </button>
  292. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  293. <!-- Download SVG icon from http://tabler.io/icons/icon/files -->
  294. <svg
  295. xmlns="http://www.w3.org/2000/svg"
  296. width="24"
  297. height="24"
  298. viewBox="0 0 24 24"
  299. fill="none"
  300. stroke="currentColor"
  301. stroke-width="2"
  302. stroke-linecap="round"
  303. stroke-linejoin="round"
  304. class="icon nav-link-icon icon-2"
  305. >
  306. <path d="M15 3v4a1 1 0 0 0 1 1h4"></path>
  307. <path d="M18 17h-7a2 2 0 0 1 -2 -2v-10a2 2 0 0 1 2 -2h4l5 5v7a2 2 0 0 1 -2 2z"></path>
  308. <path d="M16 17v2a2 2 0 0 1 -2 2h-7a2 2 0 0 1 -2 -2v-10a2 2 0 0 1 2 -2h2"></path>
  309. </svg>
  310. Files
  311. </button>
  312. </nav>
  313. ```
  314. ## Sizes
  315. You can also change the size of the segmented control. To do this, add the `nav-sm` or `nv-lg` class to the `nav` element. The `nav-sm` class will make the segmented control smaller, while the `nav-lg` class will make it larger.
  316. ```html
  317. <nav class="nav nav-segmented nav-sm" role="tablist">...</nav>
  318. ```
  319. The results can be seen in the examples below.
  320. ```html example vertical centered background="white" separated
  321. <nav class="nav nav-segmented nav-sm" role="tablist">
  322. <button
  323. class="nav-link active"
  324. role="tab"
  325. data-bs-toggle="tab"
  326. aria-selected="true"
  327. aria-current="page"
  328. >
  329. List
  330. </button>
  331. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  332. Kanban
  333. </button>
  334. <button
  335. class="nav-link disabled"
  336. role="tab"
  337. data-bs-toggle="tab"
  338. aria-selected="false"
  339. aria-disabled="true"
  340. tabindex="-1"
  341. >
  342. Calendar
  343. </button>
  344. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  345. Files
  346. </button>
  347. </nav>
  348. <nav class="nav nav-segmented nav-lg" role="tablist">
  349. <button
  350. class="nav-link active"
  351. role="tab"
  352. data-bs-toggle="tab"
  353. aria-selected="true"
  354. aria-current="page"
  355. >
  356. List
  357. </button>
  358. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  359. Kanban
  360. </button>
  361. <button
  362. class="nav-link disabled"
  363. role="tab"
  364. data-bs-toggle="tab"
  365. aria-selected="false"
  366. aria-disabled="true"
  367. tabindex="-1"
  368. >
  369. Calendar
  370. </button>
  371. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  372. Files
  373. </button>
  374. </nav>
  375. ```