We are experiencing a persistent issue with the KTSelect component when it's placed inside a KTDrawer that is hidden on the initial page load. The drawer's content is rendered by a Laravel Livewire component.
The Problem: When the KTDrawer is opened, the KTSelect dropdown does not render correctly. Instead of appearing attached to the select input, its dropdown HTML (<div data-kt-select-dropdown...) is appended to the bottom of the
tag. This causes it to be visually detached, incorrectly positioned, and hidden behind the drawer's backdrop overlay.Environment:
Steps to Reproduce:
Observed Behavior: The kt-select-dropdown element is created at the end of the
, outside of the drawer and its wrapper. It is not positioned correctly relative to the select input.Expected Behavior: The kt-select-dropdown element should be rendered within the kt-select-wrapper or positioned correctly by Popper.js, appearing directly below the select input and above the drawer's content and backdrop.
Attempted Solutions
We have tried multiple client-side solutions to fix this, but none have worked. Our core problem seems to be that a global script initializes the KTSelect component on initial page load while its parent drawer is hidden (display: none), leading to a broken state.
Here is a summary of what we've tried:
data-kt-select-dropdown-container:Example Code
Blade / Livewire View:
1 <div>
2 <!-- Button to trigger the drawer -->
3 <button type="button" class="btn btn-primary" wire:click="openDrawerAndReinit">
4 Open Drawer
5 </button>
6
7 <!-- The Drawer (hidden by default) -->
8 <div id="example_form_drawer" class="kt-drawer" wire:ignore.self>
9
10 11
17 18JavaScript (app.js):
This is the code that listens for the Livewire event to open the drawer and initialize components.
1 document.addEventListener("livewire:init", () => {
2 Livewire.on("drawer-opened", ({ drawerId }) => {
3 const drawerElement = document.querySelector(`#${drawerId}`);
4 if (!drawerElement) return;
5
6 const drawerInstance = KTDrawer.getInstance(drawerElement);
7 if (drawerInstance) {
8 drawerInstance.show();
9 }
10 11 // This is where we tried all the re-initialization logic mentioned above. 12 const selectElements = drawerElement.querySelectorAll('[data-kt-select="true"]'); 13 selectElements.forEach(el => { 14 // All attempts to re-initialize here have failed. 15 }); 16 }); 17 });
Our Question:
Is there an official, recommended method for correctly initializing KTSelect (and other components) that exist inside a KTDrawer or other container that is hidden on initial page load, especially within a dynamic framework like Livewire?
It seems the eager initialization strategy is causing this issue. Any guidance would be greatly appreciated.
Thanks for your time and help.
Hi
The recommended approach is to initialize KTSelect and similar components) only after the container (e.g., KTDrawer) becomes visible or after the DOM is updated. you should use the dropdownContainer: 'body' option, so the dropdown is appended to the body, preventing visibility issues caused by parent containers with overflow or hidden styles.
https://github.com/keenthemes/ktui/issues/17#issuecomment-3027362828
Thanks