Fieldset is a grouping component with a content toggle feature.
import { FieldsetModule } from 'primeng/fieldset';
PrimeIcons is available at npm, run the following command to download it to your project.
<p-fieldset legend="Header">
<p class="m-0">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</p-fieldset>
Content of the fieldset can be expanded and collapsed using toggleable option, default state is defined with collapsed option.
<p-fieldset legend="Header" [toggleable]="true">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</p-fieldset>
Legend section can also be defined with custom content instead of primitive values.
<p-fieldset>
<ng-template pTemplate="header">
<div class="flex align-items-center text-primary">
<span class="pi pi-user mr-2"></span>
<span class="font-bold text-lg">User Details</span>
</div>
</ng-template>
Content
</p-fieldset>
Following is the list of structural style classes, for theming classes visit theming page.
Name | Element |
---|---|
p-fieldset | Fieldset element |
p-fieldset-toggleable | Toggleable fieldset element |
p-fieldset-legend | Legend element. |
p-fieldset-content | Content element. |
Fieldset component uses the semantic fieldset element. When toggleable option is enabled, a clickable element with button role is included inside the legend element, this button has aria-controls to define the id of the content section along with aria-expanded for the visibility state. The value to read the button defaults to the value of the legend property and can be customized by defining an aria-label or aria-labelledby via the toggleButtonProps property.
The content uses region, defines an id that matches the aria-controls of the content toggle button and aria-labelledby referring to the id of the header.
Key | Function |
---|---|
tab | Moves focus to the next the focusable element in the page tab sequence. |
shift + tab | Moves focus to the previous the focusable element in the page tab sequence. |
enter | Toggles the visibility of the content. |
space | Toggles the visibility of the content. |
API defines helper props, events and others for the PrimeNG Fieldset module.
Name | Type | Default | Description |
---|---|---|---|
legend | string | null | Header text of the fieldset. |
toggleable | boolean | false | When specified, content can toggled by clicking the legend. |
collapsed | boolean | false | Defines the default visibility state of the content. |
style | string | null | Inline style of the fieldset. |
styleClass | string | null | Style class of the fieldset. |
transitionOptions | string | 400ms cubic-bezier(0.86, 0, 0.07, 1) | Transition options of the animation. |
Name | Parameters | Description |
---|---|---|
onBeforeToggle | event.originalEvent: browser event event.collapsed: state as a boolean | Callback to invoke before content toggle. |
onAfterToggle | event.originalEvent: browser event event.collapsed: state as a boolean | Callback to invoke after content toggle. |
Name | Parameters |
---|---|
header | - |
content | - |
expandicon | - |
closeicon | - |