@keenthemes/ktui 1.0.14 → 1.0.15

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.
@@ -60,6 +60,14 @@ export class KTSelectDropdown extends KTComponent {
60
60
  this._dropdownElement = dropdownElement;
61
61
  this._config = config;
62
62
  this._ktSelectInstance = ktSelectInstance; // Assign instance
63
+
64
+ const container = this._resolveDropdownContainer();
65
+ if (container) {
66
+ if (container !== this._dropdownElement.parentElement) {
67
+ container.appendChild(this._dropdownElement);
68
+ }
69
+ }
70
+
63
71
  this._eventManager = new EventManager();
64
72
  this._focusManager = new FocusManager(
65
73
  dropdownElement,
@@ -264,16 +272,31 @@ export class KTSelectDropdown extends KTComponent {
264
272
  KTDom.reflow(this._dropdownElement);
265
273
 
266
274
  // Apply z-index
275
+ let zIndexToApply: number | null = null;
276
+
267
277
  if (this._config.dropdownZindex) {
268
- this._dropdownElement.style.zIndex =
269
- this._config.dropdownZindex.toString();
270
- } else {
271
- const parentZindex = KTDom.getHighestZindex(this._element);
272
- if (parentZindex) {
273
- this._dropdownElement.style.zIndex = (parentZindex + 1).toString();
278
+ zIndexToApply = this._config.dropdownZindex;
279
+ }
280
+
281
+ // Consider the dropdown's current z-index if it's already set and higher
282
+ const currentDropdownZIndexStr = KTDom.getCssProp(this._dropdownElement, 'z-index');
283
+ if (currentDropdownZIndexStr && currentDropdownZIndexStr !== 'auto') {
284
+ const currentDropdownZIndex = parseInt(currentDropdownZIndexStr);
285
+ if (!isNaN(currentDropdownZIndex) && currentDropdownZIndex > (zIndexToApply || 0)) {
286
+ zIndexToApply = currentDropdownZIndex;
274
287
  }
275
288
  }
276
289
 
290
+ // Ensure dropdown is above elements within its original toggle's parent context
291
+ const toggleParentContextZindex = KTDom.getHighestZindex(this._element); // _element is the select wrapper
292
+ if (toggleParentContextZindex !== null && toggleParentContextZindex >= (zIndexToApply || 0)) {
293
+ zIndexToApply = toggleParentContextZindex + 1;
294
+ }
295
+
296
+ if (zIndexToApply !== null) {
297
+ this._dropdownElement.style.zIndex = zIndexToApply.toString();
298
+ }
299
+
277
300
  // Initialize popper
278
301
  this._initPopper();
279
302
 
@@ -395,4 +418,20 @@ export class KTSelectDropdown extends KTComponent {
395
418
  // Remove data reference
396
419
  KTData.remove(this._element, this._name);
397
420
  }
421
+
422
+ private _resolveDropdownContainer(): HTMLElement | null {
423
+ const containerSelector = this._config.dropdownContainer;
424
+ if (containerSelector && containerSelector !== 'body') {
425
+ const containerElement = document.querySelector(containerSelector) as HTMLElement | null;
426
+ if (!containerElement && this._config.debug) {
427
+ console.warn(
428
+ `KTSelectDropdown: dropdownContainer selector "${containerSelector}" not found. Dropdown will remain in its default position.`,
429
+ );
430
+ }
431
+ return containerElement;
432
+ } else if (containerSelector === 'body') {
433
+ return document.body;
434
+ }
435
+ return null;
436
+ }
398
437
  }
@@ -362,10 +362,8 @@ export class KTSelect extends KTComponent {
362
362
  // Setup HTML structure
363
363
  this._createHtmlStructure();
364
364
  this._setupElementReferences();
365
- this._initZIndex();
366
365
 
367
366
  // Initialize options
368
- // this._initializeOptionsHtml();
369
367
  this._preSelectOptions(this._element);
370
368
 
371
369
  // Apply disabled state if needed
@@ -427,20 +425,27 @@ export class KTSelect extends KTComponent {
427
425
  // Add the display element to the wrapper
428
426
  wrapperElement.appendChild(displayElement);
429
427
 
430
- // Move classes from original select to display element
428
+ // Move classes from original select to wrapper and display elements
431
429
  if (this._element.classList.length > 0) {
432
- // Exclude kt-select class from being added to the wrapper element
433
- const classes = Array.from(this._element.classList).filter(
434
- (className) => className !== 'kt-select',
430
+ const originalClasses = Array.from(this._element.classList);
431
+ const displaySpecificClasses = ['kt-select', 'kt-select-sm', 'kt-select-lg'];
432
+
433
+ const classesForWrapper = originalClasses.filter(
434
+ (className) => !displaySpecificClasses.includes(className)
435
435
  );
436
- wrapperElement.classList.add(...classes);
436
+ if (classesForWrapper.length > 0) {
437
+ wrapperElement.classList.add(...classesForWrapper);
438
+ }
437
439
 
438
- // If element has class kt-select, move it to display element
439
- if (this._element.classList.contains('kt-select')) {
440
- displayElement.classList.add('kt-select');
440
+ // Move display-specific classes to display element
441
+ const classesForDisplay = originalClasses.filter(
442
+ (className) => displaySpecificClasses.includes(className)
443
+ );
444
+ if (classesForDisplay.length > 0) {
445
+ displayElement.classList.add(...classesForDisplay);
441
446
  }
442
447
 
443
- this._element.className = '';
448
+ this._element.className = ''; // Clear classes from original select element
444
449
  }
445
450
 
446
451
  // Create an empty dropdown first (without options) using template
@@ -458,9 +463,6 @@ export class KTSelect extends KTComponent {
458
463
  // Create options container using template
459
464
  const optionsContainer = defaultTemplates.options(this._config);
460
465
 
461
- // Clear the options container
462
- optionsContainer.innerHTML = '';
463
-
464
466
  // Add each option directly to the container
465
467
  options.forEach((optionElement) => {
466
468
  // Skip empty placeholder options (only if BOTH value AND text are empty)
@@ -701,25 +703,6 @@ export class KTSelect extends KTComponent {
701
703
  }
702
704
  }
703
705
 
704
- /**
705
- * Set appropriate z-index for dropdown
706
- */
707
- private _initZIndex() {
708
- let zindex: number = this._config.dropdownZindex as number;
709
- if (
710
- parseInt(KTDom.getCssProp(this._dropdownContentElement, 'z-index')) >
711
- zindex
712
- ) {
713
- zindex = parseInt(
714
- KTDom.getCssProp(this._dropdownContentElement, 'z-index'),
715
- );
716
- }
717
- if (KTDom.getHighestZindex(this._wrapperElement) > zindex) {
718
- zindex = KTDom.getHighestZindex(this._wrapperElement) + 1;
719
- }
720
- this._dropdownContentElement.style.zIndex = String(zindex);
721
- }
722
-
723
706
  /**
724
707
  * ========================================================================
725
708
  * DROPDOWN MANAGEMENT