1010 * governing permissions and limitations under the License.
1111 */
1212
13- import { ContextValue , DisclosureGroup , DisclosureGroupProps , SlotProps } from 'react-aria-components' ;
13+ import { AriaLabelingProps , DOMProps , DOMRef , DOMRefValue , Key } from '@react-types/shared' ;
14+ import { ContextValue , DisclosureGroup , RenderProps , SlotProps } from 'react-aria-components' ;
1415import {
1516 Disclosure ,
1617 DisclosureContext ,
1718 DisclosureHeader ,
1819 DisclosurePanel ,
19- DisclosurePanelProps ,
20- DisclosureProps ,
21- DisclosureTitle ,
22- DisclosureTitleProps
20+ DisclosureTitle
2321} from './Disclosure' ;
24- import { DOMProps , DOMRef , DOMRefValue , GlobalDOMAttributes } from '@react-types/shared' ;
25- import { getAllowedOverrides , StylesPropWithHeight , UnsafeStyles } from './style-utils' with { type : 'macro' } ;
22+ import { getAllowedOverrides , StyleProps , StylesPropWithHeight , UnsafeStyles } from './style-utils' with { type : 'macro' } ;
2623import React , { createContext , forwardRef , ReactNode } from 'react' ;
2724import { style } from '../style' with { type : 'macro' } ;
2825import { useDOMRef } from '@react-spectrum/utils' ;
2926import { useSpectrumContextProps } from './useSpectrumContextProps' ;
3027
31- export interface AccordionProps extends Omit < DisclosureGroupProps , 'className' | 'style' | 'children' | keyof GlobalDOMAttributes > , UnsafeStyles , DOMProps , SlotProps {
32- /** The disclosure elements in the accordion. */
28+ export interface AccordionProps extends UnsafeStyles , DOMProps , SlotProps {
29+ /** The accordion item elements in the accordion. */
3330 children : React . ReactNode ,
3431 /** Spectrum-defined styles, returned by the `style()` macro. */
3532 styles ?: StylesPropWithHeight ,
@@ -39,12 +36,22 @@ export interface AccordionProps extends Omit<DisclosureGroupProps, 'className' |
3936 */
4037 size ?: 'S' | 'M' | 'L' | 'XL' ,
4138 /**
42- * The amount of space between the disclosure items.
39+ * The amount of space between the accordion items.
4340 * @default 'regular'
4441 */
4542 density ?: 'compact' | 'regular' | 'spacious' ,
4643 /** Whether the accordion should be displayed with a quiet style. */
47- isQuiet ?: boolean
44+ isQuiet ?: boolean ,
45+ /** Whether multiple accordion items can be expanded at the same time. */
46+ allowsMultipleExpanded ?: boolean ,
47+ /** Whether all accordion items are disabled. */
48+ isDisabled ?: boolean ,
49+ /** The currently expanded keys in the accordion (controlled). */
50+ expandedKeys ?: Iterable < Key > ,
51+ /** The initial expanded keys in the accordion (uncontrolled). */
52+ defaultExpandedKeys ?: Iterable < Key > ,
53+ /** Handler that is called when accordion items are expanded or collapsed. */
54+ onExpandedChange ?: ( keys : Set < Key > ) => any
4855}
4956
5057const accordion = style ( {
@@ -80,18 +87,85 @@ export const Accordion = forwardRef(function Accordion(props: AccordionProps, re
8087 ) ;
8188} ) ;
8289
83- export interface AccordionItemProps extends DisclosureProps {
84- /** The contents of the accordion, consisting of a AccordionItemTitle and AccordionItemPanel. */
85- children : ReactNode
90+ export interface AccordionItemState {
91+ /** Whether the accordion item is currently expanded. */
92+ readonly isExpanded : boolean ,
93+ /** Sets whether the accordion item is expanded. */
94+ setExpanded ( isExpanded : boolean ) : void ,
95+ /** Expand the accordion item. */
96+ expand ( ) : void ,
97+ /** Collapse the accordion item. */
98+ collapse ( ) : void ,
99+ /** Toggles the accordion item's visibility. */
100+ toggle ( ) : void
86101}
102+
103+ export interface AccordionItemRenderProps {
104+ /**
105+ * Whether the accordion item is expanded.
106+ * @selector [data-expanded]
107+ */
108+ isExpanded : boolean ,
109+ /**
110+ * Whether the accordion item has keyboard focus.
111+ * @selector [data-focus-visible-within]
112+ */
113+ isFocusVisibleWithin : boolean ,
114+ /**
115+ * Whether the accordion item is disabled.
116+ * @selector [data-disabled]
117+ */
118+ isDisabled : boolean ,
119+ /**
120+ * State of the accordion item.
121+ */
122+ state : AccordionItemState
123+ }
124+
125+ export interface AccordionItemProps extends Omit < RenderProps < AccordionItemRenderProps > , 'className' | 'style' > , SlotProps , StyleProps {
126+ /**
127+ * The size of the accordion item.
128+ * @default 'M'
129+ */
130+ size ?: 'S' | 'M' | 'L' | 'XL' ,
131+ /**
132+ * The amount of space between the accordion item.
133+ * @default 'regular'
134+ */
135+ density ?: 'compact' | 'regular' | 'spacious' ,
136+ /** Whether the accordion item should be displayed with a quiet style. */
137+ isQuiet ?: boolean ,
138+ /** The contents of the accordion item, consisting of a accordion item title and accordion item panel. */
139+ children : ReactNode ,
140+ /** An id for the accordion item, matching the id used in `expandedKeys`. */
141+ id ?: Key ,
142+ /** Whether the accordion item is disabled. */
143+ isDisabled ?: boolean ,
144+ /** Handler that is called when the accordion item's expanded state changes. */
145+ onExpandedChange ?: ( isExpanded : boolean ) => void ,
146+ /** Whether the accordion item is expanded (controlled). */
147+ isExpanded ?: boolean ,
148+ /** Whether the accordion item is expanded by default (uncontrolled). */
149+ defaultExpanded ?: boolean
150+ }
151+
87152/**
88153 * A accordion item is a collapsible section of content. It is composed of a header with a heading and trigger button, and a panel that contains the content.
89154 */
90155export const AccordionItem = forwardRef ( function AccordionItem ( props : AccordionItemProps , ref : DOMRef < HTMLDivElement > ) {
91156 return < Disclosure { ...props } ref = { ref } /> ;
92157} ) ;
93158
94- export interface AccordionItemTitleProps extends DisclosureTitleProps { }
159+ export interface AccordionItemTitleProps extends UnsafeStyles , DOMProps {
160+ /** The heading level of the accordion item title.
161+ *
162+ * @default 3
163+ */
164+ level ?: number ,
165+ /** The contents of the accordion item title. */
166+ children : React . ReactNode
167+ }
168+
95169/**
96170 * An accordion item title consisting of a heading and a trigger button to expand/collapse the panel.
97171 */
@@ -100,16 +174,27 @@ export const AccordionItemTitle = forwardRef(function AccordionItemTitle(props:
100174} ) ;
101175
102176export interface AccordionItemHeaderProps extends UnsafeStyles , DOMProps {
177+ /** The contents of the accordion item header. */
103178 children : React . ReactNode
104179}
180+
105181/**
106182 * A wrapper element for the accordion item title that can contain other elements not part of the trigger.
107183 */
108184export const AccordionItemHeader = forwardRef ( function AccordionItemHeader ( props : AccordionItemHeaderProps , ref : DOMRef < HTMLDivElement > ) {
109185 return < DisclosureHeader { ...props } ref = { ref } /> ;
110186} ) ;
111187
112- export interface AccordionItemPanelProps extends DisclosurePanelProps { }
188+ export interface AccordionItemPanelProps extends UnsafeStyles , DOMProps , AriaLabelingProps {
189+ /** The contents of the accordion item panel. */
190+ children : React . ReactNode ,
191+ /**
192+ * The accessibility role for the accordion item panel.
193+ * @default 'group'
194+ */
195+ role ?: 'group' | 'region'
196+ }
197+
113198/**
114199 * An accordion item panel is a collapsible section of content that is hidden until the accordion item is expanded.
115200 */
0 commit comments