Skip to content

Commit abe2e95

Browse files
authored
fix: Dont display disclosure panel content if isDisabled and isExpanded=false (#8893)
* fix: Dont display disclosure panel content if isDisabled and isExpanded=false * make sure disabled disclosures arent expanded if provided isExpanded this retains the old behavior on main
1 parent f1a021e commit abe2e95

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

packages/@react-aria/disclosure/src/useDisclosure.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export function useDisclosure(props: AriaDisclosureProps, state: DisclosureState
155155
role: 'group',
156156
'aria-labelledby': triggerId,
157157
'aria-hidden': !state.isExpanded,
158-
hidden: isSSR ? !state.isExpanded : undefined
158+
hidden: (isSSR || isDisabled) ? (isDisabled || !state.isExpanded) : undefined
159159
}
160160
};
161161
}

packages/react-aria-components/test/Disclosure.test.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('Disclosure', () => {
7878
});
7979

8080
it('should support disabled state', () => {
81-
const {getByTestId, getByRole} = render(
81+
const {getByTestId, getByRole, queryByText} = render(
8282
<Disclosure data-testid="disclosure" isDisabled>
8383
<Heading level={3}>
8484
<Button slot="trigger">Trigger</Button>
@@ -94,6 +94,25 @@ describe('Disclosure', () => {
9494
const button = getByRole('button');
9595
expect(button).toHaveAttribute('disabled');
9696
expect(button).toHaveAttribute('data-disabled', 'true');
97+
const panel = queryByText('Content');
98+
expect(panel).not.toBeVisible();
99+
});
100+
101+
it('should not expand a disabled disclosure via isExpanded', () => {
102+
const {getByTestId, queryByText} = render(
103+
<Disclosure data-testid="disclosure" isDisabled isExpanded>
104+
<Heading level={3}>
105+
<Button slot="trigger">Trigger</Button>
106+
</Heading>
107+
<DisclosurePanel>
108+
<p>Content</p>
109+
</DisclosurePanel>
110+
</Disclosure>
111+
);
112+
const disclosure = getByTestId('disclosure');
113+
expect(disclosure).toHaveAttribute('data-disabled', 'true');
114+
const panel = queryByText('Content');
115+
expect(panel).not.toBeVisible();
97116
});
98117

99118
it('should support controlled isExpanded prop', async () => {
@@ -239,7 +258,7 @@ describe('Disclosure', () => {
239258
const menuTrigger = getByTestId('menu-trigger');
240259
expect(disclosure).not.toHaveAttribute('data-expanded');
241260
expect(panel).not.toBeVisible();
242-
261+
243262
await user.click(menuTrigger);
244263
const menu = getByTestId('menu');
245264
expect(menu).toBeVisible();

0 commit comments

Comments
 (0)