segmented-control.mdx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 class="nav-link active" role="tab" data-bs-toggle="tab" aria-selected="true" aria-current="page">
  18. First
  19. </button>
  20. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  21. Second
  22. </button>
  23. <button class="nav-link" disabled role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  24. Disabled
  25. </button>
  26. </nav>
  27. ```
  28. ## Full width
  29. 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.
  30. ```html
  31. <nav class="nav nav-segmented w-100" role="tablist">
  32. ...
  33. </nav>
  34. ```
  35. The results can be seen in the example below.
  36. ```html example vcentered background="white"
  37. <nav class="nav nav-segmented w-100" role="tablist">
  38. <button class="nav-link active" role="tab" data-bs-toggle="tab" aria-selected="true" aria-current="page">
  39. Daily
  40. </button>
  41. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  42. Weekly
  43. </button>
  44. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  45. Monthly
  46. </button>
  47. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  48. Quarterly
  49. </button>
  50. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  51. Yearly
  52. </button>
  53. </nav>
  54. ```
  55. ## With emojis
  56. You can also use emojis in the segmented control. To do this, add the emoji inside the `button` element.
  57. ```html example centered background="white"
  58. <nav class="nav nav-segmented nav-1" role="tablist">
  59. <button class="nav-link active" role="tab" data-bs-toggle="tab" aria-selected="true" aria-current="page">
  60. 👦
  61. </button>
  62. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  63. 👦🏿
  64. </button>
  65. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  66. 👦🏾
  67. </button>
  68. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  69. 👦🏽
  70. </button>
  71. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  72. 👦🏼
  73. </button>
  74. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  75. 👦🏻
  76. </button>
  77. </nav>
  78. ```
  79. ## With icons
  80. You can also use icons in the segmented control. To do this, add the icon inside the `button` element.
  81. ```html example centered background="white"
  82. <nav class="nav nav-segmented" role="tablist">
  83. <button class="nav-link active" role="tab" data-bs-toggle="tab" aria-selected="true" aria-current="page">
  84. <!-- Download SVG icon from http://tabler.io/icons/icon/list -->
  85. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon nav-link-icon icon-2"><path d="M9 6l11 0"></path><path d="M9 12l11 0"></path><path d="M9 18l11 0"></path><path d="M5 6l0 .01"></path><path d="M5 12l0 .01"></path><path d="M5 18l0 .01"></path></svg>
  86. List
  87. </button>
  88. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  89. <!-- Download SVG icon from http://tabler.io/icons/icon/layout -->
  90. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon nav-link-icon icon-2"><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><path 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"></path><path 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"></path></svg>
  91. Kanban
  92. </button>
  93. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  94. <!-- Download SVG icon from http://tabler.io/icons/icon/calendar -->
  95. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon nav-link-icon icon-2"><path 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"></path><path d="M16 3v4"></path><path d="M8 3v4"></path><path d="M4 11h16"></path><path d="M11 15h1"></path><path d="M12 15v3"></path></svg>
  96. Calendar
  97. </button>
  98. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  99. <!-- Download SVG icon from http://tabler.io/icons/icon/files -->
  100. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon nav-link-icon icon-2"><path d="M15 3v4a1 1 0 0 0 1 1h4"></path><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><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></svg>
  101. Files
  102. </button>
  103. </nav>
  104. ```
  105. ## Vertical direction
  106. To create a vertical segmented control, add the `nav-segmented-vertical` class to the `nav` element.
  107. ```html
  108. <nav class="nav nav-segmented-vertical" role="tablist">
  109. ...
  110. </nav>
  111. ```
  112. The results can be seen in the example below.
  113. ```html example centered background="white"
  114. <nav class="nav nav-segmented nav-segmented-vertical" role="tablist">
  115. <button class="nav-link active" role="tab" data-bs-toggle="tab" aria-selected="true" aria-current="page">
  116. <!-- Download SVG icon from http://tabler.io/icons/icon/list -->
  117. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon nav-link-icon icon-2"><path d="M9 6l11 0"></path><path d="M9 12l11 0"></path><path d="M9 18l11 0"></path><path d="M5 6l0 .01"></path><path d="M5 12l0 .01"></path><path d="M5 18l0 .01"></path></svg>
  118. List
  119. </button>
  120. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  121. <!-- Download SVG icon from http://tabler.io/icons/icon/layout -->
  122. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon nav-link-icon icon-2"><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><path 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"></path><path 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"></path></svg>
  123. Kanban
  124. </button>
  125. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  126. <!-- Download SVG icon from http://tabler.io/icons/icon/calendar -->
  127. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon nav-link-icon icon-2"><path 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"></path><path d="M16 3v4"></path><path d="M8 3v4"></path><path d="M4 11h16"></path><path d="M11 15h1"></path><path d="M12 15v3"></path></svg>
  128. Calendar
  129. </button>
  130. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  131. <!-- Download SVG icon from http://tabler.io/icons/icon/files -->
  132. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon nav-link-icon icon-2"><path d="M15 3v4a1 1 0 0 0 1 1h4"></path><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><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></svg>
  133. Files
  134. </button>
  135. </nav>
  136. ```
  137. ## Sizes
  138. 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.
  139. ```html
  140. <nav class="nav nav-segmented nav-sm" role="tablist">
  141. ...
  142. </nav>
  143. ```
  144. The results can be seen in the examples below.
  145. ```html example vertical centered background="white" separated
  146. <nav class="nav nav-segmented nav-sm" role="tablist">
  147. <button class="nav-link active" role="tab" data-bs-toggle="tab" aria-selected="true" aria-current="page">
  148. List
  149. </button>
  150. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  151. Kanban
  152. </button>
  153. <button class="nav-link disabled" role="tab" data-bs-toggle="tab" aria-selected="false" aria-disabled="true" tabindex="-1">
  154. Calendar
  155. </button>
  156. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  157. Files
  158. </button>
  159. </nav>
  160. <nav class="nav nav-segmented nav-lg" role="tablist">
  161. <button class="nav-link active" role="tab" data-bs-toggle="tab" aria-selected="true" aria-current="page">
  162. List
  163. </button>
  164. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  165. Kanban
  166. </button>
  167. <button class="nav-link disabled" role="tab" data-bs-toggle="tab" aria-selected="false" aria-disabled="true" tabindex="-1">
  168. Calendar
  169. </button>
  170. <button class="nav-link" role="tab" data-bs-toggle="tab" aria-selected="false" tabindex="-1">
  171. Files
  172. </button>
  173. </nav>
  174. ```