slim-select 2.2.2 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -67,7 +67,7 @@ class Settings {
67
67
  this.id = 'ss-' + generateID();
68
68
  this.style = settings.style || '';
69
69
  this.class = settings.class || [];
70
- this.isEnabled = settings.isEnabled !== undefined ? settings.isEnabled : true;
70
+ this.disabled = settings.disabled !== undefined ? settings.disabled : false;
71
71
  this.alwaysOpen = settings.alwaysOpen !== undefined ? settings.alwaysOpen : false;
72
72
  this.showSearch = settings.showSearch !== undefined ? settings.showSearch : true;
73
73
  this.searchPlaceholder = settings.searchPlaceholder || 'Search';
@@ -85,6 +85,8 @@ class Settings {
85
85
  this.minSelected = settings.minSelected || 0;
86
86
  this.maxSelected = settings.maxSelected || 1000;
87
87
  this.timeoutDelay = settings.timeoutDelay || 200;
88
+ this.maxValuesShown = settings.maxValuesShown || 20;
89
+ this.maxValuesMessage = settings.maxValuesMessage || '{number} selected';
88
90
  }
89
91
  }
90
92
 
@@ -267,23 +269,21 @@ class Store {
267
269
  const dataSearch = [];
268
270
  this.data.forEach((dataObj) => {
269
271
  if (dataObj instanceof Optgroup) {
270
- if (!includeOptgroup) {
271
- dataObj.options.forEach((option) => {
272
- if (filter && filter(option)) {
273
- dataSearch.push(option);
272
+ let optOptions = [];
273
+ dataObj.options.forEach((option) => {
274
+ if (!filter || filter(option)) {
275
+ if (!includeOptgroup) {
276
+ dataSearch.push(new Option(option));
274
277
  }
275
- });
276
- }
277
- else {
278
- let optOptions = [];
279
- dataObj.options.forEach((option) => {
280
- if (!filter || filter(option)) {
278
+ else {
281
279
  optOptions.push(new Option(option));
282
280
  }
283
- });
284
- if (optOptions.length > 0) {
285
- dataSearch.push(new Optgroup(dataObj));
286
281
  }
282
+ });
283
+ if (optOptions.length > 0) {
284
+ let optgroup = new Optgroup(dataObj);
285
+ optgroup.options = optOptions;
286
+ dataSearch.push(optgroup);
287
287
  }
288
288
  }
289
289
  if (dataObj instanceof Option) {
@@ -303,6 +303,7 @@ class Render {
303
303
  placeholder: 'ss-placeholder',
304
304
  values: 'ss-values',
305
305
  single: 'ss-single',
306
+ max: 'ss-max',
306
307
  value: 'ss-value',
307
308
  valueText: 'ss-value-text',
308
309
  valueDelete: 'ss-value-delete',
@@ -359,23 +360,7 @@ class Render {
359
360
  this.main.main.classList.add(this.settings.openPosition === 'up' ? this.classes.openAbove : this.classes.openBelow);
360
361
  this.moveContent();
361
362
  this.renderOptions(this.store.getData());
362
- if (this.settings.contentPosition === 'relative') {
363
- this.moveContentBelow();
364
- }
365
- else if (this.settings.openPosition.toLowerCase() === 'up') {
366
- this.moveContentAbove();
367
- }
368
- else if (this.settings.openPosition.toLowerCase() === 'down') {
369
- this.moveContentBelow();
370
- }
371
- else {
372
- if (this.putContent(this.content.main, this.settings.isOpen) === 'up') {
373
- this.moveContentAbove();
374
- }
375
- else {
376
- this.moveContentBelow();
377
- }
378
- }
363
+ this.moveContent();
379
364
  const selectedOptions = this.store.getSelectedOptions();
380
365
  if (selectedOptions.length) {
381
366
  const selectedId = selectedOptions[selectedOptions.length - 1].id;
@@ -433,7 +418,7 @@ class Render {
433
418
  }
434
419
  };
435
420
  main.onclick = (e) => {
436
- if (!this.settings.isEnabled) {
421
+ if (this.settings.disabled) {
437
422
  return;
438
423
  }
439
424
  this.settings.isOpen ? this.callbacks.close() : this.callbacks.open();
@@ -448,7 +433,7 @@ class Render {
448
433
  }
449
434
  deselect.onclick = (e) => {
450
435
  e.stopPropagation();
451
- if (!this.settings.isEnabled) {
436
+ if (this.settings.disabled) {
452
437
  return;
453
438
  }
454
439
  let shouldDelete = true;
@@ -564,6 +549,19 @@ class Render {
564
549
  placeholder.remove();
565
550
  }
566
551
  }
552
+ if (selectedOptions.length > this.settings.maxValuesShown) {
553
+ const singleValue = document.createElement('div');
554
+ singleValue.classList.add(this.classes.max);
555
+ singleValue.textContent = this.settings.maxValuesMessage.replace('{number}', selectedOptions.length.toString());
556
+ this.main.values.innerHTML = singleValue.outerHTML;
557
+ return;
558
+ }
559
+ else {
560
+ const maxValuesMessage = this.main.values.querySelector('.' + this.classes.max);
561
+ if (maxValuesMessage) {
562
+ maxValuesMessage.remove();
563
+ }
564
+ }
567
565
  let removeNodes = [];
568
566
  for (let i = 0; i < currentNodes.length; i++) {
569
567
  const node = currentNodes[i];
@@ -618,6 +616,9 @@ class Render {
618
616
  deleteDiv.onclick = (e) => {
619
617
  e.preventDefault();
620
618
  e.stopPropagation();
619
+ if (this.settings.disabled) {
620
+ return;
621
+ }
621
622
  let shouldDelete = true;
622
623
  const before = this.store.getSelectedOptions();
623
624
  const after = before.filter((o) => {
@@ -689,12 +690,23 @@ class Render {
689
690
  }
690
691
  moveContent() {
691
692
  if (this.settings.contentPosition === 'relative') {
693
+ this.moveContentBelow();
692
694
  return;
693
695
  }
694
- const containerRect = this.main.main.getBoundingClientRect();
695
- this.content.main.style.top = containerRect.top + containerRect.height + window.scrollY + 'px';
696
- this.content.main.style.left = containerRect.left + window.scrollX + 'px';
697
- this.content.main.style.width = containerRect.width + 'px';
696
+ if (this.settings.openPosition === 'down') {
697
+ this.moveContentBelow();
698
+ return;
699
+ }
700
+ else if (this.settings.openPosition === 'up') {
701
+ this.moveContentAbove();
702
+ return;
703
+ }
704
+ if (this.putContent() === 'up') {
705
+ this.moveContentAbove();
706
+ }
707
+ else {
708
+ this.moveContentBelow();
709
+ }
698
710
  }
699
711
  searchDiv() {
700
712
  const main = document.createElement('div');
@@ -905,8 +917,7 @@ class Render {
905
917
  this.content.list.innerHTML = '';
906
918
  if (data.length === 0) {
907
919
  const noResults = document.createElement('div');
908
- noResults.classList.add(this.classes.option);
909
- noResults.classList.add(this.classes.disabled);
920
+ noResults.classList.add(this.classes.search);
910
921
  noResults.innerHTML = this.settings.searchText;
911
922
  this.content.list.appendChild(noResults);
912
923
  return;
@@ -982,7 +993,7 @@ class Render {
982
993
  optgroupClosable.appendChild(optgroupClosableSvg);
983
994
  const optgroupClosableArrow = document.createElementNS('http://www.w3.org/2000/svg', 'path');
984
995
  optgroupClosableSvg.appendChild(optgroupClosableArrow);
985
- if (d.options.some((o) => o.selected)) {
996
+ if (d.options.some((o) => o.selected) || this.content.search.input.value.trim() !== '') {
986
997
  optgroupClosable.classList.add(this.classes.open);
987
998
  optgroupClosableArrow.setAttribute('d', this.classes.arrowOpen);
988
999
  }
@@ -1041,8 +1052,7 @@ class Render {
1041
1052
  optionEl.style.cssText = option.style;
1042
1053
  }
1043
1054
  if (this.settings.searchHighlight && this.content.search.input.value.trim() !== '') {
1044
- const textOrHtml = option.html !== '' ? option.html : option.text;
1045
- optionEl.innerHTML = this.highlightText(textOrHtml, this.content.search.input.value, this.classes.searchHighlighter);
1055
+ optionEl.innerHTML = this.highlightText(option.html !== '' ? option.html : option.text, this.content.search.input.value, this.classes.searchHighlighter);
1046
1056
  }
1047
1057
  else if (option.html !== '') {
1048
1058
  optionEl.innerHTML = option.html;
@@ -1053,7 +1063,7 @@ class Render {
1053
1063
  if (this.settings.showOptionTooltips && optionEl.textContent) {
1054
1064
  optionEl.setAttribute('title', optionEl.textContent);
1055
1065
  }
1056
- if ((option.selected && !this.settings.allowDeselect) || (option.disabled && !this.settings.allowDeselect)) {
1066
+ if (option.disabled) {
1057
1067
  optionEl.classList.add(this.classes.disabled);
1058
1068
  }
1059
1069
  if (option.selected && this.settings.hideSelected) {
@@ -1074,9 +1084,8 @@ class Render {
1074
1084
  if (option.disabled || (option.selected && !this.settings.allowDeselect)) {
1075
1085
  return;
1076
1086
  }
1077
- if (this.settings.isMultiple &&
1078
- Array.isArray(selectedOptions) &&
1079
- this.settings.maxSelected <= selectedOptions.length) {
1087
+ if ((this.settings.isMultiple && this.settings.maxSelected <= selectedOptions.length && !option.selected) ||
1088
+ (this.settings.isMultiple && this.settings.minSelected >= selectedOptions.length && option.selected)) {
1080
1089
  return;
1081
1090
  }
1082
1091
  let shouldUpdate = false;
@@ -1141,23 +1150,30 @@ class Render {
1141
1150
  return completedString;
1142
1151
  }
1143
1152
  moveContentAbove() {
1144
- let mainHeight = this.main.main.offsetHeight;
1153
+ const mainHeight = this.main.main.offsetHeight;
1145
1154
  const contentHeight = this.content.main.offsetHeight;
1146
- const height = mainHeight + contentHeight - 1;
1147
- this.content.main.style.margin = '-' + height + 'px 0px 0px 0px';
1148
- this.content.main.style.transformOrigin = 'center bottom';
1149
1155
  this.main.main.classList.remove(this.classes.openBelow);
1150
1156
  this.main.main.classList.add(this.classes.openAbove);
1151
1157
  this.content.main.classList.remove(this.classes.openBelow);
1152
1158
  this.content.main.classList.add(this.classes.openAbove);
1159
+ const containerRect = this.main.main.getBoundingClientRect();
1160
+ this.content.main.style.margin = '-' + (mainHeight + contentHeight - 1) + 'px 0px 0px 0px';
1161
+ this.content.main.style.top = containerRect.top + containerRect.height + window.scrollY + 'px';
1162
+ this.content.main.style.left = containerRect.left + window.scrollX + 'px';
1163
+ this.content.main.style.width = containerRect.width + 'px';
1153
1164
  }
1154
1165
  moveContentBelow() {
1155
- this.content.main.style.margin = '-1px 0px 0px 0px';
1156
- this.content.main.style.transformOrigin = 'center top';
1157
1166
  this.main.main.classList.remove(this.classes.openAbove);
1158
1167
  this.main.main.classList.add(this.classes.openBelow);
1159
1168
  this.content.main.classList.remove(this.classes.openAbove);
1160
1169
  this.content.main.classList.add(this.classes.openBelow);
1170
+ const containerRect = this.main.main.getBoundingClientRect();
1171
+ this.content.main.style.margin = '-1px 0px 0px 0px';
1172
+ if (this.settings.contentPosition !== 'relative') {
1173
+ this.content.main.style.top = containerRect.top + containerRect.height + window.scrollY + 'px';
1174
+ this.content.main.style.left = containerRect.left + window.scrollX + 'px';
1175
+ this.content.main.style.width = containerRect.width + 'px';
1176
+ }
1161
1177
  }
1162
1178
  ensureElementInView(container, element) {
1163
1179
  const cTop = container.scrollTop + container.offsetTop;
@@ -1171,16 +1187,18 @@ class Render {
1171
1187
  container.scrollTop += eBottom - cBottom;
1172
1188
  }
1173
1189
  }
1174
- putContent(el, isOpen) {
1175
- const height = el.offsetHeight;
1176
- const rect = el.getBoundingClientRect();
1177
- const elemTop = isOpen ? rect.top : rect.top - height;
1178
- const elemBottom = isOpen ? rect.bottom : rect.bottom + height;
1179
- if (elemTop <= 0) {
1180
- return 'down';
1181
- }
1182
- if (elemBottom >= window.innerHeight) {
1183
- return 'up';
1190
+ putContent() {
1191
+ const mainHeight = this.main.main.offsetHeight;
1192
+ const mainRect = this.main.main.getBoundingClientRect();
1193
+ const contentHeight = this.content.main.offsetHeight;
1194
+ const spaceBelow = window.innerHeight - (mainRect.top + mainHeight);
1195
+ if (spaceBelow <= contentHeight) {
1196
+ if (mainRect.top > contentHeight) {
1197
+ return 'up';
1198
+ }
1199
+ else {
1200
+ return 'down';
1201
+ }
1184
1202
  }
1185
1203
  return 'down';
1186
1204
  }
@@ -1191,16 +1209,17 @@ class Select {
1191
1209
  this.listen = false;
1192
1210
  this.observer = null;
1193
1211
  this.select = select;
1212
+ this.select.addEventListener('change', this.valueChange.bind(this), {
1213
+ passive: true,
1214
+ });
1215
+ this.observer = new MutationObserver(this.observeCall.bind(this));
1216
+ this.changeListen(true);
1194
1217
  }
1195
1218
  enable() {
1196
- this.disconnectObserver();
1197
1219
  this.select.disabled = false;
1198
- this.connectObserver();
1199
1220
  }
1200
1221
  disable() {
1201
- this.disconnectObserver();
1202
1222
  this.select.disabled = true;
1203
- this.connectObserver();
1204
1223
  }
1205
1224
  hideUI() {
1206
1225
  this.select.tabIndex = -1;
@@ -1212,65 +1231,54 @@ class Select {
1212
1231
  this.select.style.display = '';
1213
1232
  this.select.removeAttribute('aria-hidden');
1214
1233
  }
1215
- changeListen(on) {
1216
- this.listen = on;
1217
- if (this.listen) {
1218
- this.connectObserver();
1234
+ changeListen(listen) {
1235
+ this.listen = listen;
1236
+ if (listen) {
1237
+ if (this.observer) {
1238
+ this.observer.observe(this.select, {
1239
+ subtree: true,
1240
+ childList: true,
1241
+ attributes: true,
1242
+ });
1243
+ }
1219
1244
  }
1220
- else {
1221
- this.disconnectObserver();
1245
+ if (!listen) {
1246
+ if (this.observer) {
1247
+ this.observer.disconnect();
1248
+ }
1222
1249
  }
1223
1250
  }
1224
- addSelectChangeListener(func) {
1225
- this.onSelectChange = func;
1226
- this.addObserver();
1227
- this.connectObserver();
1228
- this.changeListen(true);
1229
- }
1230
- removeSelectChangeListener() {
1231
- this.changeListen(false);
1232
- this.onSelectChange = undefined;
1233
- }
1234
- addValueChangeListener(func) {
1235
- this.onValueChange = func;
1236
- this.select.addEventListener('change', this.valueChange.bind(this), {
1237
- passive: true,
1238
- });
1239
- }
1240
- removeValueChangeListener() {
1241
- this.onValueChange = undefined;
1242
- this.select.removeEventListener('change', this.valueChange.bind(this));
1243
- }
1244
1251
  valueChange(ev) {
1245
1252
  if (this.listen && this.onValueChange) {
1246
1253
  this.onValueChange(this.getSelectedValues());
1247
1254
  }
1248
1255
  return true;
1249
1256
  }
1250
- observeWrapper(mutations) {
1251
- if (this.onSelectChange) {
1252
- this.changeListen(false);
1253
- this.onSelectChange(this.getData());
1254
- this.changeListen(true);
1257
+ observeCall(mutations) {
1258
+ if (!this.listen) {
1259
+ return;
1255
1260
  }
1256
- }
1257
- addObserver() {
1258
- if (this.observer) {
1259
- this.disconnectObserver();
1260
- this.observer = null;
1261
+ let disabledChanged = false;
1262
+ let optgroupOptionChanged = false;
1263
+ for (const m of mutations) {
1264
+ if (m.target === this.select) {
1265
+ if (m.attributeName === 'disabled') {
1266
+ disabledChanged = true;
1267
+ }
1268
+ }
1269
+ if (m.target.nodeName === 'OPTGROUP' || m.target.nodeName === 'OPTION') {
1270
+ optgroupOptionChanged = true;
1271
+ }
1261
1272
  }
1262
- this.observer = new MutationObserver(this.observeWrapper.bind(this));
1263
- }
1264
- connectObserver() {
1265
- if (this.observer) {
1266
- this.observer.observe(this.select, {
1267
- childList: true,
1268
- });
1273
+ if (disabledChanged && this.onDisabledChange) {
1274
+ this.changeListen(false);
1275
+ this.onDisabledChange(this.select.disabled);
1276
+ this.changeListen(true);
1269
1277
  }
1270
- }
1271
- disconnectObserver() {
1272
- if (this.observer) {
1273
- this.observer.disconnect();
1278
+ if (optgroupOptionChanged && this.onOptionsChange) {
1279
+ this.changeListen(false);
1280
+ this.onOptionsChange(this.getData());
1281
+ this.changeListen(true);
1274
1282
  }
1275
1283
  }
1276
1284
  getData() {
@@ -1288,7 +1296,7 @@ class Select {
1288
1296
  }
1289
1297
  getDataFromOptgroup(optgroup) {
1290
1298
  let data = {
1291
- id: (optgroup.dataset ? optgroup.dataset.id : false) || '',
1299
+ id: optgroup.id,
1292
1300
  label: optgroup.label,
1293
1301
  selectAll: optgroup.dataset ? optgroup.dataset.selectall === 'true' : false,
1294
1302
  closable: optgroup.dataset ? optgroup.dataset.closable : 'off',
@@ -1304,10 +1312,10 @@ class Select {
1304
1312
  }
1305
1313
  getDataFromOption(option) {
1306
1314
  return {
1307
- id: (option.dataset ? option.dataset.id : false) || '',
1315
+ id: option.id,
1308
1316
  value: option.value,
1309
1317
  text: option.text,
1310
- html: option.innerHTML,
1318
+ html: option.dataset && option.dataset.html ? option.dataset.html : '',
1311
1319
  selected: option.selected,
1312
1320
  display: option.style.display === 'none' ? false : true,
1313
1321
  disabled: option.disabled,
@@ -1343,6 +1351,7 @@ class Select {
1343
1351
  return values;
1344
1352
  }
1345
1353
  setSelected(value) {
1354
+ this.changeListen(false);
1346
1355
  const options = this.select.childNodes;
1347
1356
  for (const o of options) {
1348
1357
  if (o.nodeName === 'OPTGROUP') {
@@ -1360,6 +1369,7 @@ class Select {
1360
1369
  option.selected = value.includes(option.value);
1361
1370
  }
1362
1371
  }
1372
+ this.changeListen(true);
1363
1373
  }
1364
1374
  updateSelect(id, style, classes) {
1365
1375
  this.changeListen(false);
@@ -1412,8 +1422,12 @@ class Select {
1412
1422
  }
1413
1423
  createOption(info) {
1414
1424
  const optionEl = document.createElement('option');
1415
- optionEl.value = info.value !== '' ? info.value : info.text;
1416
- optionEl.innerHTML = info.html || info.text;
1425
+ optionEl.id = info.id;
1426
+ optionEl.value = info.value;
1427
+ optionEl.innerHTML = info.text;
1428
+ if (info.html !== '') {
1429
+ optionEl.setAttribute('data-html', info.html);
1430
+ }
1417
1431
  if (info.selected) {
1418
1432
  optionEl.selected = info.selected;
1419
1433
  }
@@ -1443,15 +1457,18 @@ class Select {
1443
1457
  }
1444
1458
  destroy() {
1445
1459
  this.changeListen(false);
1446
- this.disconnectObserver();
1447
- this.removeSelectChangeListener();
1448
- this.removeValueChangeListener();
1460
+ this.select.removeEventListener('change', this.valueChange.bind(this));
1461
+ if (this.observer) {
1462
+ this.observer.disconnect();
1463
+ this.observer = null;
1464
+ }
1449
1465
  this.showUI();
1450
1466
  }
1451
1467
  }
1452
1468
 
1453
1469
  class SlimSelect {
1454
1470
  constructor(config) {
1471
+ var _a;
1455
1472
  this.events = {
1456
1473
  search: undefined,
1457
1474
  searchFilter: (opt, search) => {
@@ -1475,23 +1492,7 @@ class SlimSelect {
1475
1492
  if (!this.settings.isOpen) {
1476
1493
  return;
1477
1494
  }
1478
- if (this.settings.openPosition === 'down') {
1479
- this.render.moveContentBelow();
1480
- return;
1481
- }
1482
- else if (this.settings.openPosition === 'up') {
1483
- this.render.moveContentAbove();
1484
- return;
1485
- }
1486
- if (this.settings.contentPosition === 'relative') {
1487
- this.render.moveContentBelow();
1488
- }
1489
- else if (this.render.putContent(this.render.content.main, this.settings.isOpen) === 'up') {
1490
- this.render.moveContentAbove();
1491
- }
1492
- else {
1493
- this.render.moveContentBelow();
1494
- }
1495
+ this.render.moveContent();
1495
1496
  });
1496
1497
  this.documentClick = (e) => {
1497
1498
  if (!this.settings.isOpen) {
@@ -1523,18 +1524,27 @@ class SlimSelect {
1523
1524
  this.events[key] = config.events[key];
1524
1525
  }
1525
1526
  }
1527
+ this.settings.disabled = ((_a = config.settings) === null || _a === void 0 ? void 0 : _a.disabled) ? config.settings.disabled : this.selectEl.disabled;
1526
1528
  this.settings.isMultiple = this.selectEl.multiple;
1527
1529
  this.settings.style = this.selectEl.style.cssText;
1528
1530
  this.settings.class = this.selectEl.className.split(' ');
1529
1531
  this.select = new Select(this.selectEl);
1530
1532
  this.select.updateSelect(this.settings.id, this.settings.style, this.settings.class);
1531
1533
  this.select.hideUI();
1532
- this.select.addSelectChangeListener((data) => {
1533
- this.setData(data);
1534
- });
1535
- this.select.addValueChangeListener((values) => {
1534
+ this.select.onValueChange = (values) => {
1536
1535
  this.setSelected(values);
1537
- });
1536
+ };
1537
+ this.select.onDisabledChange = (disabled) => {
1538
+ if (disabled) {
1539
+ this.disable();
1540
+ }
1541
+ else {
1542
+ this.enable();
1543
+ }
1544
+ };
1545
+ this.select.onOptionsChange = (data) => {
1546
+ this.setData(data);
1547
+ };
1538
1548
  this.store = new Store(this.settings.isMultiple ? 'multiple' : 'single', config.data ? config.data : this.select.getData());
1539
1549
  if (config.data) {
1540
1550
  this.select.updateOptions(this.store.getData());
@@ -1560,7 +1570,7 @@ class SlimSelect {
1560
1570
  if (this.settings.openPosition === 'auto') {
1561
1571
  window.addEventListener('scroll', this.windowScroll, false);
1562
1572
  }
1563
- if (!this.settings.isEnabled) {
1573
+ if (this.settings.disabled) {
1564
1574
  this.disable();
1565
1575
  }
1566
1576
  if (this.settings.alwaysOpen) {
@@ -1569,12 +1579,12 @@ class SlimSelect {
1569
1579
  this.selectEl.slim = this;
1570
1580
  }
1571
1581
  enable() {
1572
- this.settings.isEnabled = true;
1582
+ this.settings.disabled = false;
1573
1583
  this.select.enable();
1574
1584
  this.render.enable();
1575
1585
  }
1576
1586
  disable() {
1577
- this.settings.isEnabled = false;
1587
+ this.settings.disabled = true;
1578
1588
  this.select.disable();
1579
1589
  this.render.disable();
1580
1590
  }
@@ -1608,7 +1618,12 @@ class SlimSelect {
1608
1618
  const data = this.store.getData();
1609
1619
  this.select.updateOptions(data);
1610
1620
  this.render.renderValues();
1611
- this.render.renderOptions(data);
1621
+ if (this.render.content.search.input.value !== '') {
1622
+ this.search(this.render.content.search.input.value);
1623
+ }
1624
+ else {
1625
+ this.render.renderOptions(data);
1626
+ }
1612
1627
  if (this.events.afterChange && !isEqual(selected, this.store.getSelected())) {
1613
1628
  this.events.afterChange(this.store.getSelectedOptions());
1614
1629
  }
@@ -1625,7 +1640,7 @@ class SlimSelect {
1625
1640
  }
1626
1641
  }
1627
1642
  open() {
1628
- if (!this.settings.isEnabled || this.settings.isOpen) {
1643
+ if (this.settings.disabled || this.settings.isOpen) {
1629
1644
  return;
1630
1645
  }
1631
1646
  if (this.events.beforeOpen) {
@@ -1641,10 +1656,12 @@ class SlimSelect {
1641
1656
  }
1642
1657
  this.settings.isOpen = true;
1643
1658
  }, this.settings.timeoutDelay);
1644
- if (this.settings.intervalMove) {
1645
- clearInterval(this.settings.intervalMove);
1659
+ if (this.settings.contentPosition === 'absolute') {
1660
+ if (this.settings.intervalMove) {
1661
+ clearInterval(this.settings.intervalMove);
1662
+ }
1663
+ this.settings.intervalMove = setInterval(this.render.moveContent.bind(this.render), 500);
1646
1664
  }
1647
- this.settings.intervalMove = setInterval(this.render.moveContent.bind(this.render), 500);
1648
1665
  }
1649
1666
  close() {
1650
1667
  if (!this.settings.isOpen || this.settings.alwaysOpen) {
@@ -1760,7 +1777,7 @@ var script = defineComponent({
1760
1777
  this.slim = new SlimSelect(config);
1761
1778
  let selected = this.$props.multiple ? this.slim.getSelected() : this.slim.getSelected()[0];
1762
1779
  if (this.value !== selected) {
1763
- this.value = selected;
1780
+ this.slim.setSelected(this.value);
1764
1781
  }
1765
1782
  },
1766
1783
  beforeUnmount() {
@@ -1769,6 +1786,13 @@ var script = defineComponent({
1769
1786
  }
1770
1787
  },
1771
1788
  watch: {
1789
+ modelValue: {
1790
+ handler: function (newVal) {
1791
+ var _a;
1792
+ (_a = this.slim) === null || _a === void 0 ? void 0 : _a.setSelected(this.getCleanValue(newVal));
1793
+ },
1794
+ immediate: true,
1795
+ },
1772
1796
  data: {
1773
1797
  handler: function (newData) {
1774
1798
  if (this.slim) {
@@ -1781,18 +1805,7 @@ var script = defineComponent({
1781
1805
  computed: {
1782
1806
  value: {
1783
1807
  get() {
1784
- const multi = this.$props.multiple;
1785
- const val = this.$props.modelValue;
1786
- if (val === undefined) {
1787
- return multi ? [] : '';
1788
- }
1789
- if (multi && typeof val === 'string') {
1790
- return [val];
1791
- }
1792
- if (!multi && Array.isArray(val)) {
1793
- return val[0];
1794
- }
1795
- return multi ? [] : '';
1808
+ return this.getCleanValue(this.$props.modelValue);
1796
1809
  },
1797
1810
  set(value) {
1798
1811
  this.$emit('update:modelValue', value);
@@ -1803,6 +1816,16 @@ var script = defineComponent({
1803
1816
  getSlimSelect() {
1804
1817
  return this.slim;
1805
1818
  },
1819
+ getCleanValue(val) {
1820
+ const multi = this.$props.multiple;
1821
+ if (typeof val === 'string') {
1822
+ return multi ? [val] : val;
1823
+ }
1824
+ if (Array.isArray(val)) {
1825
+ return multi ? val : val[0];
1826
+ }
1827
+ return multi ? [] : '';
1828
+ },
1806
1829
  },
1807
1830
  });
1808
1831