PrimeNG v18 Documentation

website·Indexed 34 days ago

https://v18.primeng.org

Documentation for PrimeNG v18, a comprehensive UI component library for Angular. Includes guides on application-wide configuration, migration, and detailed API references for components such as Drawer, Paginator, Dialog, Menu, and Stepper, as well as theming and styling options.

Tokens
99.2K
Snippets
653
Records
794
Agent score
3%

What's inside PrimeNG

  1. PrimeNG Accessibility Compliance Overview

    PrimeNG components are designed with WCAG 2.1 AA level compliance. For detailed accessibility information regarding specific components, developers should refer to the accessibility documentation provided for each individual component.
  2. Restrict input keystrokes using KeyFilter

    KeyFilter is a directive used to restrict individual key strokes in an input field. For full input restriction (rather than just keystroke filtering), use InputNumber or InputMask instead.
    import { KeyFilterModule } from 'primeng/keyfilter';
  3. Use the PrimeNG Divider component

    The Divider component is used to separate content visually. It supports both horizontal and vertical orientations and can optionally contain content (such as text) centered within the divider.
  4. Understand PrimeNG Theming Architecture

    PrimeNG uses a design-agnostic architecture where styling is decoupled from components via a theme consisting of a base (CSS rules with variables) and a preset (design tokens). Design tokens are organized into three tiers:

    1. Primitive Tokens: Context-less values, such as a color palette (e.g., blue-50 to blue-900).
    2. Semantic Tokens: Tokens with defined purpose (e.g., primary.color), which map to primitive tokens. The colorScheme group allows defining different tokens for light and dark modes.
    3. Component Tokens: Isolated tokens for specific components (e.g., button.background) that map to semantic tokens.

    Best Practice: Use primitive tokens for core palettes, semantic tokens for common design elements (focus rings, surfaces), and component tokens only for specific component overrides. Avoid using CSS style classes for overrides; use design tokens instead.

  5. Migrate from SASS themes to v18 Styled Mode

    PrimeNG v18 introduces a new design token-based architecture using CSS variables, completely removing the dependency on SASS. The legacy theme.css and primeng/resources paths no longer exist. All imports of these assets must be removed. Custom themes created for v17 must be recreated using the new Styled Mode APIs.
  6. Install and import the Select component

    To use the Select component in a PrimeNG project, import the SelectModule from the primeng/select package.
    import { SelectModule } from 'primeng/select';
  7. Keyboard navigation for PrimeNG Select

    The Select component supports comprehensive keyboard navigation across three states:

    Closed State:

    • Tab: Focuses the select element.
    • Space / Down Arrow: Opens popup and focuses the selected option (or first option if none selected).
    • Up Arrow: Opens popup and focuses the selected option (or last option if none selected).

    Popup State:

    • Tab / Shift + Tab: Cycles focus through focusable elements in the popup.
    • Enter / Space: Selects the focused option and closes the popup.
    • Escape: Closes the popup and returns focus to the select element.
    • Down Arrow / Up Arrow: Navigates between options.
    • Home / End: Moves focus to the first or last option (unless editable, then moves input cursor).
    • Left Arrow / Right Arrow: (Editable mode only) Moves the input cursor.
    • Printable Characters: (Non-editable mode) Jumps to the option starting with the typed characters.

    Filter Input State:

    • Enter / Escape: Closes the popup and returns focus to the select element.
  8. Close a dynamic dialog and return data

    A dynamic dialog can be closed by calling the close method on the DynamicDialogRef. Any value passed to close() will be emitted via the onClose observable of the reference in the caller component.
    // In the caller component
    this.ref = this.dialogService.open(ProductListDemo, { header: 'Select a Product' });
    
    this.ref.onClose.subscribe((product: Product) => {
        if (product) {
            console.log('Product Selected:', product.name);
        }
    });
    
    // Inside the loaded component (ProductListDemo)
    // Inject DynamicDialogRef in constructor
    constructor(public ref: DynamicDialogRef) {}
    
    selectProduct(product: Product) {
        this.ref.close(product); // Pass data back to caller
    }
  9. Install and import the PrimeNG Terminal module

    To use the Terminal component in your Angular application, import the TerminalModule from the primeng/terminal package.
    import { TerminalModule } from 'primeng/terminal';
  10. Customize InputOtp using templates

    You can replace the default design of the OTP inputs by using an ng-template with pTemplate="input". The template provides access to the current token value, the index of the token, and a set of event handlers (input, keydown, focus, blur, paste) that must be bound to the custom input element to maintain component functionality.
    <p-inputotp [(ngModel)]="value">
        <ng-template pTemplate="input" let-token let-events="events" let-index="index">
            <input 
                class="custom-otp-input" 
                (input)="events.input($event)" 
                (keydown)="events.keydown($event)" 
                type="text" 
                [attr.value]="token" 
                [maxLength]="1" />
        </ng-template>
    </p-inputotp>
  11. Import the Galleria component

    To use the Galleria component in your Angular application, import the GalleriaModule from the primeng/galleria package.
    import { GalleriaModule } from 'primeng/galleria';
  12. Use custom icons in PrimeNG components via templating

    PrimeNG components support custom icon libraries through the use of ng-template. By targeting specific template identifiers (such as #dropdownicon for the Select component), developers can replace default icons with Material Icons, Font Awesome, inline SVGs, or image files.