@keenthemes/ktui 1.1.1 → 1.1.2
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.
- package/dist/ktui.js +182 -190
- package/dist/ktui.min.js +1 -1
- package/dist/ktui.min.js.map +1 -1
- package/dist/styles.css +1 -1
- package/lib/cjs/components/select/combobox.js +0 -2
- package/lib/cjs/components/select/combobox.js.map +1 -1
- package/lib/cjs/components/select/config.js +4 -1
- package/lib/cjs/components/select/config.js.map +1 -1
- package/lib/cjs/components/select/dropdown.js +0 -16
- package/lib/cjs/components/select/dropdown.js.map +1 -1
- package/lib/cjs/components/select/remote.js +0 -40
- package/lib/cjs/components/select/remote.js.map +1 -1
- package/lib/cjs/components/select/search.js +80 -19
- package/lib/cjs/components/select/search.js.map +1 -1
- package/lib/cjs/components/select/select.js +98 -110
- package/lib/cjs/components/select/select.js.map +1 -1
- package/lib/cjs/components/select/tags.js +0 -2
- package/lib/cjs/components/select/tags.js.map +1 -1
- package/lib/esm/components/select/combobox.js +0 -2
- package/lib/esm/components/select/combobox.js.map +1 -1
- package/lib/esm/components/select/config.js +4 -1
- package/lib/esm/components/select/config.js.map +1 -1
- package/lib/esm/components/select/dropdown.js +0 -16
- package/lib/esm/components/select/dropdown.js.map +1 -1
- package/lib/esm/components/select/remote.js +0 -40
- package/lib/esm/components/select/remote.js.map +1 -1
- package/lib/esm/components/select/search.js +80 -19
- package/lib/esm/components/select/search.js.map +1 -1
- package/lib/esm/components/select/select.js +98 -110
- package/lib/esm/components/select/select.js.map +1 -1
- package/lib/esm/components/select/tags.js +0 -2
- package/lib/esm/components/select/tags.js.map +1 -1
- package/package.json +3 -3
- package/src/components/datatable/__tests__/race-conditions.test.ts +5 -5
- package/src/components/select/__tests__/ux-behaviors.test.ts +619 -0
- package/src/components/select/combobox.ts +0 -1
- package/src/components/select/config.ts +7 -1
- package/src/components/select/dropdown.ts +0 -24
- package/src/components/select/remote.ts +0 -49
- package/src/components/select/search.ts +85 -21
- package/src/components/select/select.ts +118 -149
- package/src/components/select/tags.ts +0 -1
|
@@ -95,8 +95,6 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
95
95
|
_this._state
|
|
96
96
|
.setItems()
|
|
97
97
|
.then(function () {
|
|
98
|
-
if (_this._config.debug)
|
|
99
|
-
console.log('Setting up component after remote data is loaded');
|
|
100
98
|
_this._setupComponent();
|
|
101
99
|
})
|
|
102
100
|
.catch(function (error) {
|
|
@@ -131,6 +129,33 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
131
129
|
// Cast to writable to allow assignment (config is readonly but needs initialization)
|
|
132
130
|
this._config = __assign(__assign(__assign(__assign(__assign({}, this._defaultConfig), KTSelect.globalConfig), this._getGlobalConfig()), KTDom.getDataAttributes(this._element, this._dataOptionPrefix + this._name)), config);
|
|
133
131
|
};
|
|
132
|
+
/**
|
|
133
|
+
* Override _dispatchEvent to also dispatch on document for global listeners (jQuery compatibility)
|
|
134
|
+
*/
|
|
135
|
+
KTSelect.prototype._dispatchEvent = function (eventType, payload) {
|
|
136
|
+
if (payload === void 0) { payload = null; }
|
|
137
|
+
// Call parent method to dispatch on element (existing behavior)
|
|
138
|
+
_super.prototype._dispatchEvent.call(this, eventType, payload);
|
|
139
|
+
// Also dispatch on document if configured
|
|
140
|
+
var dispatchGlobalEvents = this._config.dispatchGlobalEvents !== false; // Default to true
|
|
141
|
+
if (dispatchGlobalEvents) {
|
|
142
|
+
// Create namespaced event name for document dispatch
|
|
143
|
+
var namespacedEventType = "kt-select:".concat(eventType);
|
|
144
|
+
// Create event with same detail structure
|
|
145
|
+
var globalEvent = new CustomEvent(namespacedEventType, {
|
|
146
|
+
detail: {
|
|
147
|
+
payload: payload,
|
|
148
|
+
instance: this, // Include component instance reference
|
|
149
|
+
element: this._element, // Include element reference
|
|
150
|
+
},
|
|
151
|
+
bubbles: true,
|
|
152
|
+
cancelable: true,
|
|
153
|
+
composed: true, // Allow event to cross shadow DOM boundaries
|
|
154
|
+
});
|
|
155
|
+
// Dispatch on document
|
|
156
|
+
document.dispatchEvent(globalEvent);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
134
159
|
/**
|
|
135
160
|
* Initialize remote data fetching
|
|
136
161
|
*/
|
|
@@ -138,8 +163,6 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
138
163
|
var _this = this;
|
|
139
164
|
if (!this._remoteModule || !this._config.remote)
|
|
140
165
|
return;
|
|
141
|
-
if (this._config.debug)
|
|
142
|
-
console.log('Initializing remote data with URL:', this._config.dataUrl);
|
|
143
166
|
// For remote data, we need to create the HTML structure first
|
|
144
167
|
// so that the component can be properly initialized
|
|
145
168
|
this._createHtmlStructure();
|
|
@@ -150,8 +173,6 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
150
173
|
this._remoteModule
|
|
151
174
|
.fetchData()
|
|
152
175
|
.then(function (items) {
|
|
153
|
-
if (_this._config.debug)
|
|
154
|
-
console.log('Remote data fetched:', items);
|
|
155
176
|
// Remove placeholder/loading options before setting new items
|
|
156
177
|
_this._clearExistingOptions();
|
|
157
178
|
// Update state with fetched items
|
|
@@ -160,8 +181,6 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
160
181
|
.then(function () {
|
|
161
182
|
// Generate options from the fetched data
|
|
162
183
|
_this._generateOptionsHtml(_this._element);
|
|
163
|
-
if (_this._config.debug)
|
|
164
|
-
console.log('Generating options HTML from remote data');
|
|
165
184
|
// Update the dropdown to show the new options
|
|
166
185
|
_this._updateDropdownWithNewOptions();
|
|
167
186
|
// Complete the component setup with the fetched data
|
|
@@ -189,9 +208,6 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
189
208
|
var selectedOptions = Array.from(this._element.querySelectorAll('option[selected]:not([value=""])'));
|
|
190
209
|
if (selectedOptions.length > 0) {
|
|
191
210
|
this._preSelectedValues = selectedOptions.map(function (opt) { return opt.value; });
|
|
192
|
-
if (this._config.debug) {
|
|
193
|
-
console.log('Captured pre-selected values before clearing:', this._preSelectedValues);
|
|
194
|
-
}
|
|
195
211
|
}
|
|
196
212
|
// Keep only the empty/placeholder option and remove the rest
|
|
197
213
|
var options = Array.from(this._element.querySelectorAll('option:not([value=""])'));
|
|
@@ -250,9 +266,6 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
250
266
|
optionsContainer.appendChild(fragment);
|
|
251
267
|
// Update options NodeList
|
|
252
268
|
this._options = this._dropdownContentElement.querySelectorAll('[data-kt-select-option]');
|
|
253
|
-
if (this._config.debug) {
|
|
254
|
-
console.log("Rendered ".concat(optionsData.length, " options in dropdown"));
|
|
255
|
-
}
|
|
256
269
|
};
|
|
257
270
|
/**
|
|
258
271
|
* Update dropdown with new options from the original select element
|
|
@@ -277,9 +290,6 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
277
290
|
}
|
|
278
291
|
// Apply pre-selected values captured before remote data was loaded
|
|
279
292
|
if (this._preSelectedValues.length > 0) {
|
|
280
|
-
if (this._config.debug) {
|
|
281
|
-
console.log('Applying pre-selected values after remote data loaded:', this._preSelectedValues);
|
|
282
|
-
}
|
|
283
293
|
// Get all available option values from the loaded remote data
|
|
284
294
|
var availableValues_1 = Array.from(this._element.querySelectorAll('option')).map(function (opt) { return opt.value; });
|
|
285
295
|
// Filter pre-selected values to only those that exist in remote data
|
|
@@ -291,9 +301,6 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
291
301
|
var valuesToSelect = this._config.multiple
|
|
292
302
|
? validPreSelectedValues
|
|
293
303
|
: [validPreSelectedValues[0]];
|
|
294
|
-
if (this._config.debug) {
|
|
295
|
-
console.log('Selecting matched values:', valuesToSelect);
|
|
296
|
-
}
|
|
297
304
|
// Get any existing selections from _preSelectOptions (e.g., data-kt-select-pre-selected)
|
|
298
305
|
var existingSelections = this._state.getSelectedOptions();
|
|
299
306
|
// Merge existing selections with native pre-selected values (no duplicates)
|
|
@@ -310,9 +317,6 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
310
317
|
this.updateSelectedOptionDisplay();
|
|
311
318
|
this._updateSelectedOptionClass();
|
|
312
319
|
}
|
|
313
|
-
else if (this._config.debug) {
|
|
314
|
-
console.log('None of the pre-selected values matched remote data:', this._preSelectedValues);
|
|
315
|
-
}
|
|
316
320
|
// Clear the pre-selected values array after processing
|
|
317
321
|
this._preSelectedValues = [];
|
|
318
322
|
}
|
|
@@ -387,8 +391,6 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
387
391
|
// If dropdown is already created, show error message there
|
|
388
392
|
this._showDropdownMessage('error', message);
|
|
389
393
|
if (!this._wrapperElement) {
|
|
390
|
-
if (this._config.debug)
|
|
391
|
-
console.log('Setting up component after error');
|
|
392
394
|
this._setupComponent();
|
|
393
395
|
}
|
|
394
396
|
};
|
|
@@ -500,8 +502,6 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
500
502
|
});
|
|
501
503
|
// Update options NodeList to include the new options
|
|
502
504
|
this._options = this._dropdownContentElement.querySelectorAll("[data-kt-select-option]");
|
|
503
|
-
if (this._config.debug)
|
|
504
|
-
console.log("Added ".concat(newItems.length, " more options to dropdown"));
|
|
505
505
|
};
|
|
506
506
|
/**
|
|
507
507
|
* ========================================================================
|
|
@@ -640,10 +640,18 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
640
640
|
return;
|
|
641
641
|
}
|
|
642
642
|
// Get search input element - this is used for the search functionality
|
|
643
|
-
|
|
644
|
-
|
|
643
|
+
// First try to find the actual input element (not the wrapper div)
|
|
644
|
+
this._searchInputElement = this._dropdownContentElement.querySelector("input[data-kt-select-search]");
|
|
645
|
+
// If not found, try the wrapper selector (for backward compatibility)
|
|
645
646
|
if (!this._searchInputElement) {
|
|
646
|
-
|
|
647
|
+
var searchWrapper = this._dropdownContentElement.querySelector("[data-kt-select-search]");
|
|
648
|
+
if (searchWrapper) {
|
|
649
|
+
this._searchInputElement = searchWrapper.querySelector('input');
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
// If still not found in dropdown, check if it's the display element itself (combobox mode)
|
|
653
|
+
if (!this._searchInputElement) {
|
|
654
|
+
this._searchInputElement = this._displayElement.querySelector('input[data-kt-select-search]');
|
|
647
655
|
}
|
|
648
656
|
this._selectAllButton = this._wrapperElement.querySelector('[data-kt-select-select-all]');
|
|
649
657
|
// Cache the options container for performance
|
|
@@ -709,8 +717,6 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
709
717
|
KTSelect.prototype._generateOptionsHtml = function (element) {
|
|
710
718
|
var _this = this;
|
|
711
719
|
var items = this._state.getItems() || [];
|
|
712
|
-
if (this._config.debug)
|
|
713
|
-
console.log("Generating options HTML from ".concat(items.length, " items"));
|
|
714
720
|
// Only modify options if we have items to replace them with
|
|
715
721
|
if (items && items.length > 0) {
|
|
716
722
|
// Clear existing options except the first empty one
|
|
@@ -738,9 +744,6 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
738
744
|
label =
|
|
739
745
|
extractedLabel !== null ? String(extractedLabel) : 'Unnamed option';
|
|
740
746
|
}
|
|
741
|
-
// Log the extracted values for debugging
|
|
742
|
-
if (_this._config.debug)
|
|
743
|
-
console.log("Option: value=".concat(value, ", label=").concat(label));
|
|
744
747
|
// Set option attributes
|
|
745
748
|
optionElement.value = value;
|
|
746
749
|
optionElement.textContent = label || 'Unnamed option';
|
|
@@ -749,12 +752,6 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
749
752
|
}
|
|
750
753
|
element.appendChild(optionElement);
|
|
751
754
|
});
|
|
752
|
-
if (this._config.debug)
|
|
753
|
-
console.log("Added ".concat(items.length, " options to select element"));
|
|
754
|
-
}
|
|
755
|
-
else {
|
|
756
|
-
if (this._config.debug)
|
|
757
|
-
console.log('No items to generate options from');
|
|
758
755
|
}
|
|
759
756
|
};
|
|
760
757
|
/**
|
|
@@ -767,8 +764,6 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
767
764
|
var result = key
|
|
768
765
|
.split('.')
|
|
769
766
|
.reduce(function (o, k) { return (o && o[k] !== undefined ? o[k] : null); }, obj);
|
|
770
|
-
if (this._config.debug)
|
|
771
|
-
console.log("Extracting [".concat(key, "] from object => ").concat(result !== null ? JSON.stringify(result) : 'null'));
|
|
772
767
|
return result;
|
|
773
768
|
};
|
|
774
769
|
/**
|
|
@@ -801,33 +796,48 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
801
796
|
* Open the dropdown
|
|
802
797
|
*/
|
|
803
798
|
KTSelect.prototype.openDropdown = function () {
|
|
799
|
+
var _this = this;
|
|
804
800
|
if (this._config.disabled) {
|
|
805
|
-
if (this._config.debug)
|
|
806
|
-
console.log('openDropdown: select is disabled, not opening');
|
|
807
801
|
return;
|
|
808
802
|
}
|
|
809
|
-
if (this._config.debug)
|
|
810
|
-
console.log('openDropdown called, dropdownModule exists:', !!this._dropdownModule);
|
|
811
803
|
if (!this._dropdownModule) {
|
|
812
|
-
if (this._config.debug)
|
|
813
|
-
console.log('Early return from openDropdown - module missing');
|
|
814
804
|
return;
|
|
815
805
|
}
|
|
816
806
|
// Don't open dropdown if the select is disabled
|
|
817
807
|
if (this._config.disabled) {
|
|
818
|
-
if (this._config.debug)
|
|
819
|
-
console.log('Early return from openDropdown - select is disabled');
|
|
820
808
|
return;
|
|
821
809
|
}
|
|
822
|
-
if
|
|
823
|
-
|
|
810
|
+
// Global dropdown management: close other open dropdowns if configured
|
|
811
|
+
var closeOnOtherOpen = this._config.closeOnOtherOpen !== false; // Default to true
|
|
812
|
+
if (closeOnOtherOpen) {
|
|
813
|
+
// Close all other open dropdowns
|
|
814
|
+
var otherSelectsToClose_1 = [];
|
|
815
|
+
KTSelect.openDropdowns.forEach(function (otherSelect) {
|
|
816
|
+
var isOther = otherSelect !== _this;
|
|
817
|
+
var isOpen = otherSelect._dropdownIsOpen;
|
|
818
|
+
if (isOther && isOpen) {
|
|
819
|
+
otherSelectsToClose_1.push(otherSelect);
|
|
820
|
+
}
|
|
821
|
+
});
|
|
822
|
+
otherSelectsToClose_1.forEach(function (otherSelect) {
|
|
823
|
+
otherSelect.closeDropdown();
|
|
824
|
+
});
|
|
825
|
+
}
|
|
824
826
|
// Set our internal flag to match what we're doing
|
|
825
827
|
this._dropdownIsOpen = true;
|
|
828
|
+
// Add to registry
|
|
829
|
+
KTSelect.openDropdowns.add(this);
|
|
826
830
|
// Open the dropdown via the module
|
|
827
831
|
this._dropdownModule.open();
|
|
828
|
-
// Dispatch custom
|
|
832
|
+
// Dispatch custom events
|
|
829
833
|
this._dispatchEvent('show');
|
|
830
834
|
this._fireEvent('show');
|
|
835
|
+
// Dispatch dropdown.show event on wrapper for search module
|
|
836
|
+
var dropdownShowEvent = new CustomEvent('dropdown.show', {
|
|
837
|
+
bubbles: true,
|
|
838
|
+
cancelable: true,
|
|
839
|
+
});
|
|
840
|
+
this._wrapperElement.dispatchEvent(dropdownShowEvent);
|
|
831
841
|
// Update ARIA states
|
|
832
842
|
this._setAriaAttributes();
|
|
833
843
|
// Update select all button state
|
|
@@ -839,17 +849,10 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
839
849
|
* Close the dropdown
|
|
840
850
|
*/
|
|
841
851
|
KTSelect.prototype.closeDropdown = function () {
|
|
842
|
-
if (this._config.debug)
|
|
843
|
-
console.log('closeDropdown called, dropdownModule exists:', !!this._dropdownModule);
|
|
844
852
|
// Only check if dropdown module exists, not dropdownIsOpen flag
|
|
845
853
|
if (!this._dropdownModule) {
|
|
846
|
-
if (this._config.debug)
|
|
847
|
-
console.log('Early return from closeDropdown - module missing');
|
|
848
854
|
return;
|
|
849
855
|
}
|
|
850
|
-
// Always close by delegating to the dropdown module, which is the source of truth
|
|
851
|
-
if (this._config.debug)
|
|
852
|
-
console.log('Closing dropdown via dropdownModule...');
|
|
853
856
|
// Clear search input if the dropdown is closing
|
|
854
857
|
if (this._searchModule && this._searchInputElement) {
|
|
855
858
|
// Clear search input if configured to do so
|
|
@@ -861,6 +864,8 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
861
864
|
}
|
|
862
865
|
// Set our internal flag to match what we're doing
|
|
863
866
|
this._dropdownIsOpen = false;
|
|
867
|
+
// Remove from registry
|
|
868
|
+
KTSelect.openDropdowns.delete(this);
|
|
864
869
|
// Call the dropdown module's close method
|
|
865
870
|
this._dropdownModule.close();
|
|
866
871
|
// Reset all focus states
|
|
@@ -870,10 +875,14 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
870
875
|
// Dispatch custom events
|
|
871
876
|
this._dispatchEvent('close');
|
|
872
877
|
this._fireEvent('close');
|
|
878
|
+
// Dispatch dropdown.close event on wrapper for search module
|
|
879
|
+
var dropdownCloseEvent = new CustomEvent('dropdown.close', {
|
|
880
|
+
bubbles: true,
|
|
881
|
+
cancelable: true,
|
|
882
|
+
});
|
|
883
|
+
this._wrapperElement.dispatchEvent(dropdownCloseEvent);
|
|
873
884
|
// Update ARIA states
|
|
874
885
|
this._setAriaAttributes();
|
|
875
|
-
if (this._config.debug)
|
|
876
|
-
console.log('closeDropdown complete');
|
|
877
886
|
};
|
|
878
887
|
/**
|
|
879
888
|
* Update dropdown position
|
|
@@ -910,8 +919,6 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
910
919
|
KTSelect.prototype._selectOption = function (value) {
|
|
911
920
|
// Prevent selection if the option is disabled (in dropdown or original select)
|
|
912
921
|
if (this._isOptionDisabled(value)) {
|
|
913
|
-
if (this._config.debug)
|
|
914
|
-
console.log('_selectOption: Option is disabled, ignoring selection');
|
|
915
922
|
return;
|
|
916
923
|
}
|
|
917
924
|
// Get current selection state
|
|
@@ -1040,8 +1047,6 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
1040
1047
|
var selectedValues = this._state.getSelectedOptions();
|
|
1041
1048
|
var maxReached = typeof this._config.maxSelections === 'number' &&
|
|
1042
1049
|
selectedValues.length >= this._config.maxSelections;
|
|
1043
|
-
if (this._config.debug)
|
|
1044
|
-
console.log('Updating selected classes for options, selected values:', selectedValues);
|
|
1045
1050
|
allOptions.forEach(function (option) {
|
|
1046
1051
|
var optionValue = option.getAttribute('data-value');
|
|
1047
1052
|
if (!optionValue)
|
|
@@ -1142,36 +1147,24 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
1142
1147
|
* Handle clicking on an option in the dropdown
|
|
1143
1148
|
*/
|
|
1144
1149
|
KTSelect.prototype._handleOptionClick = function (event) {
|
|
1145
|
-
if (this._config.debug)
|
|
1146
|
-
console.log('_handleOptionClick called', event.target);
|
|
1147
1150
|
event.preventDefault();
|
|
1148
1151
|
event.stopPropagation();
|
|
1149
1152
|
// Find the clicked option element
|
|
1150
1153
|
var clickedOption = event.target.closest("[data-kt-select-option]");
|
|
1151
1154
|
if (!clickedOption) {
|
|
1152
|
-
if (this._config.debug)
|
|
1153
|
-
console.log('No clicked option found');
|
|
1154
1155
|
return;
|
|
1155
1156
|
}
|
|
1156
1157
|
// Check if the option is disabled
|
|
1157
1158
|
if (clickedOption.getAttribute('aria-disabled') === 'true') {
|
|
1158
|
-
if (this._config.debug)
|
|
1159
|
-
console.log('Option is disabled, ignoring click');
|
|
1160
1159
|
return;
|
|
1161
1160
|
}
|
|
1162
1161
|
// Use dataset.value to get the option value
|
|
1163
1162
|
var optionValue = clickedOption.dataset.value;
|
|
1164
1163
|
if (optionValue === undefined) {
|
|
1165
|
-
if (this._config.debug)
|
|
1166
|
-
console.log('Option value is undefined');
|
|
1167
1164
|
return;
|
|
1168
1165
|
}
|
|
1169
|
-
if (this._config.debug)
|
|
1170
|
-
console.log('Option clicked:', optionValue);
|
|
1171
1166
|
// If in single-select mode and the clicked option is already selected, just close the dropdown.
|
|
1172
1167
|
if (!this._config.multiple && this._state.isSelected(optionValue)) {
|
|
1173
|
-
if (this._config.debug)
|
|
1174
|
-
console.log('Single select mode: clicked already selected option. Closing dropdown.');
|
|
1175
1168
|
this.closeDropdown();
|
|
1176
1169
|
return;
|
|
1177
1170
|
}
|
|
@@ -1300,22 +1293,14 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
1300
1293
|
KTSelect.prototype.toggleSelection = function (value) {
|
|
1301
1294
|
// Prevent selection if the option is disabled (in dropdown or original select)
|
|
1302
1295
|
if (this._isOptionDisabled(value)) {
|
|
1303
|
-
if (this._config.debug)
|
|
1304
|
-
console.log('toggleSelection: Option is disabled, ignoring selection');
|
|
1305
1296
|
return;
|
|
1306
1297
|
}
|
|
1307
1298
|
// Get current selection state
|
|
1308
1299
|
var isSelected = this._state.isSelected(value);
|
|
1309
|
-
if (this._config.debug)
|
|
1310
|
-
console.log("toggleSelection called for value: ".concat(value, ", isSelected: ").concat(isSelected, ", multiple: ").concat(this._config.multiple));
|
|
1311
1300
|
// If already selected in single select mode, do nothing (can't deselect in single select)
|
|
1312
1301
|
if (isSelected && !this._config.multiple) {
|
|
1313
|
-
if (this._config.debug)
|
|
1314
|
-
console.log('Early return from toggleSelection - already selected in single select mode');
|
|
1315
1302
|
return;
|
|
1316
1303
|
}
|
|
1317
|
-
if (this._config.debug)
|
|
1318
|
-
console.log("Toggling selection for option: ".concat(value, ", currently selected: ").concat(isSelected));
|
|
1319
1304
|
// Ensure any search input is cleared when selection changes
|
|
1320
1305
|
if (this._searchModule) {
|
|
1321
1306
|
this._searchModule.clearSearch();
|
|
@@ -1340,16 +1325,21 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
1340
1325
|
this.updateSelectedOptionDisplay();
|
|
1341
1326
|
// Update option classes without re-rendering the dropdown content
|
|
1342
1327
|
this._updateSelectedOptionClass();
|
|
1343
|
-
// For single select mode,
|
|
1328
|
+
// For single select mode, close the dropdown after selection unless closeOnEnter is false
|
|
1344
1329
|
// For multiple select mode, keep the dropdown open to allow multiple selections
|
|
1345
1330
|
if (!this._config.multiple) {
|
|
1346
|
-
if
|
|
1347
|
-
|
|
1348
|
-
|
|
1331
|
+
// Check if we should close based on closeOnEnter config
|
|
1332
|
+
// closeOnEnter only applies to Enter key selections, but for backward compatibility,
|
|
1333
|
+
// we'll respect it for all selections when explicitly set to false
|
|
1334
|
+
var shouldClose = this._config.closeOnEnter !== false; // Default to true
|
|
1335
|
+
if (shouldClose) {
|
|
1336
|
+
this.closeDropdown();
|
|
1337
|
+
}
|
|
1338
|
+
else {
|
|
1339
|
+
this.updateSelectAllButtonState();
|
|
1340
|
+
}
|
|
1349
1341
|
}
|
|
1350
1342
|
else {
|
|
1351
|
-
if (this._config.debug)
|
|
1352
|
-
console.log('Multiple select mode - keeping dropdown open for additional selections');
|
|
1353
1343
|
// Don't close dropdown in multiple select mode to allow multiple selections
|
|
1354
1344
|
this.updateSelectAllButtonState();
|
|
1355
1345
|
}
|
|
@@ -1481,9 +1471,6 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
1481
1471
|
var validSelections = currentlySelected.filter(function (value) {
|
|
1482
1472
|
return availableValues.includes(value);
|
|
1483
1473
|
});
|
|
1484
|
-
if (_this._config.debug && currentlySelected.length > 0) {
|
|
1485
|
-
console.log('update(): Preserving selections that exist in new data:', validSelections);
|
|
1486
|
-
}
|
|
1487
1474
|
// Add new options from remote data and restore selection state
|
|
1488
1475
|
items.forEach(function (item) {
|
|
1489
1476
|
var option = document.createElement('option');
|
|
@@ -1566,9 +1553,6 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
1566
1553
|
var validSelections = currentlySelected.filter(function (value) {
|
|
1567
1554
|
return availableValues.includes(value);
|
|
1568
1555
|
});
|
|
1569
|
-
if (_this._config.debug && currentlySelected.length > 0) {
|
|
1570
|
-
console.log('reload(): Preserving selections that exist in new data:', validSelections);
|
|
1571
|
-
}
|
|
1572
1556
|
// Mark preserved selections on new options
|
|
1573
1557
|
validSelections.forEach(function (value) {
|
|
1574
1558
|
var option = Array.from(_this._element.querySelectorAll('option')).find(function (opt) { return opt.value === value; });
|
|
@@ -1632,9 +1616,6 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
1632
1616
|
var validSelections = currentlySelected.filter(function (value) {
|
|
1633
1617
|
return availableValues.includes(value);
|
|
1634
1618
|
});
|
|
1635
|
-
if (_this._config.debug && currentlySelected.length > 0) {
|
|
1636
|
-
console.log('refresh(): Preserving selections that exist in new data:', validSelections);
|
|
1637
|
-
}
|
|
1638
1619
|
// Add new options and restore selection state
|
|
1639
1620
|
items.forEach(function (item) {
|
|
1640
1621
|
var option = document.createElement('option');
|
|
@@ -1813,9 +1794,6 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
1813
1794
|
this._searchModule.refreshAfterSearch();
|
|
1814
1795
|
}
|
|
1815
1796
|
this.updateSelectAllButtonState();
|
|
1816
|
-
if (this._config.debug) {
|
|
1817
|
-
console.log('Restored original options after search clear');
|
|
1818
|
-
}
|
|
1819
1797
|
};
|
|
1820
1798
|
/**
|
|
1821
1799
|
* Update search results in the dropdown
|
|
@@ -1866,9 +1844,6 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
1866
1844
|
}
|
|
1867
1845
|
_this._element.appendChild(optionElement);
|
|
1868
1846
|
});
|
|
1869
|
-
if (this._config.debug) {
|
|
1870
|
-
console.log("Updated original select with ".concat(items.length, " search results"));
|
|
1871
|
-
}
|
|
1872
1847
|
};
|
|
1873
1848
|
/**
|
|
1874
1849
|
* Check if dropdown is open
|
|
@@ -1993,8 +1968,6 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
1993
1968
|
if (val !== undefined &&
|
|
1994
1969
|
!this._config.multiple &&
|
|
1995
1970
|
this._state.isSelected(val)) {
|
|
1996
|
-
if (this._config.debug)
|
|
1997
|
-
console.log('Enter on already selected item in single-select mode. Closing.');
|
|
1998
1971
|
this.closeDropdown();
|
|
1999
1972
|
event.preventDefault();
|
|
2000
1973
|
break;
|
|
@@ -2178,8 +2151,23 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
2178
2151
|
? this._config.clearAllText
|
|
2179
2152
|
: this._config.selectAllText;
|
|
2180
2153
|
};
|
|
2154
|
+
/**
|
|
2155
|
+
* Destroy the component and clean up resources
|
|
2156
|
+
*/
|
|
2157
|
+
KTSelect.prototype.destroy = function () {
|
|
2158
|
+
// Remove from global dropdown registry
|
|
2159
|
+
KTSelect.openDropdowns.delete(this);
|
|
2160
|
+
// Close dropdown if open
|
|
2161
|
+
if (this._dropdownIsOpen) {
|
|
2162
|
+
this.closeDropdown();
|
|
2163
|
+
}
|
|
2164
|
+
// Call parent dispose method
|
|
2165
|
+
_super.prototype.dispose.call(this);
|
|
2166
|
+
};
|
|
2181
2167
|
// Static global configuration
|
|
2182
2168
|
KTSelect.globalConfig = {};
|
|
2169
|
+
// Static registry for tracking open dropdowns (global dropdown management)
|
|
2170
|
+
KTSelect.openDropdowns = new Set();
|
|
2183
2171
|
return KTSelect;
|
|
2184
2172
|
}(KTComponent));
|
|
2185
2173
|
export { KTSelect };
|