Angular PrimeNG 带有tabindex-1的Focus Trap按钮

Angular PrimeNG 带有tabindex-1的Focus Trap按钮

Angular PrimeNG是一个开源框架,拥有丰富的原生Angular UI组件,可用于出色的造型,该框架可用于制作响应式网站,非常方便。本文将向我们展示如何在Angular PrimeNG中使用Focus Trap Button,并使用tabindex -1。我们还将学习各种属性及其在代码示例中的语法。

Angular PrimeNG Focus Trap用于指定元素是否只能聚焦于对话框内的元素。它是boolean数据类型,默认值是true。

Angular PrimeNG Focus Trap Button with tabindex -1 属性:

  • tabindex。它描述了一个元素在使用 “标签 “按钮导航时的标签顺序。

语法:

<button pButton 
  type="button" 
  icon="..." 
  label="..."
  tabindex ="-1"
</button>

创建Angular应用程序和模块安装。

第1步:使用以下命令创建一个Angular应用程序。

ng new appname

第2步:创建你的项目文件夹即appname后,使用以下命令移动到它。

cd appname

第3步:在你给定的目录中安装PrimeNG。

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

项目结构:它将看起来像如下。

带有tabindex-1的Angular PrimeNG Focus Trap按钮

要运行上述文件,请运行以下命令:

ng serve --save

例子1:下面的例子说明了Angular PrimeNG Focus Trap Button的使用,tabindex -1.

<div pFocusTrap class="card">
  <h2 style="color: green">GeeksforGeeks</h2>
  <h5>Angular PrimeNG Button with tabindex -1</h5>
  
  <button
    pButton
    type="button"
    icon="pi pi-check"
    tabindex="1"
    label="tabindex 1"
    class="p-button-success p-button-outlined">
  </button>
  
  <button
    pButton
    type="button"
    icon="pi pi-check"
    tabindex="2"
    label="tabindex 2"
    class="p-button-info p-button-outlined">
  </button>
  
  <button
    pButton
    type="button"
    icon="pi pi-check"
    tabindex="-1"
    class="p-button-danger p-button-outlined"
    label="tabindex -1 (skipped)">
  </button>
  
  <button
    pButton
    type="button"
    icon="pi pi-check"
    tabindex="3"
    class="p-button-warning p-button-outlined"
    label="tabindex 3">
  </button>
</div>
import { Component } from '@angular/core';
  
@Component({
   selector: 'app-root',
   templateUrl: './app.component.html',
})
  
export class AppComponent {}
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from
    '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { CalendarModule } from 'primeng/calendar';
  
@NgModule({
   imports: [
     BrowserAnimationsModule,
     CalendarModule
   ],
   declarations: [AppComponent],
   bootstrap: [AppComponent],
})
  
export class AppModule {}

输出:

带有tabindex-1的Angular PrimeNG Focus Trap按钮

例子2:下面是另一个例子,说明了Angular PrimeNG Focus Trap Button与tabindex -1.的使用。

<div pFocusTrap class="card">
  <h2 style="color: green">GeeksforGeeks</h2>
  <h5>Angular PrimeNG Button with tabindex -1</h5>
  
  <div class="row">
    <div class="col">
      <button
        pButton
        type="button"
        icon="pi pi-check"
        tabindex="1"
        label="tabindex 1"
        class="p-button-success">
      </button>
    </div>
  </div>
  
  <div class="row">
    <div class="col">
      <button
        pButton
        type="button"
        icon="pi pi-times"
        tabindex="2"
        label="tabindex 2"
        class="p-button-info">
      </button>
    </div>
  </div>
  
  <div class="row">
    <div class="col">
      <button
        pButton
        type="button"
        icon="pi pi-code"
        tabindex="-1"
        class="p-button-danger"
        label="tabindex -1 (skipped)">
      </button>
    </div>
  </div>
  
  <div class="row">
    <div class="col">
      <button
        pButton
        type="button"
        icon="pi pi-hashtag"
        tabindex="3"
        class="p-button-warning"
        label="tabindex 3">
      </button>
    </div>
  </div>
</div>
import { Component } from '@angular/core';
  
@Component({
   selector: 'app-root',
   templateUrl: './app.component.html',
})
  
export class AppComponent {}
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from
    '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { CalendarModule } from 'primeng/calendar';
  
@NgModule({
   imports: [
     BrowserAnimationsModule,
     CalendarModule
   ],
   declarations: [AppComponent],
   bootstrap: [AppComponent],
})
  
export class AppModule {}

输出:

带有tabindex-1的Angular PrimeNG Focus Trap按钮

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程