Accordion

<smart-accordion> is a collapsible section: a header button that toggles a body. The header and body are projected through the [accordionHeader] / [accordionBody] slots, and the open state is the two-way show model. The accordion has no injection token: <smart-accordion> always renders <smart-accordion-default>; for the styled look use <smart-accordion-preset> directly, and for a look of your own extend AccordionBaseComponent.


Usage

<smart-accordion [(show)]="open">
  <span accordionHeader>What is your refund policy?</span>
  <p accordionBody>You can request a full refund within 30 days of purchase.</p>
</smart-accordion>

The preview renders the code above in an application that registers every preset (provideSmartPresets(), see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.

Wrapper: <smart-accordion>

Inputs and models

InputTypeDefaultDescription
showModelSignal<boolean>falseOpen state, two-way ([(show)]); showChange reports every change.
optionsIAccordionOptions | undefinedundefinedopen (initial state, applied once) and disabled.
classstring''Classes appended to the container (the cssClass input, alias class).

Content projection

SelectorDescription
[accordionHeader]Content of the header button.
[accordionBody]Content shown while the section is open.

The wrapper passes both slots to <smart-accordion-default> as the headerTpl / bodyTpl templates.

IAccordionOptions

FieldTypeDefaultDescription
openbooleanundefinedInitial open state. When it is true on the first render and show is not already true, AccordionBaseComponent.ngOnInit sets show to true once and emits showChange, in every variant. Later changes of options.open are ignored; toggles and [(show)] take over.
disabledbooleanfalsetoggle() does nothing and the header button is rendered disabled.
animatedbooleanundefinedDeprecated: not read by the built-in implementations (no variant animates); available to a custom implementation.

Bind [(show)] to a signal when you combine it with options.open: a plain class field updated during the first change detection raises NG0100 (ExpressionChangedAfterItHasBeenChecked) in dev mode.

Building blocks of the default rendering

<smart-accordion-default> (AccordionDefaultComponent) is a bordered card made of two exported components you can reuse:

ComponentSelectorInputs
AccordionHeaderComponentsmart-accordion-headeropen (boolean, chevron up while true), disabled (boolean), cssClass (string)
AccordionBodyComponentsmart-accordion-bodycssClass (string)

AccordionPresetComponent (<smart-accordion-preset>)

A fully styled accordion based on the Preline bordered accordion. It extends AccordionBaseComponent, so it takes the same contract as AccordionDefaultComponent: the required headerTpl / bodyTpl template inputs, the show model, options and cssClass (bound as [cssClass]; the base input has no class alias).

Because there is no token, the preset cannot restyle <smart-accordion>, and provideSmartPresets() does not change it: render <smart-accordion-preset> where you want the styled look and supply the templates yourself.

Expand/collapse is driven by the inherited show model and @if; no Preline JS runtime is needed. The toggle button carries aria-expanded / aria-controls, the open body is a region, the chevron points down while collapsed and up while expanded, and the container border is visible only while open.

AccordionBaseComponent

The abstract directive every variant extends (AccordionDefaultComponent, AccordionPresetComponent, and yours).

Inputs

InputTypeDefaultDescription
showModelSignal<boolean>falseTwo-way binding for open state
optionsInputSignal<IAccordionOptions | undefined>undefinedAccordion configuration
cssClassInputSignal<string>''External CSS classes
headerTplInputSignal<TemplateRef<unknown>>requiredHeader template
bodyTplInputSignal<TemplateRef<unknown>>requiredBody template

Computed properties

PropertyTypeDescription
sharedContainerClassesSignal<string[]>Divider, rounded, border classes with dark mode support

Methods

MethodDescription
toggle()Toggles the show model (no-op while options.disabled)
ngOnInit()Applies options.open as the initial state; a subclass with its own ngOnInit calls super.ngOnInit() to keep it

Extending the base class

import { NgTemplateOutlet } from '@angular/common';
import {
  ChangeDetectionStrategy,
  Component,
  computed,
  signal,
  ViewEncapsulation,
} from '@angular/core';

import {
  AccordionBaseComponent,
  IAccordionOptions,
} from '@smartsoft001/angular';

@Component({
  selector: 'docs-custom-accordion',
  imports: [NgTemplateOutlet],
  template: `
    <div [class]="containerClasses()">
      <button
        type="button"
        class="docs-accordion__header"
        [disabled]="options()?.disabled ?? false"
        [attr.aria-expanded]="show()"
        (click)="toggle()"
      >
        <ng-container [ngTemplateOutlet]="headerTpl()" />
        <span aria-hidden="true">{{ show() ? '-' : '+' }}</span>
      </button>

      @if (show()) {
        <div class="docs-accordion__body">
          <ng-container [ngTemplateOutlet]="bodyTpl()" />
        </div>
      }
    </div>
  `,
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomAccordionComponent extends AccordionBaseComponent {
  containerClasses = computed(() =>
    ['docs-accordion', ...this.sharedContainerClasses(), this.cssClass()]
      .filter(Boolean)
      .join(' '),
  );
}

// The accordion has no standard-component token, so a custom implementation is
// rendered directly by its own selector instead of being injected into
// <smart-accordion>. The required headerTpl / bodyTpl inputs are <ng-template>
// references supplied by the host.
@Component({
  selector: 'docs-accordion-custom-example',
  imports: [CustomAccordionComponent],
  template: `
    <ng-template #headerTpl
      >What is the best thing about Switzerland?</ng-template
    >
    <ng-template #bodyTpl
      >I don't know, but the flag is a big plus.</ng-template
    >

    <docs-custom-accordion
      [headerTpl]="headerTpl"
      [bodyTpl]="bodyTpl"
      [(show)]="open"
      [options]="options"
    />
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AccordionCustomExampleComponent {
  open = signal(false);

  options: IAccordionOptions = { disabled: false };
}

Source

The component lives in packages/shared/angular/src/lib/components/accordion and is documented for Claude Code by the angular-components-accordion skill.

SmartAccordion is a collapsible section: a header button that toggles a body. The header and body are ReactNode slots (accordionHeader, accordionBody). The open state is either controlled (show + onShowChange) or kept inside the component (defaultShow, or options.open applied once on the first render). The accordion has no registry key: SmartAccordion always renders SmartAccordionDefault; for the styled look render SmartAccordionPreset directly.


Usage

import { useState } from 'react';

import { SmartAccordion } from '@smartsoft001/react';

export function AccordionUsageExample() {
  const [open, setOpen] = useState(false);

  return (
    <SmartAccordion
      show={open}
      onShowChange={setOpen}
      accordionHeader={<span>What is your refund policy?</span>}
      accordionBody={
        <p>You can request a full refund within 30 days of purchase.</p>
      }
    />
  );
}

The preview renders the code above in an application that registers every preset (SMART_PRESET_COMPONENTS on SmartProvider, see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.

Exports

All from @smartsoft001/react.

ExportKindWhat it is
SmartAccordioncomponentSmartAccordionDefault fed with the accordionHeader / accordionBody slots.
SmartAccordionBodycomponentThe padded content of an open accordion.
SmartAccordionDefaultcomponentThe default accordion rendering: a bordered card whose header toggles the body.
SmartAccordionHeadercomponentThe header button of SmartAccordionDefault, with a chevron pointing up while open.
SmartAccordionPresetcomponentStyled accordion variation (preset), based on the Preline bordered accordion.
useAccordionhookThe behaviour every accordion variant shares: the open state, controlled through show + onShowChange or kept internally, and toggle(), which does nothing while options.disabled.

The preset's class helpers (getAccordionPresetContainerClasses, getAccordionPresetToggleClasses, getAccordionPresetContentClasses, getAccordionPresetIconClasses) are exported too, for a custom implementation that wants the preset look.

Props and Types

SmartAccordionProps

Props of SmartAccordion. Extends SmartAccordionStateProps.

PropTypeDefaultDescription
className?string—Classes appended to the container.
accordionHeader?ReactNode—Content of the header button.
accordionBody?ReactNode—Content shown while open.

SmartAccordionStateProps

The open state every accordion shares: show and options. Pass show + onShowChange to control it; leave show undefined to let the accordion keep its own state, starting from defaultShow (or options.open).

PropTypeDefaultDescription
show?boolean—Controlled open state; undefined keeps the state internal.
defaultShow?booleanfalseInitial open state when uncontrolled.
onShowChange?(show: boolean) => void—Every change of show: toggles and the initial options.open.
options?IAccordionOptions—open (initial state, applied once) and disabled (the header ignores clicks).

SmartAccordionBaseProps

Props of the accordion variations (SmartAccordionDefault, SmartAccordionPreset): the slots are headerTpl / bodyTpl instead of accordionHeader / accordionBody. Extends SmartAccordionStateProps.

PropTypeDefaultDescription
className?string—Classes appended to the container.
headerTplReactNoderequiredContent of the header button.
bodyTplReactNoderequiredContent shown while open.

SmartAccordionHeaderProps

Props of SmartAccordionHeader, the header button of the default variation.

PropTypeDefaultDescription
open?booleanfalseChevron up while true.
disabled?booleanfalseRenders the button disabled.
className?string—Classes appended to the button.
children?ReactNode—Content of the button.

SmartAccordionBodyProps

Props of SmartAccordionBody, the padded body of the default variation.

PropTypeDefaultDescription
className?string—Classes appended to the body.
children?ReactNode—Content of the body.

IAccordionOptions

FieldTypeDefaultDescription
open?boolean—Initial open state, applied once on the first render by every variant: an uncontrolled accordion starts open, and onShowChange(true) is reported unless show / defaultShow was already true. Later changes to this flag are ignored; toggles and the show prop take over. A controlled accordion stays as its show prop says until the parent applies the reported change.
disabled?booleanfalsePrevents toggle() from changing show (the header ignores clicks).
animated?boolean—@deprecated No accordion variant (default or preset) animates anything; this flag has no effect.

Controlled and uncontrolled

  • Uncontrolled: leave show undefined. The accordion keeps its own state, starting from defaultShow (default false) or options.open. onShowChange still reports every toggle.
  • Controlled: pass show and update it from onShowChange. A toggle only calls onShowChange(next); the accordion stays as show says until the parent changes it.
  • options.open is read once, on the first render. When it is true and the initial state is closed, the accordion reports onShowChange(true) once. Later changes of options.open are ignored.
  • options.disabled makes the header ignore clicks (the header is rendered disabled).

Replacing the Implementation

The accordion has no SmartProvider registry key, so it cannot be swapped application-wide. Pick the variation where you render it:

  • SmartAccordion (slots accordionHeader / accordionBody) renders SmartAccordionDefault, a bordered card with SmartAccordionHeader and SmartAccordionBody.
  • SmartAccordionPreset (slots headerTpl / bodyTpl) is the styled variation, based on the Preline bordered accordion: the toggle button carries aria-expanded / aria-controls and the open body is a region.
  • For a look of your own, write a component on useAccordion and render it in place of SmartAccordion.

The useAccordion hook

The behaviour every accordion variant shares: the open state, controlled through show + onShowChange or kept internally, and toggle(), which does nothing while options.disabled. options.open is applied once, on the first render: an uncontrolled accordion starts open, and onShowChange(true) is reported unless show / defaultShow was already true. A controlled accordion stays as its show prop says until the parent applies that change. Later changes of options.open are ignored.

ReturnsTypeDescription
showbooleanThe current open state (the show prop when controlled).
toggle() => voidFlips the state and reports it through onShowChange; does nothing while options.disabled.
sharedContainerClassesstring[]The border and divider classes (with smart:dark: variants) of the default container.
import { useState } from 'react';

import {
  IAccordionOptions,
  SmartAccordionBaseProps,
  useAccordion,
} from '@smartsoft001/react';

export function CustomAccordion(props: SmartAccordionBaseProps) {
  const { options, className, headerTpl, bodyTpl } = props;
  const { show, toggle, sharedContainerClasses } = useAccordion(props);

  return (
    <div
      className={['docs-accordion', ...sharedContainerClasses, className]
        .filter(Boolean)
        .join(' ')}
    >
      <button
        type="button"
        className="docs-accordion__header"
        disabled={options?.disabled ?? false}
        aria-expanded={show}
        onClick={toggle}
      >
        {headerTpl}
        <span aria-hidden="true">{show ? '-' : '+'}</span>
      </button>

      {show && <div className="docs-accordion__body">{bodyTpl}</div>}
    </div>
  );
}

const options: IAccordionOptions = { disabled: false };

// The accordion has no SmartProvider registry key, so a custom implementation
// is rendered directly in place of <SmartAccordion>.
export function AccordionCustomExample() {
  const [open, setOpen] = useState(false);

  return (
    <CustomAccordion
      headerTpl="What is the best thing about Switzerland?"
      bodyTpl="I don't know, but the flag is a big plus."
      show={open}
      onShowChange={setOpen}
      options={options}
    />
  );
}

Styling

  • Tailwind 4 classes with the smart: prefix; the default container uses useAccordion().sharedContainerClasses and the preset its own getAccordionPreset*Classes, both with smart:dark: variants.
  • className is appended to the container in both variations.
  • options.animated is deprecated and has no effect.

Source

The component lives in packages/shared/react/src/lib/components/accordion and is documented for Claude Code by the react-components-accordion skill.