Skip to main content
Light Dark System

Details

<sc-details> | ScDetails
Since 2.0 stable

Details show a brief summary and expand to show additional content.

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.
<sc-details summary="Toggle Me">
  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.
</sc-details>
import ScDetails from '@styledc-dev/styledc/dist/react/details';

const App = () => (
  <ScDetails summary="Toggle Me">
    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.
  </ScDetails>
);

Examples

Disabled

Use the disable attribute to prevent the details from expanding.

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.
<sc-details summary="Disabled" disabled>
  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.
</sc-details>
import ScDetails from '@styledc-dev/styledc/dist/react/details';

const App = () => (
  <ScDetails summary="Disabled" disabled>
    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.
  </ScDetails>
);

Customizing the Summary Icon

Use the expand-icon and collapse-icon slots to change the expand and collapse icons, respectively. To disable the animation, override the rotate property on the summary-icon part as shown below.

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.
<sc-details summary="Toggle Me" class="custom-icons">
  <sc-icon name="plus-square" slot="expand-icon"></sc-icon>
  <sc-icon name="dash-square" slot="collapse-icon"></sc-icon>

  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.
</sc-details>

<style>
  sc-details.custom-icons::part(summary-icon) {
    /* Disable the expand/collapse animation */
    rotate: none;
  }
</style>
import ScDetails from '@styledc-dev/styledc/dist/react/details';
import ScIcon from '@styledc-dev/styledc/dist/react/icon';

const css = `
  sc-details.custom-icon::part(summary-icon) {
    /* Disable the expand/collapse animation */
    rotate: none;
  }
`;

const App = () => (
  <>
    <ScDetails summary="Toggle Me" class="custom-icon">
      <ScIcon name="plus-square" slot="expand-icon" />
      <ScIcon name="dash-square" slot="collapse-icon" />
      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.
    </ScDetails>

    <style>{css}</style>
  </>
);

Grouping Details

Details are designed to function independently, but you can simulate a group or “accordion” where only one is shown at a time by listening for the sc-show event.

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. 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. 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.
<div class="details-group-example">
  <sc-details summary="First" open>
    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.
  </sc-details>

  <sc-details summary="Second">
    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.
  </sc-details>

  <sc-details summary="Third">
    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.
  </sc-details>
</div>

<script>
  const container = document.querySelector('.details-group-example');

  // Close all other details when one is shown
  container.addEventListener('sc-show', event => {
    if (event.target.localName === 'sc-details') {
      [...container.querySelectorAll('sc-details')].map(details => (details.open = event.target === details));
    }
  });
</script>

<style>
  .details-group-example sc-details:not(:last-of-type) {
    margin-bottom: var(--sc-spacing-2x-small);
  }
</style>

Importing

If you’re using the autoloader or the traditional loader, you can ignore this section. Otherwise, feel free to use any of the following snippets to cherry pick this component.

Script Import Bundler React

To import this component from the CDN using a script tag:

<script type="module" src="https://cdn.jsdelivr.net/npm/@styledc-dev/styledc@1.0.0/cdn/components/details/details.js"></script>

To import this component from the CDN using a JavaScript import:

import 'https://cdn.jsdelivr.net/npm/@styledc-dev/styledc@1.0.0/cdn/components/details/details.js';

To import this component using a bundler:

import '@styledc-dev/styledc/dist/components/details/details.js';

To import this component as a React component:

import ScDetails from '@styledc-dev/styledc/dist/react/details';

Slots

Name Description
(default) The details’ main content.
summary The details’ summary. Alternatively, you can use the summary attribute.
expand-icon Optional expand icon to use instead of the default. Works best with <sc-icon>.
collapse-icon Optional collapse icon to use instead of the default. Works best with <sc-icon>.

Learn more about using slots.

Properties

Name Description Reflects Type Default
open Indicates whether or not the details is open. You can toggle this attribute to show and hide the details, or you can use the show() and hide() methods and this attribute will reflect the details’ open state. boolean false
summary The summary to show in the header. If you need to display HTML, use the summary slot instead. string -
disabled Disables the details so it can’t be toggled. boolean false
updateComplete A read-only promise that resolves when the component has finished updating.

Learn more about attributes and properties.

Events

Name React Event Description Event Detail
sc-show onScShow Emitted when the details opens. -
sc-after-show onScAfterShow Emitted after the details opens and all animations are complete. -
sc-hide onScHide Emitted when the details closes. -
sc-after-hide onScAfterHide Emitted after the details closes and all animations are complete. -

Learn more about events.

Methods

Name Description Arguments
show() Shows the details. -
hide() Hides the details -

Learn more about methods.

Parts

Name Description
base The component’s base wrapper.
header The header that wraps both the summary and the expand/collapse icon.
summary The container that wraps the summary.
summary-icon The container that wraps the expand/collapse icons.
content The details content.

Learn more about customizing CSS parts.

Animations

Name Description
details.show The animation to use when showing details. You can use height: auto with this animation.
details.hide The animation to use when hiding details. You can use height: auto with this animation.

Learn more about customizing animations.

Dependencies

This component automatically imports the following dependencies.

  • <sc-icon>