GUILD OF GLEKS UIv21.19.0

gog-collapsible

Collapsible

A headless expand/collapse primitive — inline, not a portal. It owns no markup of its own: project any element as the trigger with gogCollapsibleTrigger and any element as the panel with gogCollapsibleContent.

Overview

Import the component and its two directives.

typescript
import {
  CollapsibleComponent,
  GogCollapsibleTriggerDirective,
  GogCollapsibleContentDirective,
} from '@guildofgleks/ui';

@Component({
  // ...
  imports: [CollapsibleComponent, GogCollapsibleTriggerDirective, GogCollapsibleContentDirective],
})

A trigger and a panel, both projected in — [(open)] is two-way bindable. The trigger here is a native button styled with gogButton; the library draws none of its own.

open: false

<gog-collapsible [(open)]="open">
  <button type="button" gogButton variant="outline" gogCollapsibleTrigger>
    {{ open() ? 'Hide details' : 'Show details' }}
  </button>
  <p gogCollapsibleContent>Ships within 2 business days via standard courier.</p>
</gog-collapsible>

<p>open: {{ open() }}</p>

Examples

Trigger host and state

A headless primitive: what it adds is the state, the ARIA wiring between trigger and content, and the height animation — the look is the trigger's. On a <div> the directive supplies what a button would have had: role="button", a tab stop and Enter/Space, so the second row is just as reachable as the first. disabled ignores presses and dims the trigger through --gog-collapsible-disabled-opacity; a programmatic [open] write still works.

<button>

Ships within 2 business days.

<div>
Open

Ships within 2 business days.

<!-- gog-collapsible renders no box of its own (display: contents), so each cell is a <div>. -->
<div>
  <span>&lt;button&gt;</span>
  @for (state of states; track state.name) {
    <div>
      <gog-collapsible [open]="state.open" [disabled]="state.disabled">
        <button type="button" gogButton variant="outline" gogCollapsibleTrigger>
          {{ state.name }}
        </button>
        <p gogCollapsibleContent>Ships within 2 business days.</p>
      </gog-collapsible>
    </div>
  }
</div>
<div>
  <!-- The directive makes a <div> a control: role="button", tabindex="0", Enter and Space. -->
  <span>&lt;div&gt;</span>
  @for (state of states; track state.name) {
    <div>
      <gog-collapsible [open]="state.open" [disabled]="state.disabled">
        <div gogCollapsibleTrigger>{{ state.name }}</div>
        <p gogCollapsibleContent>Ships within 2 business days.</p>
      </gog-collapsible>
    </div>
  }
</div>

The trigger is yours

Any markup inside the trigger, drawn from the open signal the page already holds — a chevron that flips, an icon and a label that swap. The directive also sets .gog-collapsible__trigger--open on the trigger while open, for a stylesheet that would rather rotate one icon.

<!-- The trigger draws its own state from the open signal the page already holds. -->
<gog-collapsible [(open)]="chevronOpen">
  <button type="button" gogButton variant="ghost" gogCollapsibleTrigger>
    Notifications
    <gog-icon [name]="chevronOpen() ? 'chevron-up' : 'chevron-down'" />
  </button>
  <p gogCollapsibleContent>Email digests, push alerts, weekly summary.</p>
</gog-collapsible>

<gog-collapsible [(open)]="swapOpen">
  <button type="button" gogButton variant="ghost" gogCollapsibleTrigger>
    <gog-icon [name]="swapOpen() ? 'minus' : 'plus'" />
    {{ swapOpen() ? 'Hide diagnostics' : 'Show diagnostics' }}
  </button>
  <p gogCollapsibleContent>Last check: all systems nominal, p99 118 ms.</p>
</gog-collapsible>

Height

Open, the content is as tall as it is: --gog-collapsible-max-height defaults to max-content, which animates where interpolate-size is supported and snaps open elsewhere. Set a length only to cap a panel on purpose — the rest is clipped, as the last lines of this list are.

<gog-collapsible [(open)]="open">
  <button type="button" gogButton variant="outline" gogCollapsibleTrigger>
    Changelog, capped at 6rem
  </button>
  <!-- An instance token: the panel stops at 6rem and clips the rest. -->
  <ul gogCollapsibleContent style="--gog-collapsible-max-height: 6rem">
    @for (version of versions; track version) {
      <li>v{{ version }}.0 — fixes and polish.</li>
    }
  </ul>
</gog-collapsible>

An overlay inside the content

Open the select: its list runs past the content's edge. The content clips only while it animates; open and settled it does not 21.15.0, so a dropdown, menu or tooltip inside is whole. A capped panel keeps clipping — that cap is the point of it.

<gog-collapsible [(open)]="open">
  <button type="button" gogButton variant="outline" gogCollapsibleTrigger>Regional</button>
  <div gogCollapsibleContent>
    <gog-select label="Time zone" [options]="timezones" [(value)]="timezone" />
  </div>
</gog-collapsible>

Driven from outside

A collapsible without a gogCollapsibleTrigger is driven entirely by [(open)]. Its content still carries the id, aria-hidden and inert; the controls are the page's own, so wiring aria-expanded onto them is the page's job — gog-button's ariaExpanded does it.

open: false

<div>
  <!-- No gogCollapsibleTrigger: wiring aria-expanded onto these is the page's job. -->
  <gog-button variant="outline" size="sm" [ariaExpanded]="open()" (gogClick)="open.set(true)">
    Open
  </gog-button>
  <gog-button variant="outline" size="sm" [ariaExpanded]="open()" (gogClick)="open.set(false)">
    Close
  </gog-button>
</div>
<gog-collapsible [(open)]="open">
  <p gogCollapsibleContent>Opened from outside.</p>
</gog-collapsible>

<p>open: {{ open() }}</p>

Close when focus leaves

collapseOnFocusOut closes the panel once focus leaves both the trigger and the content: Tab past the last link, or click somewhere else on the page. Clicking the plain text inside keeps it open 21.15.0. Off by default, because an FAQ or a settings section read top to bottom should stay open wherever focus goes.

open: false · closed by focus leaving: 0

<gog-collapsible [open]="open()" (openChange)="onOpenChange($event)" collapseOnFocusOut>
  <button type="button" gogButton variant="outline" gogCollapsibleTrigger>Quick links</button>
  <p gogCollapsibleContent>
    Plain text in the content, then two links:
    <a href="#overview">Billing</a> · <a href="#overview">Team</a>
  </p>
</gog-collapsible>

<p>open: {{ open() }} · closed by focus leaving: {{ closes() }}</p>

A list of independent collapsibles

Each item holds its own state, so several can be open at once — nothing closes a sibling. For one-at-a-time, keyboard movement between headers and a heading level, that is gog-accordion.

<div>
  <!-- Each item holds its own state, so several can be open at once. -->
  @for (item of faq(); track item.id) {
    <gog-collapsible [open]="item.open" (openChange)="setOpen(item.id, $event)">
      <button type="button" gogButton variant="ghost" gogCollapsibleTrigger>
        {{ item.title }}
      </button>
      <p gogCollapsibleContent>{{ item.body }}</p>
    </gog-collapsible>
  }
</div>

Accessibility

The trigger says whether it is expanded and what it controls; on an element that is not already a control, the directive makes it one.

  • Trigger — aria-expanded and aria-controls pointing at the content, plus aria-disabled while disabled. A <button> is left as written; any other element gets role="button" and tabindex="0". A host whose role or tabindex the consumer set keeps it.
  • Keyboard — Tab reaches the trigger; Enter or Space toggles it, on a <div> trigger as on a button.
  • Content — carries the id the trigger points at. Closed, it is aria-hidden and inert, so nothing inside it takes focus or is read out.
  • Name — the trigger's own text. A trigger that is only an icon needs an aria-label of its own.

API Reference

Inputs

NameTypeDefaultDescription
openboolean (model)falseTwo-way bindable open state via [(open)]. Bind it directly to drive the panel from outside — no trigger required.
disabledbooleanfalseBlocks toggle() and the trigger's click handler. Programmatic [open] writes still work.
collapseOnFocusOutbooleanfalseCloses the panel once focus leaves both the trigger and the content — Tabbing past the last focusable element inside, or a click landing elsewhere on the page. Off by default, since plenty of consumers (an FAQ list, a settings section read top to bottom) want the panel to stay open regardless of where focus goes next.
rippleboolean | undefinedundefinedPress ripple on the gogCollapsibleTrigger element. Unset, falls back to GOG_CONFIG.ripple.enabled, which is off by default; setting it here wins over the app-wide value in both directions.

Outputs

NamePayloadDescription
openChangebooleanThe new open state, on a trigger press or a focus-out close. Comes from the open model input.

Directives

SelectorGoes onDescription
[gogCollapsibleTrigger]any element inside gog-collapsible — usually a <button>Marks the element that toggles the collapsible. Wires aria-expanded, aria-controls and (when disabled) aria-disabled onto whatever it is placed on; on an element that is not a <button> it also adds role="button", tabindex="0" and Enter/Space, unless the consumer set a role or tabindex.
[gogCollapsibleContent]any element inside gog-collapsibleMarks the element the collapsible shows and hides. Wires id, aria-hidden and inert onto whatever it's placed on — that element owns its own markup and layout.

Global Configuration

Set any of these once with provideGogConfig() instead of repeating them on every instance — an instance's own input still wins when it sets one itself. See Global Configuration for the full reference.

  • GOG_CONFIG.ripple.enabled — on gogCollapsibleTrigger

This site is not on the default here. The library ships ripple.enabled as false; these docs set it to true app-wide so the demos above actually show the press feedback. In a fresh app you get no ripple until you ask for one — the droplet button in the header switches this site between the two, and it is on right now.

Styling Tokens

The component itself renders no box — gogCollapsibleTrigger and gogCollapsibleContent style the elements you project, via global .gog-collapsible__* classes rather than a scoped stylesheet, since that content sits outside gog-collapsible's own view. See the Theming guide for the full token-layering model.

TokenDescription
--gog-collapsible-transition-durationExpand/collapse animation timing.
--gog-collapsible-max-heightHeight an open panel transitions toward. Defaults to max-content, so a panel is as tall as its content and never truncates it. Set a length to cap one deliberately — the panel is overflow: hidden, so a cap clips rather than scrolls.
--gog-collapsible-disabled-opacityOpacity applied to a disabled trigger.