Skip to content

Commit 4f85a35

Browse files
authored
fix: Accordion/Disclosure release prep (#7216)
* RAC Disclosure SSR tests * tests for nested disclosures and interactive adjacent elements * DisclosurePanel: add DOMProps and render props type/table * update v3 stories and chromatic * update v3 Accordion deps * add v3 Accordion SSR test * update DisclosureGroupProps type to remove collection in jsdoc * more v3 accordion tests * yarn.lock * lint * add isQuiet to v3 Accordion/Disclosure * add focus ring style * update stories/chromatic * lint * remove active outline * lint * add isQuiet to v3 docs
1 parent b887497 commit 4f85a35

File tree

19 files changed

+519
-61
lines changed

19 files changed

+519
-61
lines changed

packages/@adobe/spectrum-css-temp/components/accordion/index.css

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ governing permissions and limitations under the License.
2020

2121
--spectrum-accordion-item-title-padding-y: var(--spectrum-global-dimension-size-150);
2222
--spectrum-accordion-item-line-height: 1.3;
23+
24+
--spectrum-accordion-item-focus-ring-color: var(--spectrum-alias-focus-color);
2325
}
2426

2527
.spectrum-Accordion {
@@ -51,13 +53,18 @@ governing permissions and limitations under the License.
5153
&:first-of-type {
5254
border-top: var(--spectrum-accordion-item-border-size) solid transparent;
5355
}
56+
57+
&.spectrum-Accordion-item--quiet, &.spectrum-Accordion-item--quiet:first-of-type {
58+
border-color: transparent;
59+
}
5460
}
5561

5662
.spectrum-Accordion-itemHeading {
5763
margin: 0;
5864
}
5965

6066
.spectrum-Accordion-itemHeader {
67+
outline: none;
6168
position: relative;
6269

6370
display: flex;
@@ -85,24 +92,16 @@ governing permissions and limitations under the License.
8592
-moz-appearance: none;
8693
appearance: none;
8794
background-color: inherit;
88-
border: 0;
8995
font-family: inherit;
9096
text-align: start;
9197
width: 100%;
98+
border-style: solid;
99+
border-color: transparent;
100+
border-radius: var(--spectrum-global-dimension-static-size-100);
92101

93-
&:focus {
94-
outline: none;
95-
96-
&::after {
97-
content: '';
98-
99-
position: absolute;
100-
inset-inline-start: 0;
101-
top: calc(var(--spectrum-accordion-item-border-size) * -1);
102-
bottom: calc(var(--spectrum-accordion-item-border-size) * -1);
103-
104-
width: var(--spectrum-accordion-item-border-size-key-focus);
105-
}
102+
&.focus-ring {
103+
outline: solid 2px var(--spectrum-accordion-item-focus-ring-color);
104+
outline-offset: -4px;
106105
}
107106
}
108107

packages/@adobe/spectrum-css-temp/components/accordion/skin.css

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ governing permissions and limitations under the License.
3030

3131
background-color: var(--spectrum-accordion-background-color-hover);
3232
}
33-
34-
&:focus-visible {
35-
&:after {
36-
background-color: var(--spectrum-accordion-border-left-color-key-focus);
37-
}
38-
}
3933
}
4034

4135
.spectrum-Accordion-item {

packages/@react-spectrum/accordion/chromatic/Accordion.stories.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const Default = {
5555
render: Template
5656
};
5757

58-
export const WithExpanedKeys = {
58+
export const WithExpandedKeys = {
5959
render: Template,
6060
args: {defaultExpandedKeys: ['shared']}
6161
};
@@ -90,4 +90,12 @@ export const WithDisabledDisclosure = {
9090
</Accordion>)
9191
};
9292

93-
// TODO: more stories
93+
export const Disabled = {
94+
render: Template,
95+
args: {isDisabled: true}
96+
};
97+
98+
export const Quiet = {
99+
render: Template,
100+
args: {isQuiet: true}
101+
};
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2024 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import {Disclosure, DisclosureHeader, DisclosurePanel} from '../';
14+
import {Meta} from '@storybook/react';
15+
import React from 'react';
16+
17+
const meta: Meta = {
18+
title: 'Accordion',
19+
component: Disclosure,
20+
excludeStories: ['Template']
21+
};
22+
23+
export default meta;
24+
25+
export const Template = (args) => (
26+
<Disclosure {...args}>
27+
<DisclosureHeader>
28+
Your files
29+
</DisclosureHeader>
30+
<DisclosurePanel>
31+
files
32+
</DisclosurePanel>
33+
</Disclosure>
34+
);
35+
36+
export const Default = {
37+
render: Template
38+
};
39+
40+
export const Disabled = {
41+
render: Template,
42+
args: {isDisabled: true}
43+
};
44+
45+
export const Quiet = {
46+
render: Template,
47+
args: {isQuiet: true}
48+
};

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,22 @@ By default, only one disclosure will be expanded at a time. To expand multiple d
134134
</Disclosure>
135135
</Accordion>
136136
```
137+
138+
### Quiet
139+
140+
```tsx example
141+
<Accordion isQuiet>
142+
<Disclosure id="personal">
143+
<DisclosureHeader>Personal Information</DisclosureHeader>
144+
<DisclosurePanel>
145+
<p>Personal information form here.</p>
146+
</DisclosurePanel>
147+
</Disclosure>
148+
<Disclosure id="billing">
149+
<DisclosureHeader>Billing Address</DisclosureHeader>
150+
<DisclosurePanel>
151+
<p>Billing address form here.</p>
152+
</DisclosurePanel>
153+
</Disclosure>
154+
</Accordion>
155+
```

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,14 @@ function ControlledExpansion() {
112112
</DisclosurePanel>
113113
</Disclosure>
114114
```
115+
116+
### Quiet
117+
118+
```tsx example
119+
<Disclosure isQuiet>
120+
<DisclosureHeader>System Requirements</DisclosureHeader>
121+
<DisclosurePanel>
122+
<p>Details about system requirements here.</p>
123+
</DisclosurePanel>
124+
</Disclosure>
125+
```

packages/@react-spectrum/accordion/package.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,8 @@
3636
"url": "https://github.com/adobe/react-spectrum"
3737
},
3838
"dependencies": {
39-
"@react-aria/accordion": "3.0.0-alpha.35",
40-
"@react-aria/focus": "^3.18.4",
4139
"@react-aria/i18n": "^3.12.3",
42-
"@react-aria/interactions": "^3.22.4",
43-
"@react-aria/utils": "^3.25.3",
4440
"@react-spectrum/utils": "^3.11.11",
45-
"@react-stately/collections": "^3.11.0",
46-
"@react-stately/tree": "^3.8.5",
4741
"@react-types/shared": "^3.25.0",
4842
"@spectrum-icons/ui": "^3.6.10",
4943
"@swc/helpers": "^0.5.0",

packages/@react-spectrum/accordion/src/Accordion.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,54 @@ import {Button, UNSTABLE_DisclosureGroup as DisclosureGroup, DisclosureGroupProp
1515
import ChevronLeftMedium from '@spectrum-icons/ui/ChevronLeftMedium';
1616
import ChevronRightMedium from '@spectrum-icons/ui/ChevronRightMedium';
1717
import {classNames, useDOMRef, useStyleProps} from '@react-spectrum/utils';
18-
import React, {forwardRef} from 'react';
18+
import React, {createContext, forwardRef} from 'react';
1919
import styles from '@adobe/spectrum-css-temp/components/accordion/vars.css';
2020
import {useLocale} from '@react-aria/i18n';
2121
import {useProviderProps} from '@react-spectrum/provider';
2222

2323
export interface SpectrumAccordionProps extends Omit<DisclosureGroupProps, 'className' | 'style' | 'children'>, StyleProps, DOMProps {
24+
/** Whether the Accordion should be displayed with a quiet style. */
25+
isQuiet?: boolean,
2426
/** The disclosures within the accordion group. */
2527
children: React.ReactNode
2628
}
2729

30+
const InternalAccordionContext = createContext<{isQuiet: boolean} | null>(null);
31+
2832
function Accordion(props: SpectrumAccordionProps, ref: DOMRef<HTMLDivElement>) {
2933
props = useProviderProps(props);
3034
let {styleProps} = useStyleProps(props);
3135
let domRef = useDOMRef(ref);
3236
return (
33-
<DisclosureGroup
34-
{...props}
35-
{...styleProps}
36-
ref={domRef}
37-
className={classNames(styles, 'spectrum-Accordion', styleProps.className)}>
38-
{props.children}
39-
</DisclosureGroup>
37+
<InternalAccordionContext.Provider value={{isQuiet: props.isQuiet || false}}>
38+
<DisclosureGroup
39+
{...props}
40+
{...styleProps}
41+
ref={domRef}
42+
className={classNames(styles, 'spectrum-Accordion', styleProps.className)}>
43+
{props.children}
44+
</DisclosureGroup>
45+
</InternalAccordionContext.Provider>
4046
);
4147
}
4248

4349
export interface SpectrumDisclosureProps extends Omit<DisclosureProps, 'className' | 'style' | 'children'>, AriaLabelingProps {
50+
/** Whether the Disclosure should be displayed with a quiet style. */
51+
isQuiet?: boolean,
4452
/** The contents of the disclosure. The first child should be the header, and the second child should be the panel. */
4553
children: React.ReactNode
4654
}
4755

4856
function Disclosure(props: SpectrumDisclosureProps, ref: DOMRef<HTMLDivElement>) {
4957
props = useProviderProps(props);
5058
let domRef = useDOMRef(ref);
59+
let accordionContext = React.useContext(InternalAccordionContext)!;
5160
return (
5261
<RACDisclosure
5362
{...props}
5463
ref={domRef}
5564
className={({isExpanded, isDisabled}) => classNames(styles, 'spectrum-Accordion-item', {
65+
'spectrum-Accordion-item--quiet': accordionContext?.isQuiet ?? props.isQuiet,
5666
'is-expanded': isExpanded,
5767
'is-disabled': isDisabled
5868
})}>

packages/@react-spectrum/accordion/stories/Accordion.stories.tsx

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,25 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import {Accordion, Disclosure, DisclosureHeader, DisclosurePanel} from '../src';
14-
import {ComponentMeta, ComponentStoryObj} from '@storybook/react';
13+
import {Accordion, Disclosure, DisclosureHeader, DisclosurePanel, SpectrumAccordionProps} from '../src';
14+
import {Meta, StoryObj} from '@storybook/react';
1515
import React from 'react';
1616

17-
export default {
17+
const meta: Meta<SpectrumAccordionProps> = {
1818
title: 'Accordion',
1919
component: Accordion,
20-
argTypes: {}
21-
} as ComponentMeta<typeof Accordion>;
20+
argTypes: {
21+
isDisabled: {
22+
control: 'boolean'
23+
},
24+
isQuiet: {
25+
control: 'boolean'
26+
}
27+
}
28+
};
2229

23-
export type AccordionStory = ComponentStoryObj<typeof Accordion>;
30+
export default meta;
31+
type AccordionStory = StoryObj<typeof Accordion>;
2432

2533
export const Default: AccordionStory = {
2634
render: (args) => (
@@ -44,3 +52,39 @@ export const Default: AccordionStory = {
4452
</Accordion>
4553
)
4654
};
55+
56+
export const WithExpandedKeys: AccordionStory = {
57+
...Default,
58+
args: {defaultExpandedKeys: ['files']}
59+
};
60+
61+
export const WithDisabledDisclosure: AccordionStory = {
62+
render: (args) => (
63+
<Accordion {...args}>
64+
<Disclosure id="files">
65+
<DisclosureHeader>
66+
Your files
67+
</DisclosureHeader>
68+
<DisclosurePanel>
69+
files
70+
</DisclosurePanel>
71+
</Disclosure>
72+
<Disclosure id="shared">
73+
<DisclosureHeader>
74+
Shared with you
75+
</DisclosureHeader>
76+
<DisclosurePanel>
77+
shared
78+
</DisclosurePanel>
79+
</Disclosure>
80+
<Disclosure id="last" isDisabled>
81+
<DisclosureHeader>
82+
Last item
83+
</DisclosureHeader>
84+
<DisclosurePanel>
85+
last
86+
</DisclosurePanel>
87+
</Disclosure>
88+
</Accordion>
89+
)
90+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2024 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import {Disclosure, DisclosureHeader, DisclosurePanel, SpectrumDisclosureProps} from '../src';
14+
import {Meta, StoryObj} from '@storybook/react';
15+
import React from 'react';
16+
17+
const meta: Meta<SpectrumDisclosureProps> = {
18+
title: 'Disclosure',
19+
component: Disclosure,
20+
argTypes: {
21+
isDisabled: {
22+
control: 'boolean'
23+
},
24+
isQuiet: {
25+
control: 'boolean'
26+
}
27+
}
28+
};
29+
30+
export default meta;
31+
type DisclosureStory = StoryObj<typeof Disclosure>;
32+
33+
export const Default: DisclosureStory = {
34+
render: (args) => (
35+
<Disclosure {...args}>
36+
<DisclosureHeader>
37+
Files
38+
</DisclosureHeader>
39+
<DisclosurePanel>
40+
<p>Files content</p>
41+
</DisclosurePanel>
42+
</Disclosure>
43+
)
44+
};

0 commit comments

Comments
 (0)