Skip to content

Commit 720c9c2

Browse files
authored
[collapsible] Fix types and vitest warnings (#772)
1 parent 9b5ce28 commit 720c9c2

File tree

8 files changed

+29
-13
lines changed

8 files changed

+29
-13
lines changed

docs/src/app/experiments/accordion-horizontal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ export default function App() {
4646
orientation="horizontal"
4747
direction="rtl"
4848
value={val}
49-
onValueChange={(newValue: Accordion.Root.Props['Value']) => {
50-
if (newValue.length > 0) {
49+
onValueChange={(newValue: Accordion.Root.Props['value']) => {
50+
if (Array.isArray(newValue) && newValue.length > 0) {
5151
setVal(newValue);
5252
}
5353
}}

docs/src/app/experiments/accordion.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Accordion } from '@base_ui/react/Accordion';
55

66
export default function App() {
77
const [openMultiple, setOpenMultiple] = React.useState(true);
8-
const [val, setVal] = React.useState(['one']);
8+
const [val, setVal] = React.useState<readonly (string | number)[]>(['one']);
99
const [val2, setVal2] = React.useState(['one']);
1010
return (
1111
<div className="AccordionDemo">
@@ -141,8 +141,8 @@ export default function App() {
141141
<Accordion.Root
142142
className="MyAccordion-root"
143143
value={val2}
144-
onValueChange={(newValue: Accordion.Root.Props['Value']) => {
145-
if (newValue.length > 0) {
144+
onValueChange={(newValue: Accordion.Root.Props['value']) => {
145+
if (Array.isArray(newValue) && newValue.length > 0) {
146146
setVal2(newValue);
147147
}
148148
}}

docs/src/app/experiments/collapsible.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default function CollapsibleDemo() {
5353
</Collapsible.Root>
5454
</div>
5555

56-
<Collapsible.Root render="span" className="MyCollapsible-root">
56+
<Collapsible.Root render={<span />} className="MyCollapsible-root">
5757
<Collapsible.Trigger className="MyCollapsible-trigger">
5858
<span className="icon">
5959
<svg

packages/mui-base/src/Accordion/Item/AccordionItem.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export namespace AccordionItem {
148148
}
149149

150150
export interface Props
151-
extends BaseUIComponentProps<any, OwnerState>,
151+
extends BaseUIComponentProps<'div', OwnerState>,
152152
Pick<useCollapsibleRoot.Parameters, 'disabled' | 'onOpenChange'> {
153153
value?: Value;
154154
}
@@ -161,6 +161,10 @@ AccordionItem.propTypes /* remove-proptypes */ = {
161161
// │ These PropTypes are generated from the TypeScript type definitions. │
162162
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
163163
// └─────────────────────────────────────────────────────────────────────┘
164+
/**
165+
* @ignore
166+
*/
167+
children: PropTypes.node,
164168
/**
165169
* Class names applied to the element or a function that returns them based on the component's state.
166170
*/

packages/mui-base/src/Accordion/Root/AccordionRoot.test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as React from 'react';
22
import { expect } from 'chai';
33
import { spy } from 'sinon';
4-
import { createRenderer, describeSkipIf } from '@mui/internal-test-utils';
4+
import { describeSkipIf, flushMicrotasks } from '@mui/internal-test-utils';
55
import { Accordion } from '@base_ui/react/Accordion';
6-
import { describeConformance } from '#test-utils';
6+
import { createRenderer, describeConformance } from '#test-utils';
77

88
describe('<Accordion.Root />', () => {
99
const { render } = createRenderer();
@@ -154,13 +154,15 @@ describe('<Accordion.Root />', () => {
154154
expect(panel).not.toBeVisible();
155155

156156
setProps({ value: [0] });
157+
await flushMicrotasks();
157158

158159
expect(trigger).to.have.attribute('aria-expanded', 'true');
159160
expect(trigger).to.have.attribute('data-panel-open');
160161
expect(panel).toBeVisible();
161162
expect(panel).to.have.attribute('data-open');
162163

163164
setProps({ value: [] });
165+
await flushMicrotasks();
164166

165167
expect(trigger).to.have.attribute('aria-expanded', 'false');
166168
expect(panel).not.toBeVisible();

packages/mui-base/src/Accordion/Root/AccordionRoot.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export namespace AccordionRoot {
107107

108108
export interface Props
109109
extends useAccordionRoot.Parameters,
110-
BaseUIComponentProps<any, OwnerState> {
110+
Omit<BaseUIComponentProps<'div', OwnerState>, 'defaultValue'> {
111111
hiddenUntilFound?: boolean;
112112
}
113113
}
@@ -124,6 +124,10 @@ AccordionRoot.propTypes /* remove-proptypes */ = {
124124
* @default true
125125
*/
126126
animated: PropTypes.bool,
127+
/**
128+
* @ignore
129+
*/
130+
children: PropTypes.node,
127131
/**
128132
* Class names applied to the element or a function that returns them based on the component's state.
129133
*/

packages/mui-base/src/Collapsible/Root/CollapsibleRoot.test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import * as React from 'react';
33
import { expect } from 'chai';
44
import { spy } from 'sinon';
5-
import { createRenderer, act, describeSkipIf } from '@mui/internal-test-utils';
5+
import { act, describeSkipIf, flushMicrotasks } from '@mui/internal-test-utils';
66
import { Collapsible } from '@base_ui/react/Collapsible';
7-
import { describeConformance } from '../../../test/describeConformance';
7+
import { createRenderer, describeConformance } from '#test-utils';
88

99
describe('<Collapsible.Root />', () => {
1010
const { render } = createRenderer();
@@ -51,13 +51,15 @@ describe('<Collapsible.Root />', () => {
5151
expect(panel).not.toBeVisible();
5252

5353
setProps({ open: true });
54+
await flushMicrotasks();
5455

5556
expect(trigger).to.have.attribute('aria-expanded', 'true');
5657
expect(panel).toBeVisible();
5758
expect(panel).to.have.attribute('data-open');
5859
expect(trigger).to.have.attribute('data-panel-open');
5960

6061
setProps({ open: false });
62+
await flushMicrotasks();
6163

6264
expect(trigger).to.have.attribute('aria-expanded', 'false');
6365
expect(panel).not.toBeVisible();

packages/mui-base/src/Collapsible/Root/CollapsibleRoot.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export namespace CollapsibleRoot {
9090

9191
export interface Props
9292
extends useCollapsibleRoot.Parameters,
93-
BaseUIComponentProps<any, OwnerState> {}
93+
BaseUIComponentProps<'div', OwnerState> {}
9494
}
9595

9696
CollapsibleRoot.propTypes /* remove-proptypes */ = {
@@ -103,6 +103,10 @@ CollapsibleRoot.propTypes /* remove-proptypes */ = {
103103
* @default true
104104
*/
105105
animated: PropTypes.bool,
106+
/**
107+
* @ignore
108+
*/
109+
children: PropTypes.node,
106110
/**
107111
* Class names applied to the element or a function that returns them based on the component's state.
108112
*/

0 commit comments

Comments
 (0)