summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/behaviors/select2.js
blob: 37b75bb5e564a69ecbaeeff5f8081301a8b5f997 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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(() => {});
  }
};