Inplace

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.

View Content

<p-inplace>
    <ng-template pTemplate="display">
        <span>View Content</span>
    </ng-template>
    <ng-template pTemplate="content">
        <span>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit...
        </span>
    </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.

Click to Edit

<p-inplace closable="closable">
    <ng-template pTemplate="display">
        <span>Click to Edit</span>
    </ng-template>
    <ng-template pTemplate="content">
        <input type="text" value="PrimeNG" pInputText />
    </ng-template>
</p-inplace>

Any content such as an image can be placed inside an Inplace.

View Picture

<p-inplace>
    <ng-template pTemplate="display">
        <div class="inline-flex align-items-center">
            <span class="pi pi-image" style="vertical-align: middle"></span>
            <span class="ml-2">View Picture</span>
        </div>
    </ng-template>
    <ng-template pTemplate="content">
        <img 
            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.

View Data

<p-inplace (onActivate)="loadData()">
    <ng-template pTemplate="display">
        <span>View Data</span>
    </ng-template>
    <ng-template pTemplate="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>

View Data

<p-inplace>
    <ng-template pTemplate="display">
        <div class="inline-flex align-items-center">
            <span class="pi pi-table" style="vertical-align: middle"></span>
            <span class="ml-2">View Data</span>
        </div>
    </ng-template>
    <ng-template pTemplate="content">
        <p-table [value]="cars" responsiveLayout="scroll">
            <ng-template pTemplate="header">
                <tr>
                    <th>Vin</th>
                    <th>Year</th>
                    <th>Brand</th>
                    <th>Color</th>
                </tr>
            </ng-template>
            <ng-template pTemplate="body" let-car>
                <tr>
                    <td>{{ car.vin }}</td>
                    <td>{{ car.year }}</td>
                    <td>{{ car.brand }}</td>
                    <td>{{ car.color }}</td>
                </tr>
            </ng-template>
        </p-table>
    </ng-template>
</p-inplace>

Following is the list of structural style classes, for theming classes visit theming page.

NameElement
p-inplaceContainer element
p-inplace-displayDisplay container
p-inplace-contentContent container

Screen Reader

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.

View Mode Keyboard Support

KeyFunction
enterSwitches to content.

Close Button Keyboard Support

KeyFunction
enterSwitches to display.
spaceSwitches to display.