@@ -13,6 +13,19 @@ import {
13
13
AccordionItemState ,
14
14
} from '../../src' ;
15
15
16
+ import Code from './components/Code' ;
17
+
18
+ // tslint:disable-next-line no-import-side-effect ordered-imports
19
+ import {
20
+ ExampleDefault ,
21
+ ExampleAllowMultipleExpanded ,
22
+ ExampleAllowZeroExpanded ,
23
+ ExamplePreExpanded ,
24
+ ExampleOnChange ,
25
+ ExampleAccordionItemState ,
26
+ ExampleDangerouslySetExpanded ,
27
+ } from './code-examples' ;
28
+
16
29
// tslint:disable-next-line no-import-side-effect
17
30
import './main.css' ;
18
31
@@ -28,8 +41,8 @@ const App = (): JSX.Element => (
28
41
React Component for creating an 'Accordion' that adheres to the{ ' ' }
29
42
< a
30
43
href = "https://www.w3.org/TR/wai-aria-practices-1.1/#accordion"
31
- target = "_BLANK "
32
- rel = "noreferrer, nofollow"
44
+ target = "_blank "
45
+ rel = "noreferrer nofollow"
33
46
>
34
47
WAI ARIA spec
35
48
</ a > { ' ' }
@@ -56,6 +69,8 @@ const App = (): JSX.Element => (
56
69
) ) }
57
70
</ Accordion >
58
71
72
+ < Code code = { ExampleDefault } />
73
+
59
74
< h2 className = "u-margin-top" > Expanding multiple items at once</ h2 >
60
75
61
76
< p >
@@ -77,6 +92,8 @@ const App = (): JSX.Element => (
77
92
) ) }
78
93
</ Accordion >
79
94
95
+ < Code code = { ExampleAllowMultipleExpanded } />
96
+
80
97
< h2 className = "u-margin-top" > Collapsing the last expanded item</ h2 >
81
98
82
99
< p >
@@ -98,6 +115,8 @@ const App = (): JSX.Element => (
98
115
) ) }
99
116
</ Accordion >
100
117
118
+ < Code code = { ExampleAllowZeroExpanded } />
119
+
101
120
< h2 className = "u-margin-top" > Pre-expanded items</ h2 >
102
121
103
122
< p >
@@ -114,8 +133,8 @@ const App = (): JSX.Element => (
114
133
< Accordion preExpanded = { [ placeholders [ 0 ] . uuid ] } >
115
134
{ placeholders . map ( ( placeholder : Placeholder ) => (
116
135
< AccordionItem
117
- key = { placeholder . heading }
118
- uuid = { placeholder . uuid }
136
+ key = { placeholder . heading }
137
+ uuid = { placeholder . uuid }
119
138
>
120
139
< AccordionItemHeading >
121
140
< AccordionItemButton >
@@ -127,6 +146,8 @@ const App = (): JSX.Element => (
127
146
) ) }
128
147
</ Accordion >
129
148
149
+ < Code code = { ExamplePreExpanded } />
150
+
130
151
< h2 className = "u-margin-top" > Informative onChange</ h2 >
131
152
132
153
< p >
@@ -149,8 +170,8 @@ const App = (): JSX.Element => (
149
170
>
150
171
{ placeholders . map ( ( placeholder : Placeholder ) => (
151
172
< AccordionItem
152
- key = { placeholder . heading }
153
- uuid = { placeholder . uuid }
173
+ key = { placeholder . heading }
174
+ uuid = { placeholder . uuid }
154
175
>
155
176
< AccordionItemHeading >
156
177
< AccordionItemButton >
@@ -161,6 +182,8 @@ const App = (): JSX.Element => (
161
182
</ AccordionItem >
162
183
) ) }
163
184
</ Accordion >
185
+
186
+ < Code code = { ExampleOnChange } />
164
187
165
188
< h2 className = "u-margin-top" > Accessing Item State</ h2 >
166
189
@@ -194,17 +217,17 @@ const App = (): JSX.Element => (
194
217
) ) }
195
218
</ Accordion >
196
219
220
+ < Code code = { ExampleAccordionItemState } />
221
+
197
222
< h2 className = "u-margin-top" > Manual state</ h2 >
198
223
199
224
< p >
200
- When you use the < strong > onChange </ strong > prop, you can get
201
- feedback about which items are expanded.
225
+ When you use the < strong > dangerouslySetExpanded </ strong > prop, you can
226
+ manually override whether an < strong > AccordionItem </ strong > is expanded.
202
227
</ p >
203
228
204
229
< p >
205
- In this example, we are simply logging the uuids of the expanded
206
- items to the console. Have a click around then check your console to
207
- see this in action.
230
+ < strong > Warning: This can impact accessibility negatively.</ strong >
208
231
</ p >
209
232
210
233
< Accordion >
@@ -230,6 +253,8 @@ const App = (): JSX.Element => (
230
253
) ;
231
254
} ) }
232
255
</ Accordion >
256
+
257
+ < Code code = { ExampleDangerouslySetExpanded } />
233
258
</ >
234
259
) ;
235
260
0 commit comments