<cs-details>
StableLayoutSince 0.1

Details display a brief summary and expand to reveal additional content. Use them to progressively disclose information, group related FAQs, or hide advanced options.

Click the summary to expand and collapse the details component. You can put any content in here that you want to reveal on demand!

Examples

Expanded Initially

Use the open attribute to expand the details initially.

This details component is expanded by default. Users can click the summary to collapse it if they want to hide the content.

Disabled

Use the disabled attribute to prevent the details from expanding.

This content can't be seen because the details component is disabled. Try removing the disabled attribute to reveal what's inside!

Expand & Collapse Icons

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 icon part as shown below.

This example uses custom plus and minus icons for expanding and collapsing. You can use any icon you want to match the look and feel of your app.

Icon Placement

The default position for the expand and collapse icons is at the end of the summary. Set the icon-placement attribute to start to place the icon at the start of the summary.

The expand/collapse icon is at the start of the summary. This is a common pattern that feels familiar to users who are used to tree views and file explorers. The expand/collapse icon is at the end of the summary. This is the default placement and works great for most use cases.

HTML in Summary

To use HTML in the summary, use the summary slot. Links and other interactive elements will still retain their behavior:

Some text a link more text You can use the summary slot to put HTML in the summary, including links and other interactive elements. Pretty neat, right?

Right-to-Left Languages

The details component, including its icon-placement, automatically adapts to right-to-left languages:

استخدام طريقة لوريم إيبسوم لأنها تعطي توزيعاَ طبيعياَ -إلى حد ما- للأحرف عوضاً عن استخدام طريقة لوريم إيبسوم لأنها تعطي توزيعاَ طبيعياَ -إلى حد ما- للأحرف عوضاً عن

Appearance

Use the appearance attribute to change the element’s visual appearance.

This is the default outlined appearance. It has a subtle border that helps it stand out without being too flashy. The filled-outlined appearance combines a filled header with an outlined body. It gives the summary a bit more visual weight while keeping the content area clean. The filled appearance adds a background color to the entire component. Use this when you want the details to really pop on the page. No bells and whistles on this one. The plain appearance strips away borders and backgrounds for a minimalist look.

Grouping Details

Use the name attribute to create accordion-like behavior where only one details element with the same name can be open at a time. This matches the behavior of native <details> elements.

This is the first section of the accordion. When you open another section, this one will close automatically. Give it a try! This is the second section. Notice how the first section closed when you opened this one? That's the accordion behavior in action, powered by the shared name attribute. And here's the third section. You can have as many sections as you need — just make sure they all share the same name and only one will be open at a time.

API

Importing

If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick this component, use one of the following snippets.

npm Self-Hosted React
import '@cruglobal/cornerstone-components/components/details/details.js';
import './cornerstone/components/details/details.js';
import CsDetails from '@cruglobal/cornerstone-components/react/details/index.js';

Slots

Learn more about using slots.

NameDescription
(default)The details' main content.
collapse-iconOptional collapse icon to use instead of the default. Works best with <cs-icon>.
expand-iconOptional expand icon to use instead of the default. Works best with <cs-icon>.
summaryThe details' summary. Alternatively, you can use the summary attribute.

Attributes & Properties

Learn more about attributes and properties.

PropertyAttributeDescriptionTypeDefaultReflects
appearanceappearanceThe element's visual appearance.'filled' | 'outlined' | 'filled-outlined' | 'plain''outlined'Yes
disableddisabledDisables the details so it can't be toggled.booleanfalseYes
iconPlacementicon-placementThe location of the expand/collapse icon.'start' | 'end''end'Yes
namenameGroups related details elements. When one opens, others with the same name will close.stringYes
openopenIndicates 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.booleanfalseYes
summarysummaryThe summary to show in the header. If you need to display HTML, use the summary slot instead.string

Methods

Learn more about methods.

NameDescriptionArguments
hide()Hides the details
show()Shows the details.

Events

Learn more about events.

NameDescription
cs-after-hideEmitted after the details closes and all animations are complete.
cs-after-showEmitted after the details opens and all animations are complete.
cs-hideEmitted when the details closes.
cs-showEmitted when the details opens.

CSS Custom Properties

Learn more about CSS custom properties.

NameDescriptionDefault
--hide-durationThe hide duration to use when applying built-in animation classes.var(--cs-transition-normal)
--show-durationThe show duration to use when applying built-in animation classes.var(--cs-transition-normal)
--spacingThe amount of space around and between the details' content. Expects a single value.

Custom States

Learn more about custom states.

NameDescriptionCSS selector
animatingApplied when the details is animating expand/collapse.:state(animating)

CSS Parts

Learn more about CSS parts.

NameDescriptionCSS selector
contentThe details content.::part(content)
detailsThe component's outer wrapper. Styles you apply to the component are automatically applied to this part, so you usually don't need to deal with it unless you need to set the display property.::part(details)
headerThe header that wraps both the summary and the expand/collapse icon.::part(header)
iconThe container that wraps the expand/collapse icons.::part(icon)
summaryThe container that wraps the summary.::part(summary)

Dependencies

This component automatically imports the following elements. Sub-dependencies, if any exist, are included in this list.