Skip to content

Commit

Permalink
docs: fix error on collapsing prerequisites
Browse files Browse the repository at this point in the history
  • Loading branch information
shahednasser committed Nov 19, 2024
1 parent 661ea78 commit b13ef22
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions www/packages/docs-ui/src/components/Prerequisites/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client"

import React from "react"
import React, { useRef } from "react"
import { Button, useCollapsible } from "../.."
import clsx from "clsx"
import { TriangleRightMini } from "@medusajs/icons"
Expand All @@ -15,9 +15,12 @@ type PrerequisitesProps = {
}

export const Prerequisites = ({ items }: PrerequisitesProps) => {
const itemsRef = useRef<HTMLDivElement>(null)
const { collapsed, getCollapsibleElms, setCollapsed } = useCollapsible({
initialValue: false,
translateEnabled: false,
childrenRef: itemsRef,
useChild: false,
})

const getPosition = (index: number): PrerequisiteItemPosition => {
Expand Down Expand Up @@ -71,7 +74,7 @@ export const Prerequisites = ({ items }: PrerequisitesProps) => {
</Button>
</summary>
{getCollapsibleElms(
<div className="flex gap-[6px] flex-col">
<div className="flex gap-[6px] flex-col" ref={itemsRef}>
{items.map((item, index) => (
<PrerequisiteItem
item={{
Expand Down
6 changes: 6 additions & 0 deletions www/packages/docs-ui/src/hooks/use-collapsible/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type CollapsibleProps = {
onClose?: () => void
unmountOnExit?: boolean
childrenRef?: React.RefObject<HTMLElement | null>
useChild?: boolean
}

export type CollapsibleReturn = {
Expand All @@ -26,10 +27,15 @@ export const useCollapsible = ({
onClose,
unmountOnExit = true,
childrenRef,
useChild = true,
}: CollapsibleProps): CollapsibleReturn => {
const [collapsed, setCollapsed] = useState(initialValue)

const getNodeFromChildrenRef = () => {
if (!useChild) {
return childrenRef?.current
}

return (
(childrenRef?.current?.firstElementChild as HTMLElement) ||
childrenRef?.current
Expand Down

0 comments on commit b13ef22

Please sign in to comment.