Inplace provides an easy to do editing and display at the same time where clicking the output displays the actual content.
import { InplaceModule } from 'primeng/inplace';
Inplace component requires display and content templates to define the content of each state.
<p-inplace>
<ng-template pTemplate="display">
<span>View Content</span>
</ng-template>
<ng-template pTemplate="content">
<p class="m-0">
Lorem ipsum dolor sit amet, consectetur adipiscing elit...
</p>
</ng-template>
</p-inplace>
Inplace can be used within a form to display a value as read only before making it editable. The closable property adds a close button next to the content to switch back to read only mode.
<p-inplace>
<ng-template pTemplate="display">
<span>Click to Edit</span>
</ng-template>
<ng-template pTemplate="content" let-closeCallback="closeCallback">
<span class="inline-flex items-center gap-2">
<input type="text" pInputText autofocus />
<button (click)="closeCallback($event)" pButton icon="pi pi-times" text severity="danger"></button>
</span>
</ng-template>
</p-inplace>
Any content such as an image can be placed inside an Inplace.
<p-inplace>
<ng-template pTemplate="display">
<span class="inline-flex items-center gap-2">
<span class="pi pi-image" style="vertical-align: middle"></span>
<span class="ml-2">View Photo</span>
</span>
</ng-template>
<ng-template pTemplate="content">
<img
class="w-full sm:w-80 shadow-md"
src="https://primefaces.org/cdn/primeng/images/demo/galleria/galleria5.jpg"
alt="Nature"
/>
</ng-template>
</p-inplace>
Using the onActivate event, data can be loaded in a lazy manner before displaying it in a table.
<p-inplace (onActivate)="loadData()">
<ng-template #display>
<span>View Data</span>
</ng-template>
<ng-template #content>
<p-table [value]="products" responsiveLayout="scroll">
<ng-template pTemplate="header">
<tr>
<th>Code</th>
<th>Name</th>
<th>Category</th>
<th>Quantity</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-product>
<tr>
<td>{{ product.code }}</td>
<td>{{ product.name }}</td>
<td>{{ product.category }}</td>
<td>{{ product.quantity }}</td>
</tr>
</ng-template>
</p-table>
</ng-template>
</p-inplace>
Inplace component defines aria-live as "polite" by default, since any valid attribute is passed to the main container aria roles and attributes of the root element can be customized easily.
Display element uses button role in view mode by default, displayProps can be used for customizations like adding aria-label or aria-labelledby attributes to describe the content of the view mode or even overriding the default role.
Closable inplace components displays a button with an aria-label that refers to the aria.close property of the locale API by default, you may usecloseButtonProps to customize the element and override the default aria-label.
Key | Function |
---|---|
enter | Switches to content. |
Key | Function |
---|---|
enter | Switches to display. |
space | Switches to display. |