PrimeNG v18 Documentation
website·Indexed 34 days ago
https://v18.primeng.orgDocumentation 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.
What's inside PrimeNG
- 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.
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';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.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:
- Primitive Tokens: Context-less values, such as a color palette (e.g.,
blue-50toblue-900). - Semantic Tokens: Tokens with defined purpose (e.g.,
primary.color), which map to primitive tokens. ThecolorSchemegroup allows defining different tokens for light and dark modes. - 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.
- Primitive Tokens: Context-less values, such as a color palette (e.g.,
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 legacytheme.cssandprimeng/resourcespaths 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.Install and import the Select component
To use the Select component in a PrimeNG project, import theSelectModulefrom theprimeng/selectpackage.import { SelectModule } from 'primeng/select';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.
Close a dynamic dialog and return data
A dynamic dialog can be closed by calling theclosemethod on theDynamicDialogRef. Any value passed toclose()will be emitted via theonCloseobservable 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 }Install and import the PrimeNG Terminal module
To use the Terminal component in your Angular application, import theTerminalModulefrom theprimeng/terminalpackage.import { TerminalModule } from 'primeng/terminal';Customize InputOtp using templates
You can replace the default design of the OTP inputs by using anng-templatewithpTemplate="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>Import the Galleria component
To use the Galleria component in your Angular application, import theGalleriaModulefrom theprimeng/galleriapackage.import { GalleriaModule } from 'primeng/galleria';Use custom icons in PrimeNG components via templating
PrimeNG components support custom icon libraries through the use ofng-template. By targeting specific template identifiers (such as#dropdowniconfor the Select component), developers can replace default icons with Material Icons, Font Awesome, inline SVGs, or image files.