Skip to content

Commit 91c5127

Browse files
authored
docs: follow-up on accordion docs from testing (#7232)
* docs: follow-up on accordion docs from testing * updates svgs for mobile, follow up from reviews * prevent outline on header on android * fix examples in useDisclosure on mobile * update focus visible * add focusProps to disclosure group example * use merge props
1 parent b5a412d commit 91c5127

File tree

7 files changed

+100
-54
lines changed

7 files changed

+100
-54
lines changed
Lines changed: 9 additions & 11 deletions
Loading

packages/@react-aria/disclosure/docs/useDisclosure.mdx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,24 @@ This example displays a basic disclosure with a button that toggles the visibili
7373
import {useDisclosureState} from '@react-stately/disclosure';
7474
import {useDisclosure} from '@react-aria/disclosure';
7575
import {useButton} from '@react-aria/button';
76+
import {mergeProps, useFocusRing} from 'react-aria';
7677

7778
function Disclosure(props) {
7879
let state = useDisclosureState(props);
7980
let panelRef = React.useRef<HTMLDivElement | null>(null);
8081
let triggerRef = React.useRef<HTMLButtonElement | null>(null);
8182
let {buttonProps: triggerProps, panelProps} = useDisclosure(props, state, panelRef);
8283
let {buttonProps} = useButton(triggerProps, triggerRef);
84+
let {isFocusVisible, focusProps} = useFocusRing();
8385

8486
return (
8587
<div className="disclosure">
8688
<h3>
87-
<button className="trigger" ref={triggerRef} {...buttonProps}>
89+
<button
90+
className="trigger"
91+
ref={triggerRef}
92+
{...mergeProps(buttonProps, focusProps)}
93+
style={{outline: isFocusVisible? '2px solid dodgerblue' : 'none'}}>
8894
<svg viewBox="0 0 24 24">
8995
<path d="m8.25 4.5 7.5 7.5-7.5 7.5" />
9096
</svg>
@@ -109,6 +115,8 @@ function Disclosure(props) {
109115
<summary style={{fontWeight: 'bold'}}><ChevronRight size="S" /> Show CSS</summary>
110116

111117
```css
118+
@import "@react-aria/example-theme";
119+
112120
.disclosure {
113121
.trigger {
114122
background: none;
@@ -119,6 +127,7 @@ function Disclosure(props) {
119127
display: flex;
120128
align-items: center;
121129
gap: 8px;
130+
color: var(--text-color);
122131

123132
svg {
124133
rotate: 0deg;
@@ -187,7 +196,7 @@ A disclosure can be disabled with the `isDisabled` prop. This will disable the t
187196

188197
A disclosure group (i.e. accordion) is a set of disclosures where only one disclosure can be expanded at a time. The following example shows how to create a `DisclosureGroup` component with the `useDisclosureGroupState` hook. We'll also create a `DisclosureItem` component that uses the `DisclosureGroupState` context for managing its state.
189198

190-
```tsx example export=true
199+
```tsx example export=true render=false
191200
import {useDisclosureGroupState} from '@react-stately/disclosure';
192201
import {useId} from '@react-aria/utils';
193202

@@ -231,11 +240,16 @@ function DisclosureItem(props) {
231240
isDisabled
232241
}, state, panelRef);
233242
let {buttonProps} = useButton(triggerProps, triggerRef);
243+
let {isFocusVisible, focusProps} = useFocusRing();
234244

235245
return (
236246
<div className="disclosure">
237247
<h3>
238-
<button className="trigger" ref={triggerRef} {...buttonProps}>
248+
<button
249+
className="trigger"
250+
ref={triggerRef}
251+
{...mergeProps(buttonProps, focusProps)}
252+
style={{outline: isFocusVisible? '2px solid dodgerblue' : 'none'}}>
239253
<svg viewBox="0 0 24 24">
240254
<path d="m8.25 4.5 7.5 7.5-7.5 7.5" />
241255
</svg>

packages/@react-spectrum/accordion/docs/Accordion.mdx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default Layout;
1313
import docs from 'docs:@react-spectrum/accordion';
1414
import {HeaderInfo, PropTable, TypeLink, PageDescription} from '@react-spectrum/docs';
1515
import packageData from '@react-spectrum/accordion/package.json';
16+
import ChevronRight from '@spectrum-icons/workflow/ChevronRight';
1617

1718
---
1819
category: Navigation
@@ -90,7 +91,7 @@ function ControlledExpansion() {
9091
}
9192
```
9293

93-
## Expansion
94+
## Expanded
9495

9596
By default, only one disclosure will be expanded at a time. To expand multiple disclosures, apply the `allowsMultipleExpanded` prop to Accordion.
9697

@@ -112,8 +113,18 @@ By default, only one disclosure will be expanded at a time. To expand multiple d
112113
```
113114
## Props
114115

116+
### Disclosure
117+
115118
<PropTable component={docs.exports.Accordion} links={docs.links} />
116119

120+
### Disclosure Panel
121+
122+
<PropTable component={docs.exports.DisclosurePanel} links={docs.links} />
123+
124+
### Disclosure Header
125+
126+
<PropTable component={docs.exports.DisclosureHeader} links={docs.links} />
127+
117128
## Visual Options
118129

119130
### Disabled

packages/react-aria-components/docs/Disclosure.mdx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,11 @@ import {Disclosure, Button, DisclosurePanel, Heading} from 'react-aria-component
103103

104104
## Features
105105

106-
Custom styled disclosures can be difficult to build in an accessible way with the correct ARIA pattern. When implementing, you must manually ensure that the button and panel are semantically connected via ids for accessibility. `Disclosure` helps with this and other accessibility features while allowing for custom styling.
106+
Disclosures can be built with the [&lt;details&gt;](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details) and [&lt;summary&gt;](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/summary) HTML element, but this can be difficult to style especially when adding adjacent interactive elements, like buttons, to the disclosure's heading. `Disclosure` helps achieve accessible disclosures implemented with the correct ARIA pattern while making custom styling easy.
107107

108108
* **Flexible** - Structured such that it can be used standalone or combined with other disclosures to form a `DisclosureGroup`
109-
* **Accessible** - When focused, a disclosure's visibility can be toggled with either the <Keyboard>Enter</Keyboard> or <Keyboard>Space</Keyboard> key, and the appropriate ARIA attributes are automatically applied.
109+
* **Keyboard Interaction** - When focused, a disclosure's visibility can be toggled with either the <Keyboard>Enter</Keyboard> or <Keyboard>Space</Keyboard> key, and the appropriate ARIA attributes are automatically applied.
110+
* **Accessible** - Uses hidden="until-found" in supported browsers, enabling find-in-page search support and improved search engine visibility for collapsed content
110111
* **Styleable** - Keyboard focus, disabled and expanded states are provided for easy styling. These states only apply when interacting with an appropriate input device, unlike CSS pseudo classes.
111112

112113
## Anatomy
@@ -202,6 +203,29 @@ A Disclosure can be disabled using the `isDisabled` prop.
202203
</MyDisclosure>
203204
```
204205

206+
## Interactive elements
207+
208+
In some use cases, you may want to add an interactive element, like a button, adjacent to the disclosure's heading.
209+
210+
```tsx example
211+
<Disclosure>
212+
<div style={{display: 'flex', alignItems: 'center'}}>
213+
<Heading>
214+
<Button slot="trigger">
215+
<svg viewBox="0 0 24 24">
216+
<path d="m8.25 4.5 7.5 7.5-7.5 7.5" />
217+
</svg>
218+
System Requirements
219+
</Button>
220+
</Heading>
221+
<Button>Click me</Button>
222+
</div>
223+
<DisclosurePanel>
224+
<p>Details about system requirements here.</p>
225+
</DisclosurePanel>
226+
</Disclosure>
227+
```
228+
205229
## Props
206230

207231
### Disclosure
Lines changed: 9 additions & 11 deletions
Loading

packages/react-aria-components/docs/DisclosureGroup.mdx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ import {DisclosureGroup, Disclosure, Button, DisclosurePanel, Heading} from 'rea
8282

8383
## Features
8484

85-
86-
Custom styled disclosure groups can be difficult to implement in an accessible way with the correct ARIA pattern. When implementing, you must manually ensure that the button and panel are semantically connected via ids for accessibility. `DisclosureGroup` helps with this and other accessibility features while allowing for custom styling.
85+
Accordions can be built by combing multiple disclosures built in HTML with the [&lt;details&gt;](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details) and [&lt;summary&gt;](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/summary) HTML element, but this can be difficult to style especially when adding adjacent interactive elements, like buttons, to the disclosure's heading. `Accordion` helps achieve accessible disclosures implemented with the correct ARIA pattern while making custom styling easy.
8786

8887
* **Accessible** - Disclosure group is exposed to assistive technology via ARIA
8988
* **Styleable** - Disclosures include builtin states for styling such as keyboard focus, disabled, and expanded states.
@@ -124,7 +123,7 @@ import {DisclosureGroup, Disclosure, Button, DisclosurePanel, Heading} from 'rea
124123

125124
### Default expanded
126125

127-
An uncontrolled DisclosureGroup can be expanded by default using the `defaultExpandedKeys` prop.
126+
An uncontrolled DisclosureGroup can be expanded by default using the `defaultExpandedKeys` prop. The `defaultExpandedKeys` must match the `id` on the disclosure(s) component that you wish to expand.
128127

129128
```tsx example export=true
130129
import type {DisclosureProps} from 'react-aria-components';
@@ -165,7 +164,7 @@ function MyDisclosure({title, children, ...props}: MyDisclosureProps) {
165164

166165
### Controlled expanded
167166

168-
A controlled DisclosureGroup can be expanded and collapsed using `expandedKeys` and `defaultExpandedKeys`
167+
A controlled DisclosureGroup can be expanded and collapsed using `expandedKeys` and `onExpandedChange`. The `expandedKeys` must match the `id` on the disclosure component(s) that you wish to expand.
169168

170169
```tsx example
171170
import {Key} from "@react-types/shared";
@@ -310,6 +309,8 @@ A `Button` can be targeted with the `.react-aria-Button` CSS selector, or by ove
310309

311310
A `DisclosurePanel` can be targeted with the `.react-aria-DisclosurePanel` CSS selector, or by overriding with a custom `className`.
312311

312+
<StateTable properties={docs.exports.DisclosurePanelRenderProps.properties} />
313+
313314
## Advanced Customization
314315

315316
### State

0 commit comments

Comments
 (0)