Skip to content

Commit 9e57dfe

Browse files
committed
Revert changes in Disclosure group
1 parent d560280 commit 9e57dfe

File tree

2 files changed

+22
-33
lines changed

2 files changed

+22
-33
lines changed

packages/react-openapi/src/OpenAPIDisclosureGroup.tsx

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,12 @@ interface Props {
1717
type TDisclosureGroup = {
1818
id: string;
1919
label: string | React.ReactNode;
20-
} & (
21-
| {
22-
tabs?: {
23-
id: string;
24-
label: string | React.ReactNode;
25-
body?: React.ReactNode;
26-
}[];
27-
}
28-
| {
29-
body?: React.ReactNode;
30-
}
31-
);
20+
tabs?: {
21+
id: string;
22+
label?: string | React.ReactNode;
23+
body?: React.ReactNode;
24+
}[];
25+
};
3226

3327
const DisclosureGroupStateContext = createContext<DisclosureGroupState | null>(null);
3428

@@ -67,7 +61,7 @@ function DisclosureItem(props: { group: TDisclosureGroup; icon?: React.ReactNode
6761

6862
const panelRef = useRef<HTMLDivElement | null>(null);
6963
const triggerRef = useRef<HTMLButtonElement | null>(null);
70-
const isDisabled = groupState?.isDisabled || ('tabs' in group && !group.tabs?.length) || false;
64+
const isDisabled = groupState?.isDisabled || !group.tabs?.length || false;
7165
const { buttonProps: triggerProps, panelProps } = useDisclosure(
7266
{
7367
...props,
@@ -80,19 +74,9 @@ function DisclosureItem(props: { group: TDisclosureGroup; icon?: React.ReactNode
8074
const { buttonProps } = useButton(triggerProps, triggerRef);
8175
const { isFocusVisible, focusProps } = useFocusRing();
8276

83-
const defaultTab =
84-
'tabs' in group && group.tabs?.[0]
85-
? (group.tabs[0]?.id ?? '')
86-
: 'body' in group
87-
? 'body'
88-
: '';
77+
const defaultTab = group.tabs?.[0]?.id || '';
8978
const [selectedTabKey, setSelectedTabKey] = useState(defaultTab);
90-
const selectedTab =
91-
'tabs' in group
92-
? group.tabs?.find((tab) => tab.id === selectedTabKey)
93-
: 'body' in group
94-
? { id: 'body', body: group.body }
95-
: null;
79+
const selectedTab = group.tabs?.find((tab) => tab.id === selectedTabKey);
9680

9781
return (
9882
<div className="openapi-disclosure-group" aria-expanded={state.isExpanded}>
@@ -119,7 +103,7 @@ function DisclosureItem(props: { group: TDisclosureGroup; icon?: React.ReactNode
119103

120104
{group.label}
121105
</button>
122-
{'tabs' in group && group.tabs ? (
106+
{group.tabs ? (
123107
<div className="openapi-disclosure-group-mediatype">
124108
{group.tabs?.length > 1 ? (
125109
<select

packages/react-openapi/src/models/OpenAPIModels.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,18 @@ function OpenAPIRootModelsSchema(props: {
7373
<span className="openapi-response-statuscode">{name}</span>
7474
</div>
7575
),
76-
body: (
77-
<Section className="openapi-section-models">
78-
<SectionBody>
79-
<OpenAPIRootSchema schema={schema} context={context} />
80-
</SectionBody>
81-
</Section>
82-
),
76+
tabs: [
77+
{
78+
id: 'model',
79+
body: (
80+
<Section className="openapi-section-models">
81+
<SectionBody>
82+
<OpenAPIRootSchema schema={schema} context={context} />
83+
</SectionBody>
84+
</Section>
85+
),
86+
},
87+
],
8388
}))}
8489
/>
8590
);

0 commit comments

Comments
 (0)