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,9 +87,67 @@ 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+ // TODO: export these
91+ export interface AccordionItemState {
92+ /** Whether the accordion item is currently expanded. */
93+ readonly isExpanded : boolean ,
94+ /** Sets whether the accordion item is expanded. */
95+ setExpanded ( isExpanded : boolean ) : void ,
96+ /** Expand the accordion item. */
97+ expand ( ) : void ,
98+ /** Collapse the accordion item. */
99+ collapse ( ) : void ,
100+ /** Toggles the accordion item's visibility. */
101+ toggle ( ) : void
102+ }
103+
104+ export interface AccordionItemRenderProps {
105+ /**
106+ * Whether the accordion item is expanded.
107+ * @selector [data-expanded]
108+ */
109+ isExpanded : boolean ,
110+ /**
111+ * Whether the accordion item has keyboard focus.
112+ * @selector [data-focus-visible-within]
113+ */
114+ isFocusVisibleWithin : boolean ,
115+ /**
116+ * Whether the accordion item is disabled.
117+ * @selector [data-disabled]
118+ */
119+ isDisabled : boolean ,
120+ /**
121+ * State of the accordion item.
122+ */
123+ state : AccordionItemState
124+ }
125+
126+ export interface AccordionItemProps extends Omit < RenderProps < AccordionItemRenderProps > , 'className' | 'style' > , SlotProps , StyleProps {
127+ /**
128+ * The size of the accordion item.
129+ * @default 'M'
130+ */
131+ size ?: 'S' | 'M' | 'L' | 'XL' ,
132+ /**
133+ * The amount of space between the accordion item.
134+ * @default 'regular'
135+ */
136+ density ?: 'compact' | 'regular' | 'spacious' ,
137+ /** Whether the accordion item should be displayed with a quiet style. */
138+ isQuiet ?: boolean ,
139+ /** The contents of the accordion item, consisting of a accordion item title and accordion item panel. */
140+ children : ReactNode ,
141+ /** An id for the accordion item, matching the id used in `expandedKeys`. */
142+ id ?: Key ,
143+ /** Whether the accordion item is disabled. */
144+ isDisabled ?: boolean ,
145+ /** Handler that is called when the accordion item's expanded state changes. */
146+ onExpandedChange ?: ( isExpanded : boolean ) => void ,
147+ /** Whether the accordion item is expanded (controlled). */
148+ isExpanded ?: boolean ,
149+ /** Whether the accordion item is expanded by default (uncontrolled). */
150+ defaultExpanded ?: boolean
86151}
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.
@@ -91,7 +156,16 @@ export const AccordionItem = forwardRef(function AccordionItem(props: AccordionI
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