Primitives
Display a series of panels that can be expanded or collapsed.
Import the Accordion primitives from ng-primitives/accordion
.
import {
NgpAccordion,
NgpAccordionItem,
NgpAccordionTrigger,
NgpAccordionContent,
} from 'ng-primitives/accordion';
Assemble the accordion directives in your template.
<div ngpAccordion ngpAccordionType="single" ngpAccordionCollapsible>
<div ngpAccordionItem ngpAccordionItemValue="item-1">
<button ngpAccordionTrigger ngpButton>Would you like to learn more?</button>
<div ngpAccordionContent>If you would like to learn more please reach out to us on GitHub.</div>
</div>
<div ngpAccordionItem ngpAccordionItemValue="item-2">
<button ngpAccordionTrigger ngpButton>Can I use this in my project?</button>
<div ngpAccordionContent>Yes, this is open source and you can use it in your project.</div>
</div>
</div>
Generate an accordion component with the NgpAccordion
and NgpAccordionItem
primitives preconfigured.
ng g ng-primitives:accordion
name
: The name of the component.prefix
: The prefix to apply to the generated component selector.directory
: The directory at which to create the component file.style
: The file extension or preprocessor to use for style files.inlineStyle
: Include styles inline in the component.ts file. Only CSS styles can be included inline.inlineTemplate
: Include template inline in the component.ts fileThe following directives are available to import from the ng-primitives/accordion
package:
Apply the ngpAccordion
directive to an element that represents the group of accordion items.
[ngpAccordion]
ngpAccordion
The following data attributes are applied to the ngpAccordion
directive:
Attribute | Description | Value |
---|---|---|
data-orientation |
The orientation of the accordion. | horizontal | vertical |
data-disabled |
Applied when the element is disabled. | - |
Apply the ngpAccordionItem
directive to an element that represents an accordion item.
[ngpAccordionItem]
ngpAccordionItem
The following data attributes are applied to the ngpAccordionItem
directive:
Attribute | Description | Value |
---|---|---|
data-orientation |
The orientation of the accordion. | horizontal | vertical |
data-open |
Applied when the accordion item is open. | - |
data-disabled |
Applied when the accordion item is disabled. | - |
Apply the ngpAccordionTrigger
directive to an element that represents the trigger for an accordion item, such as a button.
[ngpAccordionTrigger]
ngpAccordionTrigger
The following data attributes are applied to the ngpAccordionTrigger
directive:
Attribute | Description | Value |
---|---|---|
data-orientation |
The orientation of the accordion. | horizontal | vertical |
data-open |
Applied when the accordion item is open. | - |
data-disabled |
Applied when the accordion item is disabled. | - |
Apply the ngpAccordionContent
directive to an element that represents the content of an accordion item.
[ngpAccordionContent]
ngpAccordionContent
The following data attributes are applied to the ngpAccordionContent
directive:
Attribute | Description | Value |
---|---|---|
data-orientation |
The orientation of the accordion. | horizontal | vertical |
data-open |
Applied when the accordion item is open. | - |
You can configure the default options for all accordions in your application by using the provideNgpAccordionConfig
function in a providers array.
import { provideNgpAccordionConfig } from 'ng-primitives/accordion';
bootstrapApplication(AppComponent, {
providers: [
provideNgpAccordionConfig({
type: 'multiple',
collapsible: true,
orientation: 'horizontal',
}),
],
});
Adheres to the Accordion WAI-ARIA design pattern.
Copyright © 2024 Angular Primitives