Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
f8bdd1d
initialize accordion item
reidbarber Aug 22, 2024
2215a47
update yarn.lock
reidbarber Aug 22, 2024
33e0342
better hidden=until-found support
reidbarber Aug 22, 2024
a399d01
allow passing in panel ref
reidbarber Aug 22, 2024
aaa2015
comments
reidbarber Aug 22, 2024
0c20600
use RAC in v3 Accordion
reidbarber Aug 23, 2024
eeec6d2
Merge remote-tracking branch 'origin/main' into accordionitem
reidbarber Aug 27, 2024
1284b05
use disclosure hooks
reidbarber Aug 30, 2024
388f95d
initialize S2 Accordion
reidbarber Sep 4, 2024
11a3114
fix lint
reidbarber Sep 4, 2024
d3e30a0
add exports
reidbarber Sep 4, 2024
8400f19
lint
reidbarber Sep 5, 2024
dde08d2
Merge remote-tracking branch 'origin/main' into accordionitem
reidbarber Sep 5, 2024
a162de4
fix chevron color in dark mode
reidbarber Sep 5, 2024
8fa4881
fix version of @react-stately/accordion
reidbarber Sep 5, 2024
f0ec20f
keep aria-controls even when closed
reidbarber Sep 5, 2024
0ff7a6b
add isFocusVisibleWithin to AccordionPanel
reidbarber Sep 5, 2024
2329d85
fix panel height
reidbarber Sep 5, 2024
0d8d49b
fix versions
reidbarber Sep 5, 2024
b6335e1
Merge remote-tracking branch 'origin/main' into accordionitem
reidbarber Sep 5, 2024
1dc71d2
add to ts strict config
reidbarber Sep 5, 2024
c4c241a
change open/close to expand/collapse
reidbarber Sep 5, 2024
7a03c3b
move to disclosure package
reidbarber Sep 6, 2024
90eb2d4
fix chevron shrinking on wrapping header text
reidbarber Sep 6, 2024
afed83f
support for disabled in S2
reidbarber Sep 6, 2024
a5a4e49
clear ButtonContext in panel
reidbarber Sep 6, 2024
7bdb90b
update colors
reidbarber Sep 6, 2024
7e5ed31
lint
reidbarber Sep 6, 2024
0f5783e
fix v3 chevron not rotating
reidbarber Sep 10, 2024
f7b7b89
don't open via onbeforematch if disabled
reidbarber Sep 10, 2024
fc0c881
add disableTapHighlight
reidbarber Sep 10, 2024
d31b05a
open disclosure onKeyDown
reidbarber Sep 10, 2024
2a1a84a
add getAllowedOverrides
reidbarber Sep 10, 2024
5a50931
remove outer header component
reidbarber Sep 10, 2024
ee3a441
support level in S2 header
reidbarber Sep 10, 2024
a75ce7e
support level in v3 header
reidbarber Sep 10, 2024
e228d08
switch divider to use border
reidbarber Sep 10, 2024
c6778a9
simplify focus ring and padding styles
reidbarber Sep 11, 2024
e939056
update AccordionItem children types to enforce two React elements
reidbarber Sep 11, 2024
e4ff9bf
remove Header from RAC example
reidbarber Sep 11, 2024
8725ddc
scale font size
reidbarber Sep 11, 2024
851f5c2
Merge remote-tracking branch 'origin/main' into accordionitem
reidbarber Sep 11, 2024
707c6d7
update yarn.lock
reidbarber Sep 11, 2024
68f0241
fix keydown interaction + types
reidbarber Sep 11, 2024
dd699b8
support size, density, isQuiet, and isDisabled on individual items, b…
reidbarber Sep 11, 2024
f1a1386
enforce minWidth at item level
reidbarber Sep 11, 2024
6faa313
add isFocusVisibleWithin to item
reidbarber Sep 11, 2024
fa7d205
fix chevron in RTL
reidbarber Sep 11, 2024
cc64f8a
revert changes to @react-aria/accordion
reidbarber Sep 11, 2024
f845164
fix v3 chevron in RTL
reidbarber Sep 11, 2024
2df20ec
fix packages/imports
reidbarber Sep 11, 2024
f7fe88d
Merge remote-tracking branch 'origin/main' into accordionitem
reidbarber Sep 13, 2024
a1e5e7b
use 'group' as default role
reidbarber Sep 13, 2024
331e373
deprecate useAccordion and useAccordionItem
reidbarber Sep 13, 2024
02cd04e
update prop JSDocs
reidbarber Sep 13, 2024
520e6f9
update yarn.lock
reidbarber Sep 13, 2024
3e37be5
fix v3 refs
reidbarber Sep 13, 2024
3236221
add v3 tests back
reidbarber Sep 13, 2024
2a15a04
update imports
reidbarber Sep 13, 2024
88c1604
remove @ts-ignore
reidbarber Sep 16, 2024
c1010a1
Merge remote-tracking branch 'origin/main' into accordionitem
reidbarber Sep 16, 2024
ad6d1e7
Revert "remove @ts-ignore"
reidbarber Sep 16, 2024
41f22cb
fix stories
reidbarber Sep 16, 2024
760d7f8
fix context for individual accordion item
reidbarber Sep 16, 2024
8990783
fix defaults for individual item
reidbarber Sep 16, 2024
7768e8f
add story for individual item
reidbarber Sep 16, 2024
2c3c51f
make paddingTop and paddingBottom equal
reidbarber Sep 16, 2024
4a16e86
fix story
reidbarber Sep 16, 2024
8a46774
Merge remote-tracking branch 'origin/main' into accordionitem
reidbarber Sep 17, 2024
959108d
change triggerProps to buttonProps
reidbarber Sep 17, 2024
8f34766
add optional ref to useDisclosure
reidbarber Sep 17, 2024
6561566
add SSR check
reidbarber Sep 17, 2024
c2696be
use useEvent to add beforematch listener
reidbarber Sep 18, 2024
8caedac
rename AccordionGroup to Accordion
reidbarber Sep 18, 2024
809f5c4
rename Disclosure to AccordionItem
reidbarber Sep 18, 2024
c97e891
rename AccordionPanel to DisclosurePanel
reidbarber Sep 18, 2024
edd5dc7
more renaming
reidbarber Sep 18, 2024
fe47ae6
rename RAC Accordion file to Disclosure
reidbarber Sep 18, 2024
052b302
comment updates
reidbarber Sep 18, 2024
1780762
package.json updates
reidbarber Sep 18, 2024
01d2219
yarn.lock
reidbarber Sep 18, 2024
337ef1e
update render props
reidbarber Sep 18, 2024
486e631
add DEFAULT_SLOT
reidbarber Sep 18, 2024
e17434d
use fontRelative for border radius
reidbarber Sep 18, 2024
880ef23
style macro updates
reidbarber Sep 18, 2024
7b4439c
Merge remote-tracking branch 'origin/main' into accordionitem
reidbarber Sep 18, 2024
7c6c112
lint
reidbarber Sep 18, 2024
ef0d5ee
update codemod
reidbarber Sep 18, 2024
8fdb582
fix tests
reidbarber Sep 18, 2024
9abc6f3
use control for borderRadius
reidbarber Sep 18, 2024
f061a90
use ref instead of contentRef prop
reidbarber Sep 18, 2024
a5e948d
use values on grid
reidbarber Sep 18, 2024
17f7f08
lint
reidbarber Sep 18, 2024
ab629cc
yarn.lock
reidbarber Sep 18, 2024
63f5d16
fix refs
reidbarber Sep 18, 2024
c5f6b61
lint
reidbarber Sep 18, 2024
37dc1ff
revert renames in useAccordion
reidbarber Sep 19, 2024
5075dcf
move Disclosure to its own file
reidbarber Sep 19, 2024
195ed2b
reanme RAC Accordion stories to Disclosure
reidbarber Sep 19, 2024
2bf5b92
fix styles prop type
reidbarber Sep 19, 2024
53f4e0b
fix imports
reidbarber Sep 19, 2024
40aed9a
update styles type on Disclosure
reidbarber Sep 19, 2024
d58b5e4
add dedicated story for S2 Disclosure
reidbarber Sep 19, 2024
750431a
Slight fixes
devongovett Sep 19, 2024
cafacea
Center baseline and simplify padding by changing the minHeight instead
devongovett Sep 19, 2024
39e772c
fix import
devongovett Sep 19, 2024
a045812
update lockfile
devongovett Sep 19, 2024
3aeb8db
Merge branch 'main' into accordionitem
reidbarber Sep 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ governing permissions and limitations under the License.
.spectrum-Accordion-itemIndicator {
display: block;

padding-inline-start: var(--spectrum-accordion-icon-spacing);
padding-inline-start: var(--spectrum-accordion-icon-gap);
padding-inline-end: var(--spectrum-accordion-icon-gap);

transition: transform ease var(--spectrum-global-animation-duration-100);
Expand Down Expand Up @@ -66,7 +66,7 @@ governing permissions and limitations under the License.
box-sizing: border-box;
/* left padding takes into account the icon's size as well as the focus state's left border */
padding-block: var(--spectrum-accordion-item-title-padding-y);
padding-inline-start: 2px;
padding-inline-start: var(--spectrum-accordion-icon-gap);
padding-inline-end: var(--spectrum-accordion-item-padding);
margin: 0;

Expand Down Expand Up @@ -111,7 +111,7 @@ governing permissions and limitations under the License.
}

.spectrum-Accordion-item {
&.is-open {
&.is-expanded {
> .spectrum-Accordion-itemHeading {
> .spectrum-Accordion-itemHeader {
> .spectrum-Accordion-itemIndicator {
Expand All @@ -126,7 +126,7 @@ governing permissions and limitations under the License.
}

> .spectrum-Accordion-itemHeader::after {
/* No bottom border when open, so be less tall */
/* No bottom border when expanded, so be less tall */
height: var(--spectrum-accordion-item-height-actual);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ governing permissions and limitations under the License.
}

.spectrum-Accordion-item {
&.is-open {
&.is-expanded {
.spectrum-Accordion-itemHeader {
&:hover {
background-color: transparent;
Expand Down
6 changes: 6 additions & 0 deletions packages/@react-aria/accordion/src/useAccordion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export interface AccordionItemAria {
regionProps: DOMAttributes
}

/**
* @deprecated Use useDisclosure from `@react-aria/disclosure` instead.
*/
export function useAccordionItem<T>(props: AccordionItemAriaProps<T>, state: TreeState<T>, ref: RefObject<HTMLButtonElement | null>): AccordionItemAria {
let {item} = props;
let buttonId = useId();
Expand Down Expand Up @@ -65,6 +68,9 @@ export function useAccordionItem<T>(props: AccordionItemAriaProps<T>, state: Tre
};
}

/**
* @deprecated Use useDisclosure from `@react-aria/disclosure` instead.
*/
export function useAccordion<T>(props: AriaAccordionProps<T>, state: TreeState<T>, ref: RefObject<HTMLDivElement | null>): AccordionAria {
let {listProps} = useSelectableList({
...props,
Expand Down
3 changes: 3 additions & 0 deletions packages/@react-aria/disclosure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @react-aria/disclosure

This package is part of [react-spectrum](https://github.com/adobe/react-spectrum). See the repo for more details.
13 changes: 13 additions & 0 deletions packages/@react-aria/disclosure/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

export * from './src';
43 changes: 43 additions & 0 deletions packages/@react-aria/disclosure/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "@react-aria/disclosure",
"version": "3.0.0-alpha.0",
"description": "Spectrum UI components in React",
"license": "Apache-2.0",
"main": "dist/main.js",
"module": "dist/module.js",
"exports": {
"types": "./dist/types.d.ts",
"import": "./dist/import.mjs",
"require": "./dist/main.js"
},
"types": "dist/types.d.ts",
"source": "src/index.ts",
"files": [
"dist",
"src"
],
"sideEffects": false,
"repository": {
"type": "git",
"url": "https://github.com/adobe/react-spectrum"
},
"dependencies": {
"@react-aria/button": "^3.9.8",
"@react-aria/selection": "^3.19.3",
"@react-aria/ssr": "^3.9.5",
"@react-aria/utils": "^3.25.2",
"@react-stately/disclosure": "3.0.0-alpha.0",
"@react-stately/toggle": "^3.7.7",
"@react-stately/tree": "^3.8.4",
"@react-types/button": "^3.9.6",
"@react-types/shared": "^3.24.1",
"@swc/helpers": "^0.5.0"
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0",
"react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
},
"publishConfig": {
"access": "public"
}
}
13 changes: 13 additions & 0 deletions packages/@react-aria/disclosure/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
export {useDisclosure} from './useDisclosure';
export type {DisclosureAria, AriaDisclosureProps} from './useDisclosure';
93 changes: 93 additions & 0 deletions packages/@react-aria/disclosure/src/useDisclosure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

import {AriaButtonProps} from '@react-types/button';
import {DisclosureState} from '@react-stately/disclosure';
import {HTMLAttributes, RefObject, useEffect} from 'react';
import {useEvent, useId} from '@react-aria/utils';
import {useIsSSR} from '@react-aria/ssr';

export interface AriaDisclosureProps {
/** Whether the disclosure is disabled. */
isDisabled?: boolean,
/** Handler that is called when the disclosure's expanded state changes. */
onExpandedChange?: (isExpanded: boolean) => void,
/** Whether the disclosure is expanded (controlled). */
isExpanded?: boolean,
/** Whether the disclosure is expanded by default (uncontrolled). */
defaultExpanded?: boolean
}

export interface DisclosureAria {
/** Props for the disclosure button. */
buttonProps: AriaButtonProps,
/** Props for the content element. */
contentProps: HTMLAttributes<HTMLElement>
}

/**
* Provides the behavior and accessibility implementation for a disclosure component.
* @param props - Props for the disclosure.
* @param state - State for the disclosure, as returned by `useDisclosureState`.
* @param ref - A ref for the disclosure content.
*/
export function useDisclosure(props: AriaDisclosureProps, state: DisclosureState, ref?: RefObject<Element | null>): DisclosureAria {
let {
isDisabled
} = props;
let triggerId = useId();
let contentId = useId();
let isControlled = props.isExpanded !== undefined;
let isSSR = useIsSSR();
let supportsBeforeMatch = !isSSR && 'onbeforematch' in document.body;

// @ts-ignore https://github.com/facebook/react/pull/24741
useEvent(ref, 'beforematch', supportsBeforeMatch ? () => state.expand() : null);

useEffect(() => {
// Until React supports hidden="until-found": https://github.com/facebook/react/pull/24741
if (supportsBeforeMatch && ref?.current && !isControlled && !isDisabled) {
if (state.isExpanded) {
// @ts-ignore
ref.current.hidden = undefined;
} else {
// @ts-ignore
ref.current.hidden = 'until-found';
}
}
}, [isControlled, ref, props.isExpanded, state, supportsBeforeMatch, isDisabled]);

return {
buttonProps: {
id: triggerId,
'aria-expanded': state.isExpanded,
'aria-controls': contentId,
onPress: (e) => {
if (e.pointerType !== 'keyboard') {
state.toggle();
}
},
isDisabled,
onKeyDown(e) {
if (!isDisabled && (e.key === 'Enter' || e.key === ' ')) {
e.preventDefault();
state.toggle();
}
}
},
contentProps: {
id: contentId,
'aria-labelledby': triggerId,
hidden: (!supportsBeforeMatch || isControlled) ? !state.isExpanded : true
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@
*/

import {Meta} from '@storybook/react';
import {SpectrumAccordionProps} from '@react-types/accordion';
import {SpectrumAccordionProps} from '../src/Accordion';
import {Template} from '../chromatic/Accordion.stories';

const meta: Meta<SpectrumAccordionProps<object>> = {
const meta: Meta<SpectrumAccordionProps> = {
title: 'Accordion'
};

export default meta;

export const Default = {
render: Template,
args: {defaultExpandedKeys: ['shared'], disabledKeys: ['last']}
render: Template
};
50 changes: 28 additions & 22 deletions packages/@react-spectrum/accordion/chromatic/Accordion.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,49 @@
* governing permissions and limitations under the License.
*/

import {Accordion, Item} from '../';
import {Accordion, Disclosure, DisclosureHeader, DisclosurePanel} from '../';
import {Meta} from '@storybook/react';
import React from 'react';
import {SpectrumAccordionProps} from '@react-types/accordion';

const meta: Meta<SpectrumAccordionProps<object>> = {
const meta: Meta = {
title: 'Accordion',
component: Accordion,
component: Disclosure,
excludeStories: ['Template']
};

export default meta;

export const Template = (args) => (
<Accordion {...args}>
<Item key="files" title="Your files">
files
</Item>
<Item key="shared" title="Shared with you">
shared
</Item>
<Item key="last" title="Last item">
last
</Item>
<Disclosure key="files">
<DisclosureHeader>
Your files
</DisclosureHeader>
<DisclosurePanel>
files
</DisclosurePanel>
</Disclosure>
<Disclosure key="shared">
<DisclosureHeader>
Shared with you
</DisclosureHeader>
<DisclosurePanel>
shared
</DisclosurePanel>
</Disclosure>
<Disclosure key="last">
<DisclosureHeader>
Last item
</DisclosureHeader>
<DisclosurePanel>
last
</DisclosurePanel>
</Disclosure>
</Accordion>
);

export const Default = {
render: Template
};

export const ExpandedKeys = {
render: Template,
args: {defaultExpandedKeys: ['shared']}
};

export const DisabledKeys = {
render: Template,
args: {disabledKeys: ['shared']}
};
// TODO: more stories
4 changes: 2 additions & 2 deletions packages/@react-spectrum/accordion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
"@react-spectrum/utils": "^3.11.9",
"@react-stately/collections": "^3.10.9",
"@react-stately/tree": "^3.8.3",
"@react-types/accordion": "3.0.0-alpha.23",
"@react-types/shared": "^3.24.1",
"@spectrum-icons/ui": "^3.6.9",
"@swc/helpers": "^0.5.0"
"@swc/helpers": "^0.5.0",
"react-aria-components": "^1.3.3"
},
"devDependencies": {
"@adobe/spectrum-css-temp": "3.0.0-alpha.1"
Expand Down
Loading