dropdown.html 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <section>
  2. <div class="page-header">
  3. <h1 id="dropdown">Dropdown</h1>
  4. </div>
  5. <p>
  6. Select2 allows you to change the way that the dropdown works, allowing you
  7. to do anything from attach it to a different location in the document or
  8. add a search box.
  9. </p>
  10. <h2 id="dropdownParent">
  11. Attached to body
  12. </h2>
  13. <p>
  14. By default, Select2 will attach the dropdown to the end of the body and
  15. will absolutely position it to appear below the selection container.
  16. </p>
  17. <div class="row">
  18. <div class="col-sm-6">
  19. <dl class="dl-horizontal">
  20. <dt>Key</dt>
  21. <dd><code>dropdownParent</code></dd>
  22. <dt>Value</dt>
  23. <dd>jQuery element or DOM node</dd>
  24. <hr />
  25. <dt>Adapter</dt>
  26. <dd>
  27. <code title="select2/dropdown">DropdownAdapter</code>
  28. </dd>
  29. <dt>Decorator</dt>
  30. <dd>
  31. <code title="select2/dropdown/attachBody">AttachBody</code>
  32. </dd>
  33. </dl>
  34. </div>
  35. <div class="col-sm-6">
  36. <div class="alert alert-warning">
  37. <strong>Heads up!</strong>
  38. This will cause DOM events to be raised outside of the standard
  39. Select2 DOM container. This can cause issues with
  40. third-party components such as modals.
  41. </div>
  42. </div>
  43. </div>
  44. <p>
  45. When the dropdown is attached to the body, you are not limited to just
  46. displaying the dropdown below the container. Select2 will display above
  47. the container if there is not enough space below the container, but there
  48. is enough space above it. You are also not limited to displaying the
  49. dropdown within the parent container, which means Select2 will render
  50. correctly inside of modals and other small containers.
  51. </p>
  52. <h2 id="dropdown-attachContainer">
  53. Attached below the container
  54. </h2>
  55. <p>
  56. Select2 can place the dropdown directly after the selection container, so
  57. it will appear in the same location within the DOM as the rest of Select2.
  58. </p>
  59. <div class="row">
  60. <div class="col-sm-6">
  61. <dl class="dl-horizontal">
  62. <dt>Adapter</dt>
  63. <dd>
  64. <code title="select2/dropdown">DropdownAdapter</code>
  65. </dd>
  66. <dt>Decorator</dt>
  67. <dd>
  68. <code title="select2/dropdown/attachContainer">AttachContainer</code>
  69. </dd>
  70. </dl>
  71. </div>
  72. <div class="col-sm-6">
  73. <div class="alert alert-warning">
  74. <strong>Check your build.</strong> This module is only included in the
  75. <a href="index.html#builds-full" class="alert-link">full builds</a> of
  76. Select2.
  77. </div>
  78. </div>
  79. </div>
  80. <div class="alert alert-info">
  81. <strong>
  82. <a href="https://harvesthq.github.io/chosen/">Harvest Chosen</a>
  83. migrators!
  84. </strong>
  85. If you are migrating to Select2 from Chosen, this option will cause
  86. Select2 to position the dropdown in a similar way.
  87. </div>
  88. <h2 id="dropdown-search">
  89. Search
  90. </h2>
  91. <p>
  92. Users can filter down the results by typing a search term into a box that
  93. is displayed at the top of the dropdown.
  94. </p>
  95. <dl class="dl-horizontal">
  96. <dt>Adapter</dt>
  97. <dd>
  98. <code title="select2/dropdown">DropdownAdapter</code>
  99. </dd>
  100. <dt>Decorator</dt>
  101. <dd>
  102. <code title="select2/dropdown/search">DropdownSearch</code>
  103. </dd>
  104. </dl>
  105. <p>
  106. A search box is added to the top of the dropdown automatically for select
  107. boxes where only a single option can be selected.
  108. </p>
  109. <h3 id="dropdown-minimumInputLength">
  110. Minimum search term length to filter results
  111. </h3>
  112. <p>
  113. Sometimes when working with large data sets, it is more efficient to start
  114. filtering the results when the search term is a certain length. This is
  115. very common when working with remote data sets, as allows for only
  116. significant search terms to be used.
  117. </p>
  118. <div class="row">
  119. <div class="col-sm-6">
  120. <dl class="dl-horizontal">
  121. <dt>Key</dt>
  122. <dd><code>minimumInputLength</code></dd>
  123. <dt>Value</dt>
  124. <dd>integer</dd>
  125. </dl>
  126. </div>
  127. <div class="col-sm-6">
  128. <dl class="dl-horizontal">
  129. <dt>Adapter</dt>
  130. <dd>
  131. <code title="select2/data/base">DataAdapter</code>
  132. </dd>
  133. <dt>Decorator</dt>
  134. <dd>
  135. <code title="select2/data/minimumInputLength">MinimumInputLength</code>
  136. </dd>
  137. </dl>
  138. </div>
  139. </div>
  140. <h3 id="dropdown-maximumInputLength">
  141. Maximum search term length to filter results
  142. </h3>
  143. <p>
  144. In some cases, search terms need to be limited to a certain range. Select2
  145. allows you to limit the length of the search term such that it does not
  146. exceed a certain length.
  147. </p>
  148. <div class="row">
  149. <div class="col-sm-6">
  150. <dl class="dl-horizontal">
  151. <dt>Key</dt>
  152. <dd><code>maximumInputLength</code></dd>
  153. <dt>Value</dt>
  154. <dd>integer</dd>
  155. </dl>
  156. </div>
  157. <div class="col-sm-6">
  158. <dl class="dl-horizontal">
  159. <dt>Adapter</dt>
  160. <dd>
  161. <code title="select2/data/base">DataAdapter</code>
  162. </dd>
  163. <dt>Decorator</dt>
  164. <dd>
  165. <code title="select2/data/maximumInputLength">MaximumInputLength</code>
  166. </dd>
  167. </dl>
  168. </div>
  169. </div>
  170. <h3 id="dropdown-maximumInputLength">
  171. Minimum results to display the search box
  172. </h3>
  173. <p>
  174. When working with smaller data sets, the search box can take up more space
  175. that is necessary, as there are not enough results for filtering to be
  176. effective. Select2 allows you to only display the search box when the
  177. number of search results reaches a certain threshold.
  178. </p>
  179. <div class="row">
  180. <div class="col-sm-6">
  181. <dl class="dl-horizontal">
  182. <dt>Key</dt>
  183. <dd><code>minimumResultsForSearch</code></dd>
  184. <dt>Value</dt>
  185. <dd>integer</dd>
  186. </dl>
  187. </div>
  188. <div class="col-sm-6">
  189. <dl class="dl-horizontal">
  190. <dt>Adapter</dt>
  191. <dd>
  192. <code title="select2/dropdown">DropdownAdapter</code>
  193. </dd>
  194. <dt>Decorator</dt>
  195. <dd>
  196. <code title="select2/dropdown/minimumResultsForSearch">MinimumResultsForSearch</code>
  197. </dd>
  198. </dl>
  199. </div>
  200. </div>
  201. <h2 id="dropdown-select-on-close">
  202. Select the highlighted option on close
  203. </h2>
  204. <p>
  205. When users close the dropdown, the last highlighted option can be
  206. automatically selected. This is commonly used in combination with
  207. <a href="#tags">tagging</a> and <a href="#placeholder">placeholders</a>
  208. and other situations where the user is required to select an option, or
  209. they need to be able to quickly select multiple options.
  210. </p>
  211. <dl class="dl-horizontal">
  212. <dt>Adapter</dt>
  213. <dd>
  214. <code title="select2/results">ResultsAdapter</code>
  215. </dd>
  216. <dt>Decorator</dt>
  217. <dd>
  218. <code title="select2/dropdown/selectOnClose">SelectOnClose</code>
  219. </dd>
  220. </dl>
  221. <h2 id="closeOnSelect">
  222. Close the dropdown when a result is selected
  223. </h2>
  224. <p>
  225. Select2 will automatically close the dropdown when an element is selected,
  226. similar to what is done with a normal select box. This behavior can be
  227. changed though to keep the dropdown open when results are selected,
  228. allowing for multiple options to be selected quickly.
  229. </p>
  230. <div class="row">
  231. <div class="col-sm-6">
  232. <dl class="dl-horizontal">
  233. <dt>Key</dt>
  234. <dd><code>closeOnSelect</code></dd>
  235. <dt>Default</dt>
  236. <dd><code>true</code></dd>
  237. </dl>
  238. </div>
  239. <div class="col-sm-6">
  240. <dl class="dl-horizontal">
  241. <dt>Adapter</dt>
  242. <dd>
  243. <code title="select2/dropdown">DropdownAdapter</code>
  244. </dd>
  245. <dt>Decorator</dt>
  246. <dd>
  247. <code title="select2/dropdown/closeOnSelect">CloseOnSelect</code>
  248. </dd>
  249. </dl>
  250. </div>
  251. </div>
  252. <p>
  253. If this decorator is not used (or <code>closeOnSelect</code> is set to
  254. <code>false</code>), the dropdown will not automatically close when a
  255. result is selected. The dropdown will also never close if the
  256. <kbd>ctrl</kbd> key is held down when the result is selected.
  257. </p>
  258. </section>