Skip to content
Related Articles

Related Articles

Angular PrimeNG Focus Trap Editor

View Discussion
Improve Article
Save Article
  • Last Updated : 12 Aug, 2022
View Discussion
Improve Article
Save Article

Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use the Focus Trap Editor in Angular PrimeNG. We will also learn about the various properties and their syntaxes used in the code example.

Angular PrimeNG Focus Trap is used to maintain focus on certain DOM elements while we tab with the tab key.

Syntax:

<p-editor [style]="{....}">
   <ng-template pTemplate="header">
         <span class="ql-formats">
             <button type="button" 
                 class="..." 
                 aria-label="...">
             </button>
      </span>
   </ng-template>
</p-editor>

Angular PrimeNG Focus Trap Editor properties:

  • style: It is used to give custom styling to the editor.

Creating Angular application & module installation:

Step 1: Create an Angular application using the following command.

ng new appname

Step 2: After creating your project folder i.e. appname, move to it using the following command.

cd appname

Step 3: Install PrimeNG in your given directory.

npm install primeng --save
npm install primeicons --save

Project Structure: It will look like the following.

 

Example 1: Below is the example that illustrates the use of Angular PrimeNG Focus Trap Editor using the custom button options.

app.component.html




<div pFocusTrap class="card">
  <h2 style="color: green">GeeksforGeeks</h2>
  <h5>Angular PrimeNG Focus Trap Editor</h5>
    
  <p-editor [style]="{ height: '200px' }">
    <ng-template pTemplate="header">
      <span class="ql-formats">
        <button type="button" 
            class="ql-bold" 
            aria-label="Bold">
        </button>
  
        <button type="button" 
            class="ql-italic" 
            aria-label="Italic">
        </button>
  
        <button
          type="button"
          class="ql-underline"
          aria-label="Underline">
        </button>
          
        <button type="button" 
            class="ql-strike" 
            aria-label="strike">
        </button>
          
        <button
          type="button"
          class="ql-blockquote"
          aria-label="blockquote">
        </button>
      </span>
    </ng-template>
  </p-editor>
</div>

app.component.ts




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})
  
export class AppComponent {}

app.module.ts




import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from 
    '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { EditorModule } from 'primeng/editor';
  
@NgModule({
    imports: [BrowserAnimationsModule, EditorModule],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
  
export class AppModule {}

Output:

 

Example 2: Below is the example that illustrates the use of Angular PrimeNG Focus Trap Editor using the default editor options.

app.component.html




<div pFocusTrap class="card">
  <h2 style="color: green">GeeksforGeeks</h2>
  <h5>Angular PrimeNG Focus Trap Editor</h5>
  
  <p-editor [style]="{ height: '200px' }"></p-editor>
</div>

app.component.ts




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})
  
export class AppComponent {}

app.module.ts




import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from 
    '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { EditorModule } from 'primeng/editor';
  
@NgModule({
    imports: [BrowserAnimationsModule, EditorModule],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
  
export class AppModule {}

Output:

 

Reference: https://primefaces.org/primeng/focustrap


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!