-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Accordion #6931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Accordion #6931
Changes from all commits
Commits
Show all changes
108 commits
Select commit
Hold shift + click to select a range
f8bdd1d
initialize accordion item
reidbarber 2215a47
update yarn.lock
reidbarber 33e0342
better hidden=until-found support
reidbarber a399d01
allow passing in panel ref
reidbarber aaa2015
comments
reidbarber 0c20600
use RAC in v3 Accordion
reidbarber eeec6d2
Merge remote-tracking branch 'origin/main' into accordionitem
reidbarber 1284b05
use disclosure hooks
reidbarber 388f95d
initialize S2 Accordion
reidbarber 11a3114
fix lint
reidbarber d3e30a0
add exports
reidbarber 8400f19
lint
reidbarber dde08d2
Merge remote-tracking branch 'origin/main' into accordionitem
reidbarber a162de4
fix chevron color in dark mode
reidbarber 8fa4881
fix version of @react-stately/accordion
reidbarber f0ec20f
keep aria-controls even when closed
reidbarber 0ff7a6b
add isFocusVisibleWithin to AccordionPanel
reidbarber 2329d85
fix panel height
reidbarber 0d8d49b
fix versions
reidbarber b6335e1
Merge remote-tracking branch 'origin/main' into accordionitem
reidbarber 1dc71d2
add to ts strict config
reidbarber c4c241a
change open/close to expand/collapse
reidbarber 7a03c3b
move to disclosure package
reidbarber 90eb2d4
fix chevron shrinking on wrapping header text
reidbarber afed83f
support for disabled in S2
reidbarber a5a4e49
clear ButtonContext in panel
reidbarber 7bdb90b
update colors
reidbarber 7e5ed31
lint
reidbarber 0f5783e
fix v3 chevron not rotating
reidbarber f7b7b89
don't open via onbeforematch if disabled
reidbarber fc0c881
add disableTapHighlight
reidbarber d31b05a
open disclosure onKeyDown
reidbarber 2a1a84a
add getAllowedOverrides
reidbarber 5a50931
remove outer header component
reidbarber ee3a441
support level in S2 header
reidbarber a75ce7e
support level in v3 header
reidbarber e228d08
switch divider to use border
reidbarber c6778a9
simplify focus ring and padding styles
reidbarber e939056
update AccordionItem children types to enforce two React elements
reidbarber e4ff9bf
remove Header from RAC example
reidbarber 8725ddc
scale font size
reidbarber 851f5c2
Merge remote-tracking branch 'origin/main' into accordionitem
reidbarber 707c6d7
update yarn.lock
reidbarber 68f0241
fix keydown interaction + types
reidbarber dd699b8
support size, density, isQuiet, and isDisabled on individual items, b…
reidbarber f1a1386
enforce minWidth at item level
reidbarber 6faa313
add isFocusVisibleWithin to item
reidbarber fa7d205
fix chevron in RTL
reidbarber cc64f8a
revert changes to @react-aria/accordion
reidbarber f845164
fix v3 chevron in RTL
reidbarber 2df20ec
fix packages/imports
reidbarber f7fe88d
Merge remote-tracking branch 'origin/main' into accordionitem
reidbarber a1e5e7b
use 'group' as default role
reidbarber 331e373
deprecate useAccordion and useAccordionItem
reidbarber 02cd04e
update prop JSDocs
reidbarber 520e6f9
update yarn.lock
reidbarber 3e37be5
fix v3 refs
reidbarber 3236221
add v3 tests back
reidbarber 2a15a04
update imports
reidbarber 88c1604
remove @ts-ignore
reidbarber c1010a1
Merge remote-tracking branch 'origin/main' into accordionitem
reidbarber ad6d1e7
Revert "remove @ts-ignore"
reidbarber 41f22cb
fix stories
reidbarber 760d7f8
fix context for individual accordion item
reidbarber 8990783
fix defaults for individual item
reidbarber 7768e8f
add story for individual item
reidbarber 2c3c51f
make paddingTop and paddingBottom equal
reidbarber 4a16e86
fix story
reidbarber 8a46774
Merge remote-tracking branch 'origin/main' into accordionitem
reidbarber 959108d
change triggerProps to buttonProps
reidbarber 8f34766
add optional ref to useDisclosure
reidbarber 6561566
add SSR check
reidbarber c2696be
use useEvent to add beforematch listener
reidbarber 8caedac
rename AccordionGroup to Accordion
reidbarber 809f5c4
rename Disclosure to AccordionItem
reidbarber c97e891
rename AccordionPanel to DisclosurePanel
reidbarber edd5dc7
more renaming
reidbarber fe47ae6
rename RAC Accordion file to Disclosure
reidbarber 052b302
comment updates
reidbarber 1780762
package.json updates
reidbarber 01d2219
yarn.lock
reidbarber 337ef1e
update render props
reidbarber 486e631
add DEFAULT_SLOT
reidbarber e17434d
use fontRelative for border radius
reidbarber 880ef23
style macro updates
reidbarber 7b4439c
Merge remote-tracking branch 'origin/main' into accordionitem
reidbarber 7c6c112
lint
reidbarber ef0d5ee
update codemod
reidbarber 8fdb582
fix tests
reidbarber 9abc6f3
use control for borderRadius
reidbarber f061a90
use ref instead of contentRef prop
reidbarber a5e948d
use values on grid
reidbarber 17f7f08
lint
reidbarber ab629cc
yarn.lock
reidbarber 63f5d16
fix refs
reidbarber c5f6b61
lint
reidbarber 37dc1ff
revert renames in useAccordion
reidbarber 5075dcf
move Disclosure to its own file
reidbarber 195ed2b
reanme RAC Accordion stories to Disclosure
reidbarber 2bf5b92
fix styles prop type
reidbarber 53f4e0b
fix imports
reidbarber 40aed9a
update styles type on Disclosure
reidbarber d58b5e4
add dedicated story for S2 Disclosure
reidbarber 750431a
Slight fixes
devongovett cafacea
Center baseline and simplify padding by changing the minHeight instead
devongovett 39e772c
fix import
devongovett a045812
update lockfile
devongovett 3aeb8db
Merge branch 'main' into accordionitem
reidbarber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.