Skip to content

Commit ffe389d

Browse files
committed
Add compatibility with Select2 4.1
- Uses Bootstrap's `custom-select` implementation for uniformity - Use SVG background image for clear button - Add some lints to improve code readability Ref: https://getbootstrap.com/docs/4.6/components/forms/#select-menu Close: #49
1 parent b06f529 commit ffe389d

File tree

6 files changed

+228
-243
lines changed

6 files changed

+228
-243
lines changed

.stylelintrc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
"stylelint-config-twbs-bootstrap/scss"
44
],
55
"rules": {
6-
"selector-class-pattern": "^[a-z][a-z0-9\\-_]*[a-z0-9]$"
6+
"block-closing-brace-empty-line-before": "never",
7+
"declaration-no-important": null,
8+
"rule-empty-line-before": ["always", {
9+
"except": ["first-nested"],
10+
"ignore": ["after-comment"]
11+
}],
12+
"selector-class-pattern": "^[a-z][a-z0-9\\-_]*[a-z0-9]$",
13+
"selector-no-qualifying-type": null
714
}
815
}

dist/select2-bootstrap4.css

Lines changed: 85 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,21 @@
1818

1919
.select2-container--bootstrap4 .select2-selection {
2020
width: 100%;
21+
min-height: calc(1.5em + 0.75rem + 2px);
22+
padding: 0.375rem 1.75rem 0.375rem 0.75rem;
23+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
24+
font-size: 1rem;
25+
font-weight: 400;
26+
line-height: 1.5;
27+
color: #495057;
28+
vertical-align: middle;
2129
background-color: #fff;
2230
border: 1px solid #ced4da;
2331
border-radius: 0.25rem;
24-
-webkit-transition: border-color 0.15s ease-in-out, -webkit-box-shadow 0.15s ease-in-out;
25-
transition: border-color 0.15s ease-in-out, -webkit-box-shadow 0.15s ease-in-out;
26-
transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
27-
transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out, -webkit-box-shadow 0.15s ease-in-out; }
32+
-webkit-transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, -webkit-box-shadow 0.15s ease-in-out;
33+
transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, -webkit-box-shadow 0.15s ease-in-out;
34+
transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
35+
transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out, -webkit-box-shadow 0.15s ease-in-out; }
2836
@media (prefers-reduced-motion: reduce) {
2937
.select2-container--bootstrap4 .select2-selection {
3038
-webkit-transition: none;
@@ -35,11 +43,6 @@
3543
-webkit-box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
3644
box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25); }
3745

38-
.select2-container--bootstrap4.select2-container--focus.select2-container--open .select2-selection {
39-
border-bottom: none;
40-
border-bottom-right-radius: 0;
41-
border-bottom-left-radius: 0; }
42-
4346
.select2-container--bootstrap4.select2-container--open.select2-container--above .select2-selection {
4447
border-top-left-radius: 0;
4548
border-top-right-radius: 0; }
@@ -48,16 +51,14 @@
4851
border-bottom-right-radius: 0;
4952
border-bottom-left-radius: 0; }
5053

51-
.select2-container--bootstrap4.select2-container--disabled .select2-selection, .select2-container--bootstrap4.select2-container--disabled.select2-container--focus .select2-selection {
54+
.select2-container--bootstrap4.select2-container--disabled .select2-selection,
55+
.select2-container--bootstrap4.select2-container--disabled .select2-search__field {
5256
cursor: not-allowed;
5357
background-color: #e9ecef;
5458
border-color: #ced4da;
5559
-webkit-box-shadow: none;
5660
box-shadow: none; }
5761

58-
.select2-container--bootstrap4.select2-container--disabled .select2-search__field, .select2-container--bootstrap4.select2-container--disabled.select2-container--focus .select2-search__field {
59-
background-color: transparent; }
60-
6162
select.is-invalid ~ .select2-container--bootstrap4 .select2-selection,
6263
form.was-validated select:invalid ~ .select2-container--bootstrap4 .select2-selection {
6364
border-color: #dc3545; }
@@ -66,136 +67,126 @@ select.is-valid ~ .select2-container--bootstrap4 .select2-selection,
6667
form.was-validated select:valid ~ .select2-container--bootstrap4 .select2-selection {
6768
border-color: #28a745; }
6869

69-
.select2-container--bootstrap4 .select2-search {
70-
width: 100%; }
71-
7270
.select2-container--bootstrap4 .select2-dropdown {
7371
border-color: #ced4da;
7472
border-radius: 0; }
7573
.select2-container--bootstrap4 .select2-dropdown.select2-dropdown--below {
76-
border-top: none;
7774
border-bottom-right-radius: 0.25rem;
7875
border-bottom-left-radius: 0.25rem; }
7976
.select2-container--bootstrap4 .select2-dropdown.select2-dropdown--above {
80-
border-top: 1px solid #ced4da;
8177
border-top-left-radius: 0.25rem;
8278
border-top-right-radius: 0.25rem; }
83-
.select2-container--bootstrap4 .select2-dropdown .select2-results__option[aria-selected="true"] {
84-
color: #212529;
85-
background-color: #f2f2f2; }
86-
87-
.select2-container--bootstrap4 .select2-results__option--highlighted,
88-
.select2-container--bootstrap4 .select2-results__option--highlighted.select2-results__option[aria-selected="true"] {
89-
color: #fff;
90-
background-color: #007bff; }
91-
92-
.select2-container--bootstrap4 .select2-results__option[role="group"] {
93-
padding: 0; }
94-
.select2-container--bootstrap4 .select2-results__option[role="group"] .select2-results__options--nested .select2-results__option {
95-
padding-left: 1em; }
9679

9780
.select2-container--bootstrap4 .select2-results__option {
9881
padding: 0.375rem 0.75rem; }
82+
.select2-container--bootstrap4 .select2-results__option--selected {
83+
color: #212529;
84+
background-color: #e9ecef; }
85+
.select2-container--bootstrap4 .select2-results__option--highlighted {
86+
color: #fff;
87+
background-color: #007bff; }
88+
.select2-container--bootstrap4 .select2-results__option--group {
89+
padding: 0; }
90+
.select2-container--bootstrap4 .select2-results__option--group .select2-results__options--nested .select2-results__option {
91+
padding-left: 0.75rem; }
9992

10093
.select2-container--bootstrap4 .select2-results > .select2-results__options {
10194
max-height: 15em;
10295
overflow-y: auto; }
10396

10497
.select2-container--bootstrap4 .select2-results__group {
10598
display: list-item;
106-
padding: 6px;
99+
padding: 0.375rem 0.375rem;
107100
color: #6c757d; }
108101

109102
.select2-container--bootstrap4 .select2-selection__clear {
110103
float: right;
111-
width: .9em;
112-
height: .9em;
113-
padding-left: .15em;
114-
margin-top: .7em;
115-
margin-right: .3em;
116-
line-height: .75em;
117-
color: #f8f9fa;
118-
background-color: #c8c8c8;
104+
width: 1em;
105+
height: 1em;
106+
padding: 0;
107+
margin: 0.25em 0 0;
108+
font-weight: 700;
109+
line-height: 0.75em;
110+
color: #495057;
111+
background: #e6e6e6 url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 16 16'%3e%3cpath fill='%23495057' d='M1 12l4-4-4-4 3-3 4 4 4-4 3 3-4 4 4 4-3 3-4-4-4 4z'/%3e%3c/svg%3e") center no-repeat !important;
119112
border-radius: 100%; }
113+
.select2-container--bootstrap4 .select2-selection__clear span {
114+
display: none; }
120115
.select2-container--bootstrap4 .select2-selection__clear:hover {
121-
background-color: #afafaf; }
116+
background-color: #d9d9d9 !important; }
117+
118+
.select2-container--bootstrap4 .select2-results__message {
119+
color: #6c757d; }
122120

123121
.select2-container--bootstrap4 .select2-selection--single {
124-
height: calc(1.5em + 0.75rem + 2px) !important; }
122+
background: #fff url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='4' height='5' viewBox='0 0 4 5'%3e%3cpath fill='%23343a40' d='M2 0L0 2h4zm0 5L0 3h4z'/%3e%3c/svg%3e") right 0.75rem center/8px 10px no-repeat; }
125123
.select2-container--bootstrap4 .select2-selection--single .select2-selection__placeholder {
126-
line-height: calc(1.5em + 0.75rem);
127124
color: #6c757d; }
128-
.select2-container--bootstrap4 .select2-selection--single .select2-selection__arrow {
129-
position: absolute;
130-
top: 50%;
131-
right: 3px;
132-
width: 20px; }
133-
.select2-container--bootstrap4 .select2-selection--single .select2-selection__arrow b {
134-
position: absolute;
135-
top: 60%;
136-
left: 50%;
137-
width: 0;
138-
height: 0;
139-
margin-top: -2px;
140-
margin-left: -4px;
141-
border-color: #343a40 transparent transparent transparent;
142-
border-style: solid;
143-
border-width: 5px 4px 0; }
144125
.select2-container--bootstrap4 .select2-selection--single .select2-selection__rendered {
145-
padding-left: 0.75rem;
146-
line-height: calc(1.5em + 0.75rem);
126+
padding: 0;
147127
color: #495057; }
148128

149-
.select2-search--dropdown .select2-search__field {
129+
.select2-container--bootstrap4 .select2-search--dropdown .select2-search__field {
150130
padding: 0.375rem 0.75rem;
131+
color: #495057;
151132
border: 1px solid #ced4da;
152133
border-radius: 0.25rem; }
153-
154-
.select2-results__message {
155-
color: #6c757d; }
134+
.select2-container--bootstrap4 .select2-search--dropdown .select2-search__field:focus {
135+
color: #495057;
136+
background-color: #fff;
137+
border-color: #80bdff;
138+
outline: 0;
139+
-webkit-box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
140+
box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25); }
156141

157142
.select2-container--bootstrap4 .select2-selection--multiple {
158-
min-height: calc(1.5em + 0.75rem + 2px) !important; }
143+
padding: 0 0.75rem; }
159144
.select2-container--bootstrap4 .select2-selection--multiple .select2-selection__rendered {
160-
-webkit-box-sizing: border-box;
161-
box-sizing: border-box;
162-
width: 100%;
163-
padding: 0 0.375rem;
164-
margin: 0;
165-
list-style: none; }
145+
margin: 0; }
146+
.select2-container--bootstrap4 .select2-selection--multiple .select2-search--inline {
147+
display: inline-block; }
166148
.select2-container--bootstrap4 .select2-selection--multiple .select2-selection__choice {
167-
float: left;
168-
padding: 0;
169-
padding-right: 0.75rem;
170-
margin-top: calc(0.375rem - 2px);
171-
margin-right: 0.375rem;
172-
color: #495057;
149+
position: relative;
150+
display: inline-block;
151+
padding: 0 5px 0 21px;
152+
margin: 0.375rem 0.375rem 0.375rem 0;
153+
color: #fff;
154+
vertical-align: top;
173155
cursor: pointer;
174-
border: 1px solid #bdc6d0;
156+
background-color: #6c757d;
175157
border-radius: 0.2rem; }
158+
.select2-container--bootstrap4 .select2-selection--multiple .select2-selection__choice__display {
159+
padding: 0 5px; }
176160
.select2-container--bootstrap4 .select2-selection--multiple .select2-search__field {
161+
height: calc(1.5em + 0.75rem);
162+
padding-top: 0.375rem;
163+
margin: 0;
164+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
165+
line-height: 1.5;
177166
color: #495057; }
178-
.select2-container--bootstrap4 .select2-selection--multiple .select2-selection__choice + .select2-search {
179-
width: 0; }
180167
.select2-container--bootstrap4 .select2-selection--multiple .select2-selection__choice__remove {
181-
float: left;
182-
padding-right: 3px;
183-
padding-left: 3px;
184-
margin-right: 1px;
185-
margin-left: 3px;
168+
position: absolute;
169+
top: 0;
170+
left: 0;
171+
padding: 0 5px;
172+
margin: 0;
186173
font-weight: 700;
187-
color: #bdc6d0; }
174+
color: rgba(255, 255, 255, 0.75);
175+
cursor: pointer;
176+
background: none;
177+
border: none;
178+
border-right: 1px solid #a1a8ae; }
188179
.select2-container--bootstrap4 .select2-selection--multiple .select2-selection__choice__remove:hover {
189-
color: #343a40; }
180+
color: rgba(255, 255, 255, 0.85); }
181+
.select2-container--bootstrap4 .select2-selection--multiple.select2-selection--clearable {
182+
padding-right: 32px; }
190183
.select2-container--bootstrap4 .select2-selection--multiple .select2-selection__clear {
191-
position: absolute !important;
192-
top: 0;
193-
right: .7em;
194-
float: none;
195-
margin-right: 0; }
184+
position: absolute;
185+
top: 0.375rem;
186+
right: 0.75rem; }
196187

197188
.select2-container--bootstrap4.select2-container--disabled .select2-selection--multiple .select2-selection__choice {
198-
padding: 0 5px;
189+
padding-left: 5px;
199190
cursor: not-allowed; }
200191
.select2-container--bootstrap4.select2-container--disabled .select2-selection--multiple .select2-selection__choice .select2-selection__choice__remove {
201192
display: none; }

0 commit comments

Comments
 (0)