Skip to content

Instantly share code, notes, and snippets.

@FOLLGAD
Last active April 10, 2025 15:01
Show Gist options
  • Select an option

  • Save FOLLGAD/67291464aa739667eb8442f14974119a to your computer and use it in GitHub Desktop.

Select an option

Save FOLLGAD/67291464aa739667eb8442f14974119a to your computer and use it in GitHub Desktop.
Antd simple headless collapse without the header
import { HeadlessCollapse } from "./HeadlessCollapse";
export const Example = () => {
const [expand, setExpand] = useState(false);
return (
<>
<HeadlessCollapse expanded={expand}>
<p>This is some text!
<button onClick={() => setExpand(false)}>Close</button>
</HeadlessCollapse>
<p>Press this button to open a collapse:</p>
<button onClick={() => setExpand(t => !t)}>Toggle</button>
</>
)
}
import { Collapse } from "antd";
import React, { FC, PropsWithChildren } from "react";
import styles from "./styles.module.scss";
interface Props {
expanded: boolean;
}
export const HeadlessCollapse: FC<PropsWithChildren<Props>> = ({
expanded,
children,
}) => {
return (
<Collapse
activeKey={expanded ? ["1"] : []}
bordered={false}
className={styles.collapse}
>
<Collapse.Panel header="" key="1">
{children}
</Collapse.Panel>
</Collapse>
);
};
.collapse {
transition: background 0.3s ease-in-out;
border-radius: 5px;
padding: 8px;
margin: 0 -8px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment