<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Bozoanca Rares Mihail</title>
    <description>The latest articles on Forem by Bozoanca Rares Mihail (@raresmihail).</description>
    <link>https://forem.com/raresmihail</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1186199%2F14d9adec-c158-4f30-a1a0-0d4411773d45.jpg</url>
      <title>Forem: Bozoanca Rares Mihail</title>
      <link>https://forem.com/raresmihail</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/raresmihail"/>
    <language>en</language>
    <item>
      <title>How to attach Kendo UI Popup to component</title>
      <dc:creator>Bozoanca Rares Mihail</dc:creator>
      <pubDate>Mon, 16 Oct 2023 16:31:52 +0000</pubDate>
      <link>https://forem.com/raresmihail/how-to-attach-kendo-ui-popup-to-component-30b9</link>
      <guid>https://forem.com/raresmihail/how-to-attach-kendo-ui-popup-to-component-30b9</guid>
      <description>&lt;h2&gt;
  
  
  Preface
&lt;/h2&gt;

&lt;p&gt;This is a step by step guide that shows how to attach the &lt;em&gt;Kendo Popup&lt;/em&gt; to the Kendo Dropdown, as by default the Popup is attached to the &lt;a href="https://stackoverflow.com/questions/53584403/angular-kendo-popup-element-is-attached-to-very-end-of-dom"&gt;very end of the DOM&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I am writing this guide as I simply could not find one like it and hopefully it might prove useful to at least one other person.&lt;/p&gt;




&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;First start a new Angular project by sending the following command line in the terminal:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;ng new KendoDropDownPopup&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Then &lt;u&gt;generate&lt;/u&gt; a new angular component called dropdown-list:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;ng g c dropdown-list&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And add the newly generated component into the app.component.html &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bULyDl24--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/puhgvimy05ryuv222g41.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bULyDl24--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/puhgvimy05ryuv222g41.png" alt="Content of app.component.html file" width="475" height="98"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Finally install kendo-angular-dropdowns:&lt;br&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;ng add @progress/kendo-angular-dropdowns&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Actual solution
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;In the previously &lt;u&gt;generated&lt;/u&gt; dropdown-list.component.ts add a couple of list options for the dropdown:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="nx"&gt;listOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;First option&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Second option&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Third option&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In the dropdown-list.component.html file add the Kendo Dropdown:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;kendo-dropdownlist&lt;/span&gt;
    &lt;span class="na"&gt;[data]=&lt;/span&gt;&lt;span class="s"&gt;"listOptions"&lt;/span&gt;
    &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;"width: 200px; margin: 16px;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/kendo-dropdownlist&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This is how the Kendo Dropdown should look:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G7B5IqJ0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fxoqwndpfguv2igxh86i.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G7B5IqJ0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fxoqwndpfguv2igxh86i.PNG" alt="Expanded Kendo Dropdown" width="362" height="218"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Next we need to be able to &lt;u&gt;see the &lt;em&gt;Kendo Popup&lt;/em&gt; in the page source&lt;/u&gt; and check if it is attached to the &lt;a href="https://stackoverflow.com/questions/53584403/angular-kendo-popup-element-is-attached-to-very-end-of-dom"&gt;very end of the DOM&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;small&gt;In order to see the &lt;em&gt;Kendo Popup&lt;/em&gt;, from developer tools enter the following line in the browsers console while the project is running locally:&lt;/small&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;setTimeout(() =&amp;gt; {debugger}, 5000);&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;small&gt;and within 5 seconds open the dropdown, afterwards the debugger will become active and the &lt;em&gt;Kendo Popup&lt;/em&gt; can be seen in the page source.&lt;/small&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What we can see is that the &lt;em&gt;Kendo Popup&lt;/em&gt; element is contained in the app-root element and it is at the same level as the newly created app-dropdown-list component:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SsTrU7un--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u6rdzmn1gaza3et7mpnw.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SsTrU7un--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u6rdzmn1gaza3et7mpnw.PNG" alt="Source view with kendo-popup within app-root" width="754" height="144"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In order to attach the Kendo Popup to the Kendo Dropdown, add the following line into the &lt;u&gt;kendo-dropdownlist&lt;/u&gt; element from the dropdown-list.component.html file:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;kendo-dropdownlist&lt;/span&gt;
    &lt;span class="na"&gt;[data]=&lt;/span&gt;&lt;span class="s"&gt;"listOptions"&lt;/span&gt;
&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="na"&gt;-------------------------------------------------------&lt;/span&gt;
    &lt;span class="na"&gt;[popupSettings]=&lt;/span&gt;&lt;span class="s"&gt;"{appendTo: 'component'}"&lt;/span&gt; &lt;span class="err"&gt;//&lt;/span&gt; &lt;span class="na"&gt;this&lt;/span&gt; &lt;span class="na"&gt;line&lt;/span&gt;
&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="na"&gt;-------------------------------------------------------&lt;/span&gt;
    &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;"width: 200px; margin: 16px;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/kendo-dropdownlist&amp;gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now save the changes and enter the following line in the browsers console:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;setTimeout(() =&amp;gt; {debugger}, 5000);&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;and just as before open the dropdown and wait 5 seconds for the debugger to become active, afterwards we can see that the &lt;em&gt;Kendo Popup&lt;/em&gt; is inside the Kendo Dropdown:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JSMizlIn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4bu89zbvc6kv9z43jnby.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JSMizlIn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4bu89zbvc6kv9z43jnby.PNG" alt="Source view with kendo-popup within kendo-dropdownlist" width="697" height="386"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  As a side note
&lt;/h2&gt;

&lt;p&gt;We can apply a custom css class to the &lt;em&gt;Kendo Popup&lt;/em&gt; by adding the &lt;strong&gt;popupClass&lt;/strong&gt; property to the &lt;strong&gt;popupSettings&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;kendo-dropdownlist&lt;/span&gt;
    &lt;span class="na"&gt;[data]=&lt;/span&gt;&lt;span class="s"&gt;"listOptions"&lt;/span&gt;
    &lt;span class="na"&gt;[popupSettings]=&lt;/span&gt;&lt;span class="s"&gt;"
    {
       appendTo: 'component',
//-------------------------------------------------------
       popupClass: 'our-style' // this line
//-------------------------------------------------------
    }"&lt;/span&gt;
    &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;"width: 200px; margin: 16px;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/kendo-dropdownlist&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However ng-deep or ViewEncapsulation.None are still needed in order to have the css properties actually work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nx"&gt;ng&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;deep&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;our&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;font&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;900&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The final project
&lt;/h2&gt;

&lt;p&gt;A working example can be seen on &lt;a href="https://stackblitz.com/edit/github-afcxpp?file=src%2Fapp%2Fdropdown-list%2Fdropdown-list.component.html"&gt;stackblitz&lt;/a&gt;:&lt;br&gt;
&lt;iframe src="https://stackblitz.com/edit/github-afcxpp?file=src%2Fapp%2Fdropdown-list%2Fdropdown-list.component.html" width="100%" height="500"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>kendoui</category>
      <category>typescript</category>
      <category>angular</category>
      <category>kendopopup</category>
    </item>
  </channel>
</rss>
