Skip to content

Import

import { Iterate } from '@dnb/eufemia/extensions/forms'
render(<Iterate.ViewContainer />)

Description

Iterate.ViewContainer enables users to toggle (with animation) the content of each item between this view and the Iterate.EditContainer container. It can be used instead of the Iterate.AnimatedContainer.

By default, it features the Iterate.Toolbar containing a "Edit" button and a Iterate.RemoveButton button. The "Remove" will delete the current item from the array.

import { Iterate, Field, Value } from '@dnb/eufemia/extensions/forms'
render(
<Iterate.Array>
<Iterate.EditContainer
title="Edit account holder"
titleWhenNew="New account holder"
>
<Field.Name.Last itemPath="/name" />
</Iterate.EditContainer>
<Iterate.ViewContainer title="Account holder">
<Value.Name.Last itemPath="/name" />
</Iterate.ViewContainer>
</Iterate.Array>,
)

The item number in the title

You can use the {itemNo} variable in the title property to display the current item number.

import { Iterate, Value } from '@dnb/eufemia/extensions/forms'
render(
<Iterate.Array>
<Iterate.ViewContainer title="Account holder {itemNo}">
<Value.Name.Last itemPath="/name" />
</Iterate.ViewContainer>
</Iterate.Array>,
)

Customize the Toolbar

import { Iterate, Value } from '@dnb/eufemia/extensions/forms'
render(
<Iterate.Array>
<Iterate.ViewContainer>
<Value.Name.Last itemPath="/name" />
<Iterate.Toolbar>
<Iterate.ViewContainer.EditButton />
<Iterate.ViewContainer.RemoveButton />
</Iterate.Toolbar>
</Iterate.ViewContainer>
</Iterate.Array>,
)

Variants

minimumOneItem

This variant has the following behavior:

  • When ViewContainer is visible, and the number of items in the array is one, the remove button will be hidden.
import { Iterate } from '@dnb/eufemia/extensions/forms'
render(
<Iterate.Array>
<Iterate.ViewContainer toolbarVariant="minimumOneItem">
Item Content
</Iterate.ViewContainer>
</Iterate.Array>,
)

Accessibility

The Iterate.ViewContainer component has an aria-label attribute, which is set to the title property value. It uses a section element to wrap the content, which helps users with screen readers to get the needed announcement.

When the item (view and edit) container gets removed, the active element focus will be set on the previous item.