diff options
Diffstat (limited to 'app/assets/javascripts/behaviors/select2.js')
-rw-r--r-- | app/assets/javascripts/behaviors/select2.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/app/assets/javascripts/behaviors/select2.js b/app/assets/javascripts/behaviors/select2.js new file mode 100644 index 00000000000..37b75bb5e56 --- /dev/null +++ b/app/assets/javascripts/behaviors/select2.js @@ -0,0 +1,23 @@ +import $ from 'jquery'; + +export default () => { + if ($('select.select2').length) { + import(/* webpackChunkName: 'select2' */ 'select2/select2') + .then(() => { + $('select.select2').select2({ + width: 'resolve', + minimumResultsForSearch: 10, + dropdownAutoWidth: true, + }); + + // Close select2 on escape + $('.js-select2').on('select2-close', () => { + setTimeout(() => { + $('.select2-container-active').removeClass('select2-container-active'); + $(':focus').blur(); + }, 1); + }); + }) + .catch(() => {}); + } +}; |