Banner
Add a government banner so visitors can identify an official U.S. government website and check its security information.
These examples use the following JavaScript initializers:
Usage
Mobile
320pxMobile Lg
480pxTablet
640pxDesktop
1024pxAn official website of the United States government
Official websites use .gov
A .gov website belongs to an official government organization in the United States.
Secure .gov websites use HTTPS
A lock () or https:// means you've safely connected to the .gov website. Share sensitive information only on official, secure websites.
Component API
Initialization
Run after the component markup exists:
import { collapseInit } from '@uswds-tailwind/compat/collapse'
collapseInit()Banner uses Collapse; there is no separate Banner initializer.
Anatomy
Set authored attributes in your HTML. The component manages generated attributes. Types describe HTML attribute values.
root
The banner section.
| Attribute | Type | Description |
|---|---|---|
data-scope |
"collapse" |
Authored. Identifies the component scope. |
data-part |
"root" |
Authored. Identifies this part. |
aria-label |
string |
Authored. Descriptive name for the banner landmark. |
data-state |
"open" | "closed" |
Authored. Use "open" to expand initially; defaults to closed. |
data-state |
"open" | "closed" |
Generated. "open" or "closed"; use for styling. |
trigger
A native button with descriptive text.
| Attribute | Type | Description |
|---|---|---|
data-part |
"trigger" |
Authored. Identifies this part. |
data-state |
"open" | "closed" |
Generated. "open" or "closed"; use for styling. |
aria-expanded |
"true" | "false" |
Generated. Whether the content is expanded. |
aria-controls |
ID reference |
Generated. ID of the associated content. |
content
The expandable panel. Keep it inside the same root as its trigger.
| Attribute | Type | Description |
|---|---|---|
data-part |
"content" |
Authored. Identifies this part. |
data-state |
"open" | "closed" |
Generated. "open" or "closed"; use for styling. |
hidden |
boolean attribute |
Generated. Present when closed. |
Configuration
Pass these JavaScript options to the instance constructor or factory. Authored configuration attributes are read during construction.
| Option | Description |
|---|---|
defaultOpen |
Initial uncontrolled open state; overrides the authored initial state. |
open |
Controlled open state. Your application must supply the updated value after a change callback. |
id, ids |
Customize the instance identifier and generated element IDs. |
Methods
| Method | Returns | Description |
|---|---|---|
open() |
Promise<void> |
Requests expansion. |
close() |
Promise<void> |
Requests collapse. |
destroy() |
void |
Stops the instance and clears its lookup. |
import { Collapse } from '@uswds-tailwind/compat/collapse'
const banner = Collapse.getOrCreateInstance( '[data-scope="collapse"][data-part="root"]',)
await banner.open()Promises settle the queued update, not CSS transitions. When using controlled state, your application must supply the updated value.
See initialization and cleanup.
Callbacks
| Callback | Payload | When it runs |
|---|---|---|
onOpenChange |
{ open: boolean } |
An open-state change is requested. |
Pass callbacks in instance options. These are JavaScript functions, not emitted DOM events.
Accessibility
- Supply the landmark name, banner copy, and visible focus styles.
- Use Enter or Space to activate the native button.