brumate/ui

Disclosure

A section that the user expands and collapses, such as a question of an FAQ.

<script>
  import Button from '@brumate/ui/Button.brm';
  import Disclosure from '@brumate/ui/Disclosure.brm';
  import DisclosurePanel from '@brumate/ui/DisclosurePanel.brm';
  import Heading from '@brumate/ui/Heading.brm';
  import Icon from '../../src/components/Icon.brm';
</script>

<div class="ui-accordion">
<Disclosure class="ui-disclosure">
  <Heading level=(2)>
    <Button slot="trigger" class="ui-disclosure-trigger">
      Shipping
      <Icon name="chevron" />
    </Button>
  </Heading>
  <DisclosurePanel transition class="ui-disclosure-panel">
    <p>Orders leave the shop in two days.</p>
  </DisclosurePanel>
</Disclosure>
</div>

Animating the panel

transition on the DisclosurePanel lets CSS animate it. The demo above uses it.

.panel {
  height: var(--disclosure-panel-height, auto);
  overflow: clip;
  transition: height 0.25s;
}

Keeping the content

unmount on the DisclosurePanel decides what happens to the content while the panel is collapsed:

unmount The content while collapsed
false Stays in the page with hidden="until-found". This is the default.
true Leaves the page, and starts over when the panel opens.
'offscreen' Stays in an #offscreen block, with its state, and its effects pause.

With true and 'offscreen', a panel that starts collapsed has no content in the page that the server sends, so find in page and search engines do not reach it. Keep the default for text that people search for.