slim-select 2.2.3 → 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.
@@ -1,25 +1,19 @@
1
1
  import { DataArray, DataArrayPartial, Optgroup, OptgroupOptional, Option } from './store';
2
2
  export default class Select {
3
3
  select: HTMLSelectElement;
4
- listen: boolean;
5
- onSelectChange?: (data: DataArrayPartial) => void;
6
4
  onValueChange?: (value: string[]) => void;
5
+ onDisabledChange?: (disabled: boolean) => void;
6
+ onOptionsChange?: (data: DataArrayPartial) => void;
7
+ listen: boolean;
7
8
  private observer;
8
9
  constructor(select: HTMLSelectElement);
9
10
  enable(): void;
10
11
  disable(): void;
11
12
  hideUI(): void;
12
13
  showUI(): void;
13
- changeListen(on: boolean): void;
14
- addSelectChangeListener(func: (data: DataArrayPartial) => void): void;
15
- removeSelectChangeListener(): void;
16
- addValueChangeListener(func: (value: string[]) => void): void;
17
- removeValueChangeListener(): void;
14
+ changeListen(listen: boolean): void;
18
15
  valueChange(ev: Event): boolean;
19
- private observeWrapper;
20
- private addObserver;
21
- private connectObserver;
22
- private disconnectObserver;
16
+ private observeCall;
23
17
  getData(): DataArrayPartial;
24
18
  getDataFromOptgroup(optgroup: HTMLOptGroupElement): OptgroupOptional;
25
19
  getDataFromOption(option: HTMLOptionElement): Option;
@@ -8,7 +8,7 @@ export default class Settings {
8
8
  isOpen: boolean;
9
9
  triggerFocus: boolean;
10
10
  intervalMove: NodeJS.Timeout | null;
11
- isEnabled: boolean;
11
+ disabled: boolean;
12
12
  alwaysOpen: boolean;
13
13
  showSearch: boolean;
14
14
  searchPlaceholder: string;
@@ -26,5 +26,7 @@ export default class Settings {
26
26
  minSelected: number;
27
27
  maxSelected: number;
28
28
  timeoutDelay: number;
29
+ maxValuesShown: number;
30
+ maxValuesMessage: string;
29
31
  constructor(settings?: SettingsPartial);
30
32
  }
@@ -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
 
@@ -301,6 +303,7 @@ class Render {
301
303
  placeholder: 'ss-placeholder',
302
304
  values: 'ss-values',
303
305
  single: 'ss-single',
306
+ max: 'ss-max',
304
307
  value: 'ss-value',
305
308
  valueText: 'ss-value-text',
306
309
  valueDelete: 'ss-value-delete',
@@ -357,23 +360,7 @@ class Render {
357
360
  this.main.main.classList.add(this.settings.openPosition === 'up' ? this.classes.openAbove : this.classes.openBelow);
358
361
  this.moveContent();
359
362
  this.renderOptions(this.store.getData());
360
- if (this.settings.contentPosition === 'relative') {
361
- this.moveContentBelow();
362
- }
363
- else if (this.settings.openPosition.toLowerCase() === 'up') {
364
- this.moveContentAbove();
365
- }
366
- else if (this.settings.openPosition.toLowerCase() === 'down') {
367
- this.moveContentBelow();
368
- }
369
- else {
370
- if (this.putContent(this.content.main, this.settings.isOpen) === 'up') {
371
- this.moveContentAbove();
372
- }
373
- else {
374
- this.moveContentBelow();
375
- }
376
- }
363
+ this.moveContent();
377
364
  const selectedOptions = this.store.getSelectedOptions();
378
365
  if (selectedOptions.length) {
379
366
  const selectedId = selectedOptions[selectedOptions.length - 1].id;
@@ -431,7 +418,7 @@ class Render {
431
418
  }
432
419
  };
433
420
  main.onclick = (e) => {
434
- if (!this.settings.isEnabled) {
421
+ if (this.settings.disabled) {
435
422
  return;
436
423
  }
437
424
  this.settings.isOpen ? this.callbacks.close() : this.callbacks.open();
@@ -446,7 +433,7 @@ class Render {
446
433
  }
447
434
  deselect.onclick = (e) => {
448
435
  e.stopPropagation();
449
- if (!this.settings.isEnabled) {
436
+ if (this.settings.disabled) {
450
437
  return;
451
438
  }
452
439
  let shouldDelete = true;
@@ -562,6 +549,19 @@ class Render {
562
549
  placeholder.remove();
563
550
  }
564
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
+ }
565
565
  let removeNodes = [];
566
566
  for (let i = 0; i < currentNodes.length; i++) {
567
567
  const node = currentNodes[i];
@@ -616,6 +616,9 @@ class Render {
616
616
  deleteDiv.onclick = (e) => {
617
617
  e.preventDefault();
618
618
  e.stopPropagation();
619
+ if (this.settings.disabled) {
620
+ return;
621
+ }
619
622
  let shouldDelete = true;
620
623
  const before = this.store.getSelectedOptions();
621
624
  const after = before.filter((o) => {
@@ -687,12 +690,23 @@ class Render {
687
690
  }
688
691
  moveContent() {
689
692
  if (this.settings.contentPosition === 'relative') {
693
+ this.moveContentBelow();
690
694
  return;
691
695
  }
692
- const containerRect = this.main.main.getBoundingClientRect();
693
- this.content.main.style.top = containerRect.top + containerRect.height + window.scrollY + 'px';
694
- this.content.main.style.left = containerRect.left + window.scrollX + 'px';
695
- 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
+ }
696
710
  }
697
711
  searchDiv() {
698
712
  const main = document.createElement('div');
@@ -903,8 +917,7 @@ class Render {
903
917
  this.content.list.innerHTML = '';
904
918
  if (data.length === 0) {
905
919
  const noResults = document.createElement('div');
906
- noResults.classList.add(this.classes.option);
907
- noResults.classList.add(this.classes.disabled);
920
+ noResults.classList.add(this.classes.search);
908
921
  noResults.innerHTML = this.settings.searchText;
909
922
  this.content.list.appendChild(noResults);
910
923
  return;
@@ -980,7 +993,7 @@ class Render {
980
993
  optgroupClosable.appendChild(optgroupClosableSvg);
981
994
  const optgroupClosableArrow = document.createElementNS('http://www.w3.org/2000/svg', 'path');
982
995
  optgroupClosableSvg.appendChild(optgroupClosableArrow);
983
- if (d.options.some((o) => o.selected)) {
996
+ if (d.options.some((o) => o.selected) || this.content.search.input.value.trim() !== '') {
984
997
  optgroupClosable.classList.add(this.classes.open);
985
998
  optgroupClosableArrow.setAttribute('d', this.classes.arrowOpen);
986
999
  }
@@ -1039,8 +1052,7 @@ class Render {
1039
1052
  optionEl.style.cssText = option.style;
1040
1053
  }
1041
1054
  if (this.settings.searchHighlight && this.content.search.input.value.trim() !== '') {
1042
- const textOrHtml = option.html !== '' ? option.html : option.text;
1043
- 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);
1044
1056
  }
1045
1057
  else if (option.html !== '') {
1046
1058
  optionEl.innerHTML = option.html;
@@ -1051,7 +1063,7 @@ class Render {
1051
1063
  if (this.settings.showOptionTooltips && optionEl.textContent) {
1052
1064
  optionEl.setAttribute('title', optionEl.textContent);
1053
1065
  }
1054
- if ((option.selected && !this.settings.allowDeselect) || (option.disabled && !this.settings.allowDeselect)) {
1066
+ if (option.disabled) {
1055
1067
  optionEl.classList.add(this.classes.disabled);
1056
1068
  }
1057
1069
  if (option.selected && this.settings.hideSelected) {
@@ -1072,9 +1084,8 @@ class Render {
1072
1084
  if (option.disabled || (option.selected && !this.settings.allowDeselect)) {
1073
1085
  return;
1074
1086
  }
1075
- if (this.settings.isMultiple &&
1076
- Array.isArray(selectedOptions) &&
1077
- 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)) {
1078
1089
  return;
1079
1090
  }
1080
1091
  let shouldUpdate = false;
@@ -1139,23 +1150,30 @@ class Render {
1139
1150
  return completedString;
1140
1151
  }
1141
1152
  moveContentAbove() {
1142
- let mainHeight = this.main.main.offsetHeight;
1153
+ const mainHeight = this.main.main.offsetHeight;
1143
1154
  const contentHeight = this.content.main.offsetHeight;
1144
- const height = mainHeight + contentHeight - 1;
1145
- this.content.main.style.margin = '-' + height + 'px 0px 0px 0px';
1146
- this.content.main.style.transformOrigin = 'center bottom';
1147
1155
  this.main.main.classList.remove(this.classes.openBelow);
1148
1156
  this.main.main.classList.add(this.classes.openAbove);
1149
1157
  this.content.main.classList.remove(this.classes.openBelow);
1150
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';
1151
1164
  }
1152
1165
  moveContentBelow() {
1153
- this.content.main.style.margin = '-1px 0px 0px 0px';
1154
- this.content.main.style.transformOrigin = 'center top';
1155
1166
  this.main.main.classList.remove(this.classes.openAbove);
1156
1167
  this.main.main.classList.add(this.classes.openBelow);
1157
1168
  this.content.main.classList.remove(this.classes.openAbove);
1158
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
+ }
1159
1177
  }
1160
1178
  ensureElementInView(container, element) {
1161
1179
  const cTop = container.scrollTop + container.offsetTop;
@@ -1169,16 +1187,18 @@ class Render {
1169
1187
  container.scrollTop += eBottom - cBottom;
1170
1188
  }
1171
1189
  }
1172
- putContent(el, isOpen) {
1173
- const height = el.offsetHeight;
1174
- const rect = el.getBoundingClientRect();
1175
- const elemTop = isOpen ? rect.top : rect.top - height;
1176
- const elemBottom = isOpen ? rect.bottom : rect.bottom + height;
1177
- if (elemTop <= 0) {
1178
- return 'down';
1179
- }
1180
- if (elemBottom >= window.innerHeight) {
1181
- 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
+ }
1182
1202
  }
1183
1203
  return 'down';
1184
1204
  }
@@ -1189,16 +1209,17 @@ class Select {
1189
1209
  this.listen = false;
1190
1210
  this.observer = null;
1191
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);
1192
1217
  }
1193
1218
  enable() {
1194
- this.disconnectObserver();
1195
1219
  this.select.disabled = false;
1196
- this.connectObserver();
1197
1220
  }
1198
1221
  disable() {
1199
- this.disconnectObserver();
1200
1222
  this.select.disabled = true;
1201
- this.connectObserver();
1202
1223
  }
1203
1224
  hideUI() {
1204
1225
  this.select.tabIndex = -1;
@@ -1210,65 +1231,54 @@ class Select {
1210
1231
  this.select.style.display = '';
1211
1232
  this.select.removeAttribute('aria-hidden');
1212
1233
  }
1213
- changeListen(on) {
1214
- this.listen = on;
1215
- if (this.listen) {
1216
- 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
+ }
1217
1244
  }
1218
- else {
1219
- this.disconnectObserver();
1245
+ if (!listen) {
1246
+ if (this.observer) {
1247
+ this.observer.disconnect();
1248
+ }
1220
1249
  }
1221
1250
  }
1222
- addSelectChangeListener(func) {
1223
- this.onSelectChange = func;
1224
- this.addObserver();
1225
- this.connectObserver();
1226
- this.changeListen(true);
1227
- }
1228
- removeSelectChangeListener() {
1229
- this.changeListen(false);
1230
- this.onSelectChange = undefined;
1231
- }
1232
- addValueChangeListener(func) {
1233
- this.onValueChange = func;
1234
- this.select.addEventListener('change', this.valueChange.bind(this), {
1235
- passive: true,
1236
- });
1237
- }
1238
- removeValueChangeListener() {
1239
- this.onValueChange = undefined;
1240
- this.select.removeEventListener('change', this.valueChange.bind(this));
1241
- }
1242
1251
  valueChange(ev) {
1243
1252
  if (this.listen && this.onValueChange) {
1244
1253
  this.onValueChange(this.getSelectedValues());
1245
1254
  }
1246
1255
  return true;
1247
1256
  }
1248
- observeWrapper(mutations) {
1249
- if (this.onSelectChange) {
1250
- this.changeListen(false);
1251
- this.onSelectChange(this.getData());
1252
- this.changeListen(true);
1257
+ observeCall(mutations) {
1258
+ if (!this.listen) {
1259
+ return;
1253
1260
  }
1254
- }
1255
- addObserver() {
1256
- if (this.observer) {
1257
- this.disconnectObserver();
1258
- 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
+ }
1259
1272
  }
1260
- this.observer = new MutationObserver(this.observeWrapper.bind(this));
1261
- }
1262
- connectObserver() {
1263
- if (this.observer) {
1264
- this.observer.observe(this.select, {
1265
- childList: true,
1266
- });
1273
+ if (disabledChanged && this.onDisabledChange) {
1274
+ this.changeListen(false);
1275
+ this.onDisabledChange(this.select.disabled);
1276
+ this.changeListen(true);
1267
1277
  }
1268
- }
1269
- disconnectObserver() {
1270
- if (this.observer) {
1271
- this.observer.disconnect();
1278
+ if (optgroupOptionChanged && this.onOptionsChange) {
1279
+ this.changeListen(false);
1280
+ this.onOptionsChange(this.getData());
1281
+ this.changeListen(true);
1272
1282
  }
1273
1283
  }
1274
1284
  getData() {
@@ -1286,7 +1296,7 @@ class Select {
1286
1296
  }
1287
1297
  getDataFromOptgroup(optgroup) {
1288
1298
  let data = {
1289
- id: (optgroup.dataset ? optgroup.dataset.id : false) || '',
1299
+ id: optgroup.id,
1290
1300
  label: optgroup.label,
1291
1301
  selectAll: optgroup.dataset ? optgroup.dataset.selectall === 'true' : false,
1292
1302
  closable: optgroup.dataset ? optgroup.dataset.closable : 'off',
@@ -1302,10 +1312,10 @@ class Select {
1302
1312
  }
1303
1313
  getDataFromOption(option) {
1304
1314
  return {
1305
- id: (option.dataset ? option.dataset.id : false) || '',
1315
+ id: option.id,
1306
1316
  value: option.value,
1307
1317
  text: option.text,
1308
- html: option.innerHTML,
1318
+ html: option.dataset && option.dataset.html ? option.dataset.html : '',
1309
1319
  selected: option.selected,
1310
1320
  display: option.style.display === 'none' ? false : true,
1311
1321
  disabled: option.disabled,
@@ -1341,6 +1351,7 @@ class Select {
1341
1351
  return values;
1342
1352
  }
1343
1353
  setSelected(value) {
1354
+ this.changeListen(false);
1344
1355
  const options = this.select.childNodes;
1345
1356
  for (const o of options) {
1346
1357
  if (o.nodeName === 'OPTGROUP') {
@@ -1358,6 +1369,7 @@ class Select {
1358
1369
  option.selected = value.includes(option.value);
1359
1370
  }
1360
1371
  }
1372
+ this.changeListen(true);
1361
1373
  }
1362
1374
  updateSelect(id, style, classes) {
1363
1375
  this.changeListen(false);
@@ -1410,8 +1422,12 @@ class Select {
1410
1422
  }
1411
1423
  createOption(info) {
1412
1424
  const optionEl = document.createElement('option');
1413
- optionEl.value = info.value !== '' ? info.value : info.text;
1414
- 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
+ }
1415
1431
  if (info.selected) {
1416
1432
  optionEl.selected = info.selected;
1417
1433
  }
@@ -1441,15 +1457,18 @@ class Select {
1441
1457
  }
1442
1458
  destroy() {
1443
1459
  this.changeListen(false);
1444
- this.disconnectObserver();
1445
- this.removeSelectChangeListener();
1446
- this.removeValueChangeListener();
1460
+ this.select.removeEventListener('change', this.valueChange.bind(this));
1461
+ if (this.observer) {
1462
+ this.observer.disconnect();
1463
+ this.observer = null;
1464
+ }
1447
1465
  this.showUI();
1448
1466
  }
1449
1467
  }
1450
1468
 
1451
1469
  class SlimSelect {
1452
1470
  constructor(config) {
1471
+ var _a;
1453
1472
  this.events = {
1454
1473
  search: undefined,
1455
1474
  searchFilter: (opt, search) => {
@@ -1473,23 +1492,7 @@ class SlimSelect {
1473
1492
  if (!this.settings.isOpen) {
1474
1493
  return;
1475
1494
  }
1476
- if (this.settings.openPosition === 'down') {
1477
- this.render.moveContentBelow();
1478
- return;
1479
- }
1480
- else if (this.settings.openPosition === 'up') {
1481
- this.render.moveContentAbove();
1482
- return;
1483
- }
1484
- if (this.settings.contentPosition === 'relative') {
1485
- this.render.moveContentBelow();
1486
- }
1487
- else if (this.render.putContent(this.render.content.main, this.settings.isOpen) === 'up') {
1488
- this.render.moveContentAbove();
1489
- }
1490
- else {
1491
- this.render.moveContentBelow();
1492
- }
1495
+ this.render.moveContent();
1493
1496
  });
1494
1497
  this.documentClick = (e) => {
1495
1498
  if (!this.settings.isOpen) {
@@ -1521,18 +1524,27 @@ class SlimSelect {
1521
1524
  this.events[key] = config.events[key];
1522
1525
  }
1523
1526
  }
1527
+ this.settings.disabled = ((_a = config.settings) === null || _a === void 0 ? void 0 : _a.disabled) ? config.settings.disabled : this.selectEl.disabled;
1524
1528
  this.settings.isMultiple = this.selectEl.multiple;
1525
1529
  this.settings.style = this.selectEl.style.cssText;
1526
1530
  this.settings.class = this.selectEl.className.split(' ');
1527
1531
  this.select = new Select(this.selectEl);
1528
1532
  this.select.updateSelect(this.settings.id, this.settings.style, this.settings.class);
1529
1533
  this.select.hideUI();
1530
- this.select.addSelectChangeListener((data) => {
1531
- this.setData(data);
1532
- });
1533
- this.select.addValueChangeListener((values) => {
1534
+ this.select.onValueChange = (values) => {
1534
1535
  this.setSelected(values);
1535
- });
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
+ };
1536
1548
  this.store = new Store(this.settings.isMultiple ? 'multiple' : 'single', config.data ? config.data : this.select.getData());
1537
1549
  if (config.data) {
1538
1550
  this.select.updateOptions(this.store.getData());
@@ -1558,7 +1570,7 @@ class SlimSelect {
1558
1570
  if (this.settings.openPosition === 'auto') {
1559
1571
  window.addEventListener('scroll', this.windowScroll, false);
1560
1572
  }
1561
- if (!this.settings.isEnabled) {
1573
+ if (this.settings.disabled) {
1562
1574
  this.disable();
1563
1575
  }
1564
1576
  if (this.settings.alwaysOpen) {
@@ -1567,12 +1579,12 @@ class SlimSelect {
1567
1579
  this.selectEl.slim = this;
1568
1580
  }
1569
1581
  enable() {
1570
- this.settings.isEnabled = true;
1582
+ this.settings.disabled = false;
1571
1583
  this.select.enable();
1572
1584
  this.render.enable();
1573
1585
  }
1574
1586
  disable() {
1575
- this.settings.isEnabled = false;
1587
+ this.settings.disabled = true;
1576
1588
  this.select.disable();
1577
1589
  this.render.disable();
1578
1590
  }
@@ -1606,7 +1618,12 @@ class SlimSelect {
1606
1618
  const data = this.store.getData();
1607
1619
  this.select.updateOptions(data);
1608
1620
  this.render.renderValues();
1609
- 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
+ }
1610
1627
  if (this.events.afterChange && !isEqual(selected, this.store.getSelected())) {
1611
1628
  this.events.afterChange(this.store.getSelectedOptions());
1612
1629
  }
@@ -1623,7 +1640,7 @@ class SlimSelect {
1623
1640
  }
1624
1641
  }
1625
1642
  open() {
1626
- if (!this.settings.isEnabled || this.settings.isOpen) {
1643
+ if (this.settings.disabled || this.settings.isOpen) {
1627
1644
  return;
1628
1645
  }
1629
1646
  if (this.events.beforeOpen) {
@@ -1639,10 +1656,12 @@ class SlimSelect {
1639
1656
  }
1640
1657
  this.settings.isOpen = true;
1641
1658
  }, this.settings.timeoutDelay);
1642
- if (this.settings.intervalMove) {
1643
- 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);
1644
1664
  }
1645
- this.settings.intervalMove = setInterval(this.render.moveContent.bind(this.render), 500);
1646
1665
  }
1647
1666
  close() {
1648
1667
  if (!this.settings.isOpen || this.settings.alwaysOpen) {
@@ -1758,7 +1777,7 @@ var script = defineComponent({
1758
1777
  this.slim = new SlimSelect(config);
1759
1778
  let selected = this.$props.multiple ? this.slim.getSelected() : this.slim.getSelected()[0];
1760
1779
  if (this.value !== selected) {
1761
- this.value = selected;
1780
+ this.slim.setSelected(this.value);
1762
1781
  }
1763
1782
  },
1764
1783
  beforeUnmount() {
@@ -1767,6 +1786,13 @@ var script = defineComponent({
1767
1786
  }
1768
1787
  },
1769
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
+ },
1770
1796
  data: {
1771
1797
  handler: function (newData) {
1772
1798
  if (this.slim) {
@@ -1779,18 +1805,7 @@ var script = defineComponent({
1779
1805
  computed: {
1780
1806
  value: {
1781
1807
  get() {
1782
- const multi = this.$props.multiple;
1783
- const val = this.$props.modelValue;
1784
- if (val === undefined) {
1785
- return multi ? [] : '';
1786
- }
1787
- if (multi && typeof val === 'string') {
1788
- return [val];
1789
- }
1790
- if (!multi && Array.isArray(val)) {
1791
- return val[0];
1792
- }
1793
- return multi ? [] : '';
1808
+ return this.getCleanValue(this.$props.modelValue);
1794
1809
  },
1795
1810
  set(value) {
1796
1811
  this.$emit('update:modelValue', value);
@@ -1801,6 +1816,16 @@ var script = defineComponent({
1801
1816
  getSlimSelect() {
1802
1817
  return this.slim;
1803
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
+ },
1804
1829
  },
1805
1830
  });
1806
1831