<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Igli Kapri on Medium]]></title>
        <description><![CDATA[Stories by Igli Kapri on Medium]]></description>
        <link>https://medium.com/@ika.vcc?source=rss-8633e84828d9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2-WkD0ACJY1wY2WPYd9W0Q.jpeg</url>
            <title>Stories by Igli Kapri on Medium</title>
            <link>https://medium.com/@ika.vcc?source=rss-8633e84828d9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 02:06:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ika.vcc/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building a TypeScript JsonSerializer from scratch]]></title>
            <link>https://medium.com/@ika.vcc/building-a-typescript-jsonserializer-from-scratch-68502f55cb9c?source=rss-8633e84828d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/68502f55cb9c</guid>
            <category><![CDATA[serialization]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Igli Kapri]]></dc:creator>
            <pubDate>Sun, 21 May 2023 20:02:41 GMT</pubDate>
            <atom:updated>2023-05-22T01:02:53.418Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a TypeScript JSON serializer (stringify) from scratch</h3><figure><img alt="Json Serialization" src="https://cdn-images-1.medium.com/max/512/1*jF3mgC4yMgQuxiL5Pl_TRw.jpeg" /><figcaption>JsonSerializer</figcaption></figure><p>Basically for serializing values of different types in JavaScript/TypeScript we use <strong>JSON.stringify()</strong>. But what if JSON is not natively supported?</p><p>In case backwards compatibility is an important topic in your project, you can build a JSON serializer as follows:</p><pre>import {Arrays, Dates, Objects, Strings, Utils} from &#39;utilitates&#39;;<br><br>export abstract class JsonSerializer {<br>  public static deserialize&lt;T&gt;(json: string): T {<br>    // I am a lil bit more complicated..<br>    return someValue;<br>  }<br><br>  public static serialize&lt;T&gt;(value: T): string {<br>    const isJsonSupported = Objects.hasProperty(window, &#39;JSON&#39;) &amp;&amp;<br>      Utils.isFunction(JSON.stringify);<br>    if (isJsonSupported) {<br>      return JSON.stringify(value);<br>    }<br><br>    let s = Strings.EMPTY;<br>    if (Arrays.isArray(value)) {<br>      s += &#39;[&#39;.concat(<br>          value<br>              .map((v) =&gt; `${JsonSerializer.serialize(v)}`)<br>              .join(&#39;,&#39;).concat(&#39;]&#39;));<br>    } else if (Dates.isDate(value)) {<br>      s += Dates.isValid(value) ? `&quot;${value.toISOString()}&quot;` : &#39;null&#39;;<br>    } else if (Utils.isRegExp(value)) {<br>      s += &#39;{}&#39;;<br>    } else if (Objects.isObject(value)) {<br>      s += &#39;{&#39;.concat(Object<br>          .entries(value)<br>          .filter(([_, v]) =&gt; Utils.isDefined(v))<br>          .map(([k, v]) =&gt; `&quot;${k}&quot;:${JsonSerializer.serialize(v)}`)<br>          .join(&#39;,&#39;)).concat(&#39;}&#39;);<br>      return s;<br>    } else if (Strings.isString(value)) {<br>      s += `&quot;${value}&quot;`;<br>    } else {<br>      s += `${value}`;<br>    }<br><br>    return s;<br>  }<br>}</pre><p>For implementing the serialize() method, I have used a modern TS/JS utility framework called “<a href="https://www.npmjs.com/package/utilitates">utilitates</a>”. You can also use your own utility functions, it’s a free choice.</p><p>Note that the serialize() method above is simply a “minified” version of the JSON.stringify() method. In order to make this method equivalent to JSON.stringify(), there is some homework to do:</p><ol><li>First there is an issue regarding circular object references.</li></ol><pre>const obj = {...};<br>obj.self = obj;<br><br>JsonSerializer.serialize(obj);// RangeError: Maximum call stack size exceeded<br><br>// Note: This seems to be an issue even if using JSON.stringify()<br>// For that a replacer function can be used as a second parameter of<br>// the aforementioned method so that circular references are handled.</pre><p>2. You can see in the code snippet above that JavaScript Date Objects are not serialized as objects but instead as strings (ISO 8601 Date Strings). There are also other objects which have the same behavior during serialization. That’s why the method above has to be extended and tested so that it becomes fully functional just like JSON.stringify().</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68502f55cb9c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CRUD with Jakarta Persistence API in Java]]></title>
            <link>https://medium.com/@ika.vcc/crud-with-jakarta-persistence-api-in-java-589fd146f00a?source=rss-8633e84828d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/589fd146f00a</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[jakarta]]></category>
            <category><![CDATA[api-development]]></category>
            <category><![CDATA[spring]]></category>
            <dc:creator><![CDATA[Igli Kapri]]></dc:creator>
            <pubDate>Sun, 16 Apr 2023 20:25:59 GMT</pubDate>
            <atom:updated>2023-04-16T21:43:23.263Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>Step 1: </em>Installation of Jakarta</strong></p><p>To install the Jakarta Persistence API add the following dependency to your project (in my case I have created a Maven Project but the procedure for installing it in a Gradle Project is more or less the same):</p><pre>&lt;!-- pom.xml --&gt;<br>&lt;dependencies&gt;<br>  &lt;!-- Other dependencies... --&gt;<br>  &lt;dependency&gt;<br>    &lt;groupId&gt;jakarta.platform&lt;/groupId&gt;<br>    &lt;artifactId&gt;jakarta.jakartaee-api&lt;/artifactId&gt;<br>    &lt;version&gt;8.0.0&lt;/version&gt; &lt;!-- This is the version I am installing--&gt;<br>    &lt;scope&gt;provided&lt;/scope&gt;<br>  &lt;/dependency&gt;<br>&lt;/dependencies&gt;</pre><p><strong><em>Step 2:</em></strong> <strong>Create an EntityManager based on your persistence unit</strong></p><p>From your persistence.xml file which looks more or less like this:</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;persistence<br>  ...<br>  ...<br>&gt;<br>  &lt;persistence-unit name=&quot;yourpuname&quot;&gt;<br>    &lt;jta-data-source&gt;your-db&lt;/jta-data-source&gt;<br>    &lt;class&gt;com.path.to.your.entities.Entity1&lt;/class&gt;<br>    &lt;class&gt;com.path.to.your.entities.Entity2&lt;/class&gt;<br>    &lt;class&gt;com.path.to.your.entities.Entity3&lt;/class&gt;<br>    ...<br>    ...<br>    ...<br>  &lt;/persistence-unit&gt;<br>&lt;/persistence&gt;<br></pre><p>note the value of the attribute “name” which in the code block above is “yourpuname” as you will need it in order to create your EntityManager. The EntityManager is created as follows:</p><pre>import javax.persistence.EntityManager;<br>import javax.persistence.EntityManagerFactory;<br><br>...<br>...<br><br>private static EntityManager getEntityManager()<br>  throws<br>    IllegalStateException,<br>    NullPointerException {<br>  EntityManagerFactory entityManagerFactory = Persistence<br>    .createEntityManagerFactory(&quot;yourpuname&quot;); // note this!<br>  return entityManagerFactory.createEntityManager();<br>}</pre><p>Another way of creating the EntityManager for your persistence unit is by using an annotation called “PersistenceContext” from “javax.persistence.PersistenceContext” but the way above is the one I prefer although it might involve a couple of lines of code more for you need to destroy the EntityManager after each usage by calling its “close()” method and if you use the PersistenceContext annotation you don’t need to worry about its internal implementation, about how it is injected and about how its instances are destroyed. The way above is also thread-safe which might be very important for your project. Another big win by using the approach above is that you can better manage the life-cycle of the EntityManager.</p><p><strong><em>Step 3:</em></strong> <strong>Build a generic service for CRUD operations. (optional)</strong></p><p>I have created a small Maven Project for illustration of how EntityManager can be used in combination with transactions in order to perform CRUD operations.</p><p><a href="https://github.com/icapri/entity-service/blob/main/src/main/java/com/capri/EntityService.java">entity-service/EntityService.java at main · icapri/entity-service</a></p><p><strong><em>Step 4:</em></strong> <strong>Have fun programming in Java! :)</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=589fd146f00a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use Google Map in Angular Project]]></title>
            <link>https://medium.com/@ika.vcc/use-google-map-in-angular-project-4a6fd1a5efab?source=rss-8633e84828d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a6fd1a5efab</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[google-maps]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular-google-map]]></category>
            <dc:creator><![CDATA[Igli Kapri]]></dc:creator>
            <pubDate>Sun, 04 Dec 2022 14:40:19 GMT</pubDate>
            <atom:updated>2022-12-04T14:40:19.335Z</atom:updated>
            <content:encoded><![CDATA[<p>The Angular Team has built among the other libraries, a library for using the Google Maps API called “@angular/google-maps”. To install this library just execute from your project root dir this command:</p><pre>npm install @angular/google-maps</pre><p>This Angular Library does not work in case you haven’t provided the javascript file of Google Maps API. To provide this script, it is a good practice to build your own wrapper for the map e. g. a MapComponent declared in a MapModule (your wrapper module, part of your dummy-components).</p><p>Create a map-provider.ts file inside the module and add this content:</p><pre>import {APP_INITIALIZER, InjectionToken, Provider} from &#39;@angular/core&#39;;<br><br>const googleMapUri = &#39;https://maps.googleapis.com/maps/api/js?key=&#39; as const;<br><br>export interface MapConfig {<br>  apiKey: string;<br>}<br><br>export const MAP_CONFIG_PROVIDER = new InjectionToken&lt;MapConfig&gt;(<br>    &#39;map-config&#39;, { factory: () =&gt; ({apiKey: &#39;&#39;}) }<br>);<br><br>export function googleMapInitializer(mapConfig: MapConfig): VoidFunction {<br>  return () =&gt; {<br>    const apiKey = mapConfig.apiKey;<br>    if (!apiKey || typeof apiKey == &#39;string&#39; &amp;&amp; apiKey.trim().length === 0) {<br>      throw new Error(`The Google Maps API Key &quot;${apiKey}&quot; is invalid.`);<br>    }<br><br>    const script = document.createElement(&#39;script&#39;);<br>    script.src = googleMapUri.concat(apiKey);<br>    document.head.appendChild(script);<br>    script.onerror = () =&gt; {<br>      throw new Error(&#39;Could not load the Google Maps API.&#39;);<br>    };<br>  };<br>}<br><br>export const MAP_SCRIPT_INITIALIZER: Provider = {<br>  provide: APP_INITIALIZER,<br>  multi: true,<br>  useFactory: googleMapInitializer,<br>  deps: [<br>    MAP_CONFIG_PROVIDER,<br>  ],<br>};</pre><p>In your MapModule make sure you also have the code below:</p><pre>@NgModule({<br>  declarations: [YourMapWrapperComponent, ...],<br>  exports: [YourMapWrapperComponent, ...],<br>  imports: [CommonModule, GoogleMapsModule, ...],<br>})<br>export class YourMapModule {<br>  static forRoot(mapConfig?: MapConfig): ModuleWithProviders&lt;YourMapModule&gt; {<br>    return {<br>      ngModule: YourMapModule,<br>      providers: [<br>        {provide: MAP_CONFIG_PROVIDER, useValue: mapConfig},<br>        MAP_SCRIPT_INITIALIZER,<br>      ],<br>    };<br>  }<br>}</pre><p>In case you have implemented the Module Lazy Loading Pattern in your Angular Project, the providers below should be added to the AppModule (Root Module) of your project so that the Google Maps Script is loaded together with the application in the browser.</p><p>For learning about how to use Google Maps <a href="https://github.com/angular/components/tree/main/src/google-maps">read the documentation</a>. You can also read the Google Documentation of Google Maps API.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a6fd1a5efab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Add Swagger OpenAPI Specification to JAVA RESTful API]]></title>
            <link>https://medium.com/@ika.vcc/add-swagger-openapi-specification-to-java-restful-api-ff75cc39f553?source=rss-8633e84828d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff75cc39f553</guid>
            <category><![CDATA[open-api]]></category>
            <category><![CDATA[openapi-generator]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[swagger]]></category>
            <category><![CDATA[openapi-specification]]></category>
            <dc:creator><![CDATA[Igli Kapri]]></dc:creator>
            <pubDate>Fri, 18 Nov 2022 20:56:49 GMT</pubDate>
            <atom:updated>2022-11-18T20:56:49.159Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*TzLUj6_Kb4PzdKig7x9bPA.jpeg" /><figcaption>Swagger UI</figcaption></figure><p>You are building a Java RESTful API and you need help for configuring Swagger in your project for generating the API Specification? After having read carefully this article I assure you that you will be able to create the API Documentation with Swagger as well as to automatically generate the client DTOs by using the openapi-generator.</p><p>So now let’s stop philosophizing and let’s get down to business:</p><p><strong><em>Step 1: Install the Swagger Packages</em></strong></p><p>In the pom.xml file of your project, add the following dependencies: (in Gradle the procedure is similar)</p><pre>&lt;project ...&gt;<br>  ...<br>  ...<br>  &lt;dependencies&gt;<br>    ...<br>    ...<br>    &lt;dependency&gt;<br>      &lt;groupId&gt;io.swagger.core.v3&lt;/groupId&gt;<br>      &lt;artifactId&gt;swagger-jaxrs2&lt;/artifactId&gt;<br>      &lt;version&gt;2.2.4&lt;/version&gt;<br>    &lt;/dependency&gt;<br>    &lt;dependency&gt;<br>      &lt;groupId&gt;io.swagger.core.v3&lt;/groupId&gt;<br>      &lt;artifactId&gt;swagger-jaxrs2-servlet-initializer&lt;/artifactId&gt;<br>      &lt;version&gt;2.2.4&lt;/version&gt;<br>    &lt;/dependency&gt;<br>    &lt;dependency&gt;<br>      &lt;groupId&gt;io.swagger.core.v3&lt;/groupId&gt;<br>      &lt;artifactId&gt;swagger-annotations&lt;/artifactId&gt;<br>      &lt;version&gt;2.2.4&lt;/version&gt;<br>    &lt;/dependency&gt;<br>  &lt;/dependencies&gt;<br>  ...<br>  ...<br>&lt;/project&gt;</pre><p>After having added the dependencies above, install them. In Maven you could for example execute this command to install the dependencies above:</p><pre>mvn install -f &quot;/path/to/your/project/pom.xml&quot;</pre><p><strong><em>Step 2: Configure the OpenAPI Specification to your application class.</em></strong></p><p>Go to your Application class (the one that inherits from the <strong>javax.ws.rs.core.Application </strong>class) and add the following annotation:</p><pre>import javax.ws.rs.ApplicationPath;<br>import javax.ws.rs.core.Application;<br><br>import io.swagger.v3.oas.annotations.OpenAPIDefinition;<br>import io.swagger.v3.oas.annotations.info.Info;<br>import io.swagger.v3.oas.annotations.servers.Server;<br>import io.swagger.v3.oas.annotations.info.License;<br><br>@ApplicationPath(&quot;/path/to/your/api&quot;)<br>// ...<br>// ...<br>@OpenAPIDefinition(<br>  servers = {<br>    @Server(url = &quot;http://localhost:XXXX&quot;) // define the listening port<br>  },<br>  info = @Info(<br>    title = &quot;Title for your API&quot;,<br>    description = &quot;Some description for your API&quot;,<br>    version = &quot;X.X.X&quot;,<br>    license = @License(...) // optional<br>    // ... etc.<br>  )<br>)<br>public class YourApplication extends Application {<br>  // ...<br>  // ...<br><br>  public YourApplication(...) {<br>    // ...<br>  }<br>  <br>  // ...<br>  // ...<br>}</pre><p><strong><em>Step 3: Generate your API Specification file.</em></strong></p><p>Start your application server, open your browser and navigate to:</p><pre>localhost:XXXX/path/to/your/api/openapi.json</pre><p>I hope you can see a .json file with information about your API in your browser now. If so, right-click on it, then click on <strong>Save As </strong>and then in your file explorer search for your client application which will consume your API and store this JSON file somewhere (e. g. somewhere under the <strong>assets </strong>folder<strong> </strong>if your project has such one).</p><p><strong><em>Step 4: Generate the client DTOs</em></strong></p><p>Install this package <a href="https://www.npmjs.com/package/@openapitools/openapi-generator-cli"><strong>@openapitools/openapi-generator-cli</strong></a><strong> </strong>from npmjs.com. Only reading the documentation of this library is quite enough to generate the client DTOs (openapi-generator does even more than that). Because there are a couple of front-end framework I am picking one of them — Angular —for creating the client DTOs with openapi-generator. So, I have to execute this command:</p><p>openapi-generator-cli generate -i src/assets/openapi.json -g typescript-angular -o src/app/client</p><pre>openapi-generator-cli generate -i path/to/openapi.json -g typescript-angular -o path/to/model/folder</pre><p>I hope this article was worth reading for you!</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff75cc39f553" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular Trap Focus Directive]]></title>
            <link>https://medium.com/@ika.vcc/angular-trap-focus-directive-3e0cab9b7ad1?source=rss-8633e84828d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e0cab9b7ad1</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[directives]]></category>
            <category><![CDATA[focus]]></category>
            <dc:creator><![CDATA[Igli Kapri]]></dc:creator>
            <pubDate>Mon, 14 Nov 2022 22:36:21 GMT</pubDate>
            <atom:updated>2022-11-14T22:36:21.613Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/199/1*76_yubpGyEz90lV-xp9q4g.jpeg" /><figcaption>BirdComponent using TrapCatDirective</figcaption></figure><p>Below I am going to show you guys how I have built a directive for trapping focus inside a container element when navigating inside of it via Tab. A very suitable case would be for example an overlay (a dialog overlay) or maybe a sidebar. The containers of such components really need such a directive applied in order for the focus not to exit the component.</p><p><strong>Usage Steps:</strong></p><p><em>Step 1:</em> Copy the code of the TrapFocusDirective below.</p><p><em>Step 2:</em> Paste it inside your project and use it like &lt;your-container-element [mouTrapFocus]&gt;&lt;/your-container-element&gt;.</p><p><em>Step 3:</em> Test it (in case backwards compatibility is an important requirement for your project, test the directive in different browsers for different HTML elements to make sure that no errors are thrown).</p><p><em>Step 4:</em> Enjoy using it!</p><pre>import {<br>  Directive,<br>  ElementRef,<br>  AfterViewInit,<br>  HostListener,<br>} from &#39;@angular/core&#39;;<br><br>/**<br> * Represents the types of disableable HTML elements.<br> */<br>export type DisableableHTMLElement =<br>  | HTMLButtonElement<br>  | HTMLFieldSetElement<br>  | HTMLInputElement<br>  | HTMLOptGroupElement<br>  | HTMLOptionElement<br>  | HTMLSelectElement<br>  | HTMLTextAreaElement;<br><br>/**<br> * Represents the types of focusable HTML elements.<br> */<br>export type FocusableHTMLElement =<br>  | HTMLInputElement<br>  | HTMLSelectElement<br>  | HTMLTextAreaElement<br>  | HTMLAnchorElement<br>  | HTMLButtonElement<br>  | HTMLAreaElement;<br><br>/**<br> * Defines a directive for focus trapping.<br> */<br>@Directive({<br>  selector: &#39;[mouTrapFocus]&#39;,<br>})<br>export class TrapFocusDirective implements AfterViewInit {<br>  /**<br>   * Contains the list of disableable HTML elements.<br>   */<br>  private static _disableableElements: ReadonlyArray&lt;string&gt; = [<br>    &#39;BUTTON&#39;,<br>    &#39;FIELDSET&#39;,<br>    &#39;INPUT&#39;,<br>    &#39;KEYGEN&#39;,<br>    &#39;OPTGROUP&#39;,<br>    &#39;OPTION&#39;,<br>    &#39;SELECT&#39;,<br>    &#39;TEXTAREA&#39;,<br>  ] as const;<br><br>  /**<br>   * Contains the list of focusable HTML elements.<br>   */<br>  private static _focusableElements: ReadonlyArray&lt;string&gt; = [<br>    &#39;[tabindex]:not([tabindex=&quot;-1&quot;])&#39;,<br>    &#39;a[href]&#39;,<br>    &#39;button:not(:disabled)&#39;,<br>    &#39;fieldset:not(:disabled)&#39;,<br>    &#39;input:not(:disabled)&#39;,<br>    &#39;select:not(:disabled)&#39;,<br>    &#39;textarea:not(:disabled)&#39;,<br>  ];<br><br>  /**<br>   * Gets the native element to which this directive is applied.<br>   */<br>  private get element(): HTMLElement {<br>    return this.elementRef.nativeElement;<br>  }<br><br>  /** Contains the first focusable child element. */<br>  private _firstFocusableChild?: HTMLElement;<br><br>  /** Contains the last focusable child element. */<br>  private _lastFocusableChild?: HTMLElement;<br><br>  /**<br>   * Initializes a new instance of the directive.<br>   * @param elementRef Contains a reference to the element to which the directive is applied.<br>   */<br>  constructor(private readonly elementRef: ElementRef&lt;HTMLElement&gt;) {}<br><br>  /** @private */<br>  private static isDisableableElement(<br>    element: HTMLElement<br>  ): element is DisableableHTMLElement {<br>    return (<br>      TrapFocusDirective._disableableElements.indexOf(element.tagName) !== -1<br>    );<br>  }<br><br>  /** @private */<br>  private static isDisabledHTMLElement(element: HTMLElement): boolean {<br>    const isDisabledDisableable =<br>      TrapFocusDirective.isDisableableElement(element) &amp;&amp; element.disabled;<br>    const isDisabledUndisableable = element.style.pointerEvents === &#39;none&#39;;<br>    return isDisabledDisableable || isDisabledUndisableable;<br>  }<br><br>  /**<br>   * Initializes the focusable HTML elements.<br>   */<br>  ngAfterViewInit() {<br>    if (this.element) {<br>      this.initializeFocusableElements();<br>    }<br>  }<br><br>  /** @private */<br>  private initializeFocusableElements(): void {<br>    const focusableElements = this.getFocusableChildren();<br>    if (focusableElements.length &lt; 1) {<br>      return; // nothing to focus<br>    }<br>    // initialize the first and the last focusable HTML element<br>    this._firstFocusableChild = focusableElements[0];<br>    this._lastFocusableChild = focusableElements[focusableElements.length - 1];<br>  }<br><br>  /**<br>   * Traps the focus inside the HTML element to which this directive is applied once<br>   * the user navigates per tab inside it.<br>   *<br>   * @param event Contains the emitted keyboard event.<br>   */<br>  @HostListener(&#39;keydown&#39;, [&#39;$event&#39;])<br>  trapFocus(event: KeyboardEvent) {<br>    const firstFocusableChild = this._firstFocusableChild;<br>    const lastFocusableChild = this._lastFocusableChild;<br>    // there should be at least one focusable element, so stop listening for now<br>    if (!firstFocusableChild || !lastFocusableChild) {<br>      return;<br>    }<br><br>    // handle the case when Shift + Tab have been clicked same time<br>    if (event.shiftKey) {<br>      if (document.activeElement === firstFocusableChild) {<br>        lastFocusableChild.focus();<br>        event.preventDefault();<br>      }<br>    } else {<br>      // handle tab<br>      if (document.activeElement === lastFocusableChild) {<br>        firstFocusableChild.focus();<br>        event.preventDefault();<br>      }<br>    }<br>  }<br><br>  /** @private */<br>  private getFocusableChildren(): HTMLElement[] {<br>    const selector = TrapFocusDirective._focusableElements.join(&#39;, &#39;);<br>    const focusableElements =<br>      this.element.querySelectorAll&lt;HTMLElement&gt;(selector);<br>    // filter out the disabled elements and return the rest<br>    return Array.from(focusableElements).filter(<br>      (e) =&gt; !TrapFocusDirective.isDisabledHTMLElement(e)<br>    );<br>  }<br>}</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstackblitz.com%2Fedit%2Fangular-ivy-eg5rtm%3Fembed%3D1%26file%3Dsrc%252Fapp%252Ftrap-focus.directive.ts&amp;display_name=StackBlitz&amp;url=https%3A%2F%2Fstackblitz.com%2Fedit%2Fangular-ivy-eg5rtm%3Ffile%3Dsrc%252Fapp%252Ftrap-focus.directive.ts&amp;image=https%3A%2F%2Fsocial-img.staticblitz.com%2Fprojects%2Fangular-ivy-eg5rtm%2Fcf138621dbd6b9a8c6062520b2978e4f&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=stackblitz" width="745" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc5812630896a13e61003b5f92cc38b4/href">https://medium.com/media/dc5812630896a13e61003b5f92cc38b4/href</a></iframe><p>Kind regards,</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e0cab9b7ad1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>