|
| 1 | +--- |
| 2 | +layout: component |
| 3 | +title: Details |
| 4 | +status: use-with-caution-candidate |
| 5 | +intro-text: "Details makes content easier to scan as it hides information that may not be applicable to all users or situations. We use the Details component to situate plain language help at the point of the process where it is most relevant." |
| 6 | +figma-link-web: https://www.figma.com/file/JDFpGLIojfuQwANXScQjqe/VADS-Component-Examples?type=design&node-id=1350%3A22760&mode=design&t=TiJHClaf3VQ6wU6B-1 |
| 7 | +uswds-v3: default |
| 8 | +web-component: va-details |
| 9 | +web: true |
| 10 | +mobile-app: false |
| 11 | +uses_mermaid: true |
| 12 | +anchors: |
| 13 | + - anchor: Examples |
| 14 | + - anchor: Usage |
| 15 | + - anchor: Behavior |
| 16 | + - anchor: Code usage |
| 17 | + - anchor: Content considerations |
| 18 | + - anchor: Accessibility considerations |
| 19 | + - anchor: Related |
| 20 | + - anchor: Component checklist |
| 21 | +--- |
| 22 | + |
| 23 | +## Examples |
| 24 | + |
| 25 | +### Default |
| 26 | + |
| 27 | +{% include storybook-preview.html story="uswds-va-details--default" link_text="va-details default" %} |
| 28 | + |
| 29 | +## Usage |
| 30 | + |
| 31 | +### When to use Details |
| 32 | + |
| 33 | +* **Revealing helpful background information**: When you have additional information you want to convey about an application, process, or a step or question in a form that is not critical. This component should be used in instances where a more prominent [Alert]({{ site.baseurl }}/components/alert) would not be appropriate. |
| 34 | +* **Clarifying outcomes for an input**: In cases where a person's input can have large or complicated impact on outcomes we use contextual help in Details to locate expanded guidance next to the relevant interaction. |
| 35 | +* **Information closely tied to an input.** Use this component over an [Accordion]({{ site.baseurl }}/components/accordion) when the content is closely tied to a particular message or input on the screen. If the content is more tangentially related then use an Accordion. |
| 36 | +* **Clarifying a form question**: If a form question needs clarification, and that clarification is brief, use Details. The lighter design prevents breaking up the visual progression as the user navigates the form. These can also serve as alternative to where accordions feel too heavy. Be sure to review the [hint text guidance]({{ site.baseurl }}/components/form/label#hint-text) for implementation details. If a form is a conversation, Details would be considered an aside. (This <a href="https://blog.navapbc.com/structuring-a-complex-eligibility-form-for-healthcare-gov-37d79a5ad6">case study on structuring complex health care questions for healthcare.gov</a> goes into greater detail on how to structure your form as a conversation.) |
| 37 | +* **Content that can be organized under the current heading.** If you have additional content that provides context and makes sense under the same heading as the content nearby. |
| 38 | +* **Information not applicable to all**: Details can hide details that may not be applicable to all users. |
| 39 | + |
| 40 | +### When to consider something else |
| 41 | + |
| 42 | +* **Accordions for a series**: If you have a series of content in the body of a page and outside of a form or tool then an [Accordion]({{ site.baseurl }}/components/accordion) is preferred. For example, if you have a series of questions as part of an FAQ section or a set of options for payment that each have additional details. |
| 43 | +* **Too much content**: Only include critical information inside this component. This includes form fields that require a lot of explanation. Link to another page, consider an [Accordion]({{ site.baseurl }}/components/accordion), or shorten the content. Collaborate with a member of the Content and IA team to edit content and explore alternatives. |
| 44 | +* **Required content**: If the majority of people need the content to accomplish the main task then it should not be hidden from view. |
| 45 | +* **Content organized under a new heading.** If you have enough content that it makes sense to organize under a new heading that does not make sense under the same heading as the content nearby then use an [Accordion]({{ site.baseurl }}/components/accordion). |
| 46 | +* **Error messages or other immediate actions**: Do not use this component for error messages or other critical or timely information. |
| 47 | +* **Inside Alerts**: Use this component inside an [Alert]({{ site.baseurl }}/components/alert) only as a last resort and if approved in the Collaboration Cycle. Instead use the [Alert - Expandable]({{ site.baseurl }}/components/alert/alert-expandable) component, especially when the Alert is within the page content and not at the top of the page. |
| 48 | +* **Floating in space**: Try to avoid using Details outside of the flow of the page, unattached to a section of content or another component. For example, there are instances of Details between a h1 and a Card. See [placement](#placement) for more. |
| 49 | + |
| 50 | +{% include content/details-vs-hint-text-vs-accordion.md %} |
| 51 | + |
| 52 | +## Behavior |
| 53 | + |
| 54 | +The Details component uses native HTML `<details>` and `<summary>` elements, which provide several advantages over JavaScript-based implementations: |
| 55 | + |
| 56 | +* **Searchable and discoverable content**: Browser search (Ctrl+F or Cmd+F) can find text inside collapsed Details, and search engines can index the content for better search engine optimization (SEO). |
| 57 | +* **Better performance and reliability**: No JavaScript required for basic functionality, improving load times and ensuring content works even when JavaScript fails. |
| 58 | +* **Enhanced accessibility**: Native semantic meaning provides better assistive technology support without additional ARIA attributes, following web standards universally supported across browsers. |
| 59 | + |
| 60 | +### Placement |
| 61 | + |
| 62 | +The following are places where Details can be used: |
| 63 | + |
| 64 | +* After a header (h2, h3, h4) or paragraph to provide orthogonal details or provide an answer to a common question. |
| 65 | +* Within a [Process list]({{ site.baseurl }}/components/process-list) to shorten the length of content within a step. |
| 66 | +* Within, or at the end, of a [Form]({{ site.baseurl }}/components/form/label#with-details) to provide additional help text. |
| 67 | +* Whenever there is a chance to enhance the understanding a user has about a particular choice. |
| 68 | + |
| 69 | +**Note:** Placement does not alter [content considerations](#content-considerations) in any way. |
| 70 | + |
| 71 | +{% include component-docs.html component_name=page.web-component %} |
| 72 | + |
| 73 | +## Content considerations |
| 74 | + |
| 75 | +* **Use a statement, rather than a question.** Use a statement (like "Why we ask for this information") rather than a question (like "Why does VA ask for this information?") for the title (trigger text) of the component. Because we use questions to gather information from people in our forms, structuring additional information as questions as well can cause confusion. Keep titles to a single sentence or sentence fragment with no ending punctuation. |
| 76 | +* **Limit the amount of expanded content.** Limit content to fewer than 500 characters (with spaces) when possible. If you need to provide more information, consider using one or more [Accordions]({{ site.baseurl }}/components/accordion) instead or providing a brief overview in the Details component with a link to another page with more information. Collaborate with a member of the Content and Information Architecture team to edit content and explore alternatives. |
| 77 | +* **Use lists in expanded content as needed.** To make content easier to scan, we encourage you to use numbered (also called "ordered") and bulleted (also called "unordered") lists as needed. |
| 78 | + |
| 79 | +## Accessibility considerations |
| 80 | + |
| 81 | +* **Wrap content in HTML elements.** All text content inside `va-details` must be wrapped in an appropriate HTML element such as `<p>`, `<span>`, or `<div>`. Some screen readers, particularly NVDA, may ignore unwrapped plain text. For example, use `<p>This is the content.</p>` instead of placing text directly inside the component without a wrapper element. |
| 82 | +* **Do not add ARIA roles or state attributes.** The details component uses the `<details>` HTML element that exposes expanded/collapsed state and interactive behavior natively. Adding any `role="button"` or `aria-expanded` is redundant and can create conflicting announcements in assistive technology. |
| 83 | +* **Keyboard interaction is provided natively.** Users must be able to tab to the component, toggle it using Enter or Space, and if there are interactive elements in the component, the next tab takes them to those interactive elements. |
| 84 | + |
| 85 | +## Related |
| 86 | + |
| 87 | +* [Accordion]({{ site.baseurl }}/components/accordion) |
| 88 | +* [Alert]({{ site.baseurl }}/components/alert) |
| 89 | + |
| 90 | +{% include _component-checklist.html component_name=page.web-component %} |
0 commit comments