Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

KTDrawer no target element


KTDrawer does not have getTargetElement like ktmodal


modal.on("show", function () {
console.log(modal.getTargetElement());
});


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (8)


Hi

Sorry about that. getRelatedTarget() returns null when used inside the show event because the related target is set after that event fires. We’ve noted this for a future release.

Workaround 1 – use the shown event
By the time shown runs, the related target is available:

drawer.on("shown", function () {
console.log(drawer.getRelatedTarget()); // returns the element that triggered the drawer
});


Workaround 2 – if you must use show
If you need the trigger inside show, use a delegated click handler to track it:

let lastToggleElement = null;

document.body.addEventListener("click", function(e) {
const toggle = e.target.closest("[data-kt-drawer-toggle]");
if (toggle) lastToggleElement = toggle;
}, true);

drawer.on("show", function () {
const trigger = lastToggleElement || drawer.getRelatedTarget();
console.log(trigger);
});

Using shown is usually enough since it runs once the drawer is open. We’ll consider fixing the timing and adding getTargetElement() in a future release.



Workaround 1 works, thank you.



Hi

KTDrawer doesn’t expose getTargetElement(), but it does expose getRelatedTarget(), which returns the element that triggered the drawer (the same idea as KTModal’s target). You can use it like this:

drawer.on("show", function () {  console.log(drawer.getRelatedTarget());});

We’ve noted the request for a getTargetElement() method to be consistent with KTModal and will consider adding it in a future release.

Thank you



Hi, that method always returns null



Hi

Sorry for the earlier mix-up. There’s no update yet. KTDrawer still doesn’t expose a getTargetElement() method like KTModal. We’ve noted the request and will consider adding it in a future release. I appreciate your patience.



We have updated the ktui.io docs. https://ktui.io/docs/tabs

Thank you



Thanks, but you answered the wrong question.



any update


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(