Skip to content
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

fix: Support hidden="until-found" in DisclosureGroup #7199

Merged
merged 13 commits into from
Oct 21, 2024
Prev Previous commit
Next Next commit
cleanup
  • Loading branch information
reidbarber committed Oct 16, 2024
commit f0457c575ce0bc023f31532191d0d5e809ccc052
18 changes: 6 additions & 12 deletions packages/@react-aria/disclosure/src/useDisclosure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,15 @@ export function useDisclosure(

let handleBeforeMatch = useCallback((e: Event) => {
if (groupState && id !== undefined) {
if (groupState.allowsMultipleExpanded) {
groupState.toggleKey(id);
} else {
groupState.setExpandedKeys(new Set([id]));
}
groupState.toggleKey(id);
} else {
state.toggle();
}
requestAnimationFrame(() => {
if (props.isExpanded) {
(e.target as Element).removeAttribute('hidden');
} else if (!props.isExpanded) {
(e.target as Element).setAttribute('hidden', 'until-found');
}
});
if (props.isExpanded) {
(e.target as Element).removeAttribute('hidden');
} else if (props.isExpanded === false) {
(e.target as Element).setAttribute('hidden', 'until-found');
}
}, [groupState, id, props.isExpanded, state]);

// @ts-ignore https://github.com/facebook/react/pull/24741
Expand Down
46 changes: 25 additions & 21 deletions packages/@react-spectrum/s2/stories/Accordion.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,29 +129,33 @@ WithDisabledDisclosure.parameters = {
}
};

function ControlledAccordion() {
function ControlledAccordion(props) {
let [expandedKeys, setExpandedKeys] = React.useState<Set<Key>>(new Set(['people']));
return (
<Accordion
onExpandedChange={setExpandedKeys}
expandedKeys={expandedKeys}>
<Disclosure id="files">
<DisclosureHeader>
Files
</DisclosureHeader>
<DisclosurePanel>
Files content
</DisclosurePanel>
</Disclosure>
<Disclosure id="people">
<DisclosureHeader>
People
</DisclosureHeader>
<DisclosurePanel>
<TextField label="Name" />
</DisclosurePanel>
</Disclosure>
</Accordion>
<div className={style({font: 'body', display: 'flex', flexDirection: 'column', gap: 8})}>
<Accordion
onExpandedChange={setExpandedKeys}
expandedKeys={expandedKeys}
{...props}>
<Disclosure id="files">
<DisclosureHeader>
reidbarber marked this conversation as resolved.
Show resolved Hide resolved
Files
</DisclosureHeader>
<DisclosurePanel>
Files content
</DisclosurePanel>
</Disclosure>
<Disclosure id="people">
<DisclosureHeader>
People
</DisclosureHeader>
<DisclosurePanel>
<TextField label="Name" />
</DisclosurePanel>
</Disclosure>
</Accordion>
<div>Expanded keys: {expandedKeys.size ? Array.from(expandedKeys).join(', ') : 'none'}</div>
</div>
);
}

Expand Down