Angular PrimeNG Focus Trap Properties
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. In this article, we will see how to use the Focus Trap Properties in Angular PrimeNG. We will also learn about the various properties and their syntaxes used in the code example.
The Angular PrimeNG Focus Trap is used to maintain focus on certain DOM elements while we tab with the tab key.
Angular PrimeNG Focus Trap Properties:
- pFocusTrapDisabled: It specifies that the component should be disabled. It is of the boolean data type, the default value is false.
Syntax:
<div pFocusTrap class="card"> ... </div>
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:
- Steps to run the application: Run the below command to see the output:
ng serve --open
Example 1: This is the basic example that shows how to use the Angular PrimeNG Focus Trap Properties.
- app.component.html:
HTML
< div pFocusTrap class = "card" > < h2 style = "color: green" >w3wiki</ h2 > < h5 >Angular PrimeNG Focus Trap Properties</ h5 > < input id = "gfg" type = "text" size = "25" pInputText placeholder = "This is basic input field" /> </ div > |
- app.component.ts:
Javascript
import { Component } from '@angular/core' ; @Component({ selector: 'app-root' , templateUrl: './app.component.html' , }) export class AppComponent {} |
- app.module.ts:
Javascript
import { NgModule } from '@angular/core' ; import { BrowserModule } from '@angular/platform-browser' ; import { AppComponent } from './app.component' ; import { InputTextModule } from 'primeng/inputtext' ; import { EditorModule } from 'primeng/editor' ; @NgModule({ imports: [ BrowserModule, InputTextModule, EditorModule, ], declarations: [AppComponent], bootstrap: [AppComponent], }) export class AppModule {} |
Output:
Example 2: This is another basic example that shows how to use the Angular PrimeNG Focus Trap Properties.
- app.component.html:
HTML
< div pFocusTrap class = "card" > < h2 style = "color: green" >w3wiki</ h2 > < h5 >Angular PrimeNG Focus Trap Properties</ h5 > < span class = "p-float-label" > < input id = "float-input" type = "text" size = "30" pInputText /> < label for = "float-input" > This is floating input field </ label > </ span > </ div > |
- app.component.ts:
Javascript
import { Component } from '@angular/core' ; @Component({ selector: 'app-root' , templateUrl: './app.component.html' , }) export class AppComponent {} |
- app.module.ts:
Javascript
import { NgModule } from '@angular/core' ; import { BrowserModule } from '@angular/platform-browser' ; import { AppComponent } from './app.component' ; import { InputTextModule } from 'primeng/inputtext' ; import { EditorModule } from 'primeng/editor' ; @NgModule({ imports: [ BrowserModule, InputTextModule, EditorModule, ], declarations: [AppComponent], bootstrap: [AppComponent], }) export class AppModule {} |
Output:
Reference: https://primefaces.org/primeng/focustrap