Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close Circular and Schema Version Dropdowns When Clicking Away #2362

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions app/routes/circulars.$circularId.($version)/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import type { HeadersFunction, LoaderFunctionArgs } from '@remix-run/node'
import { json } from '@remix-run/node'
import { Link, useLoaderData, useRouteLoaderData } from '@remix-run/react'
import { Button, ButtonGroup, CardBody, Icon } from '@trussworks/react-uswds'
import { useState } from 'react'
import { useRef, useState } from 'react'
import invariant from 'tiny-invariant'
import { useOnClickOutside } from 'usehooks-ts'

import type { loader as parentLoader } from '../circulars.$circularId/route'
import { get } from '../circulars/circulars.server'
Expand Down Expand Up @@ -154,23 +155,26 @@ function CircularsHistory({
circular: number
history?: number[]
}) {
const [showVersions, setShowVersions] = useState<boolean>(false)

const ref = useRef<HTMLDivElement>(null)
const [showContent, setShowContent] = useState(false)
useOnClickOutside(ref, () => {
setShowContent(false)
})
return (
<>
<div ref={ref}>
<DetailsDropdownButton
outline
onClick={() => {
setShowVersions((shown) => !shown)
setShowContent((shown) => !shown)
}}
>
Versions
</DetailsDropdownButton>
{showVersions && (
{showContent && (
<DetailsDropdownContent>
<CardBody>
<Link
onClick={() => setShowVersions(!showVersions)}
onClick={() => setShowContent(!showContent)}
to={`/circulars/${circular}`}
>
Latest
Expand All @@ -179,7 +183,7 @@ function CircularsHistory({
history.map((version) => (
<div key={version}>
<Link
onClick={() => setShowVersions(!showVersions)}
onClick={() => setShowContent(!showContent)}
to={`/circulars/${circular}/${version}`}
>
Version {version}
Expand All @@ -189,6 +193,6 @@ function CircularsHistory({
</CardBody>
</DetailsDropdownContent>
)}
</>
</div>
)
}
19 changes: 12 additions & 7 deletions app/routes/docs_._schema-browser.schema.($version).$/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import {
} from '@trussworks/react-uswds'
import classNames from 'classnames'
import { dirname } from 'path'
import { useState } from 'react'
import { useRef, useState } from 'react'
import { useParams } from 'react-router'
import invariant from 'tiny-invariant'
import { useOnClickOutside } from 'usehooks-ts'

import type { loader as parentLoader } from '../docs_._schema-browser'
import type { Schema } from './components'
Expand Down Expand Up @@ -125,19 +126,23 @@ function VersionSelector({
versions: { name: string | null; ref: string }[]
path: string
}) {
const [showVersions, setShowVersions] = useState(false)
const ref = useRef<HTMLDivElement>(null)
const [showContent, setShowContent] = useState(false)
useOnClickOutside(ref, () => {
setShowContent(false)
})

return (
<>
<div ref={ref}>
<DetailsDropdownButton
title="Select version"
onClick={() => {
setShowVersions((shown) => !shown)
setShowContent((shown) => !shown)
}}
>
Version: {version}
</DetailsDropdownButton>
{showVersions && (
{showContent && (
<DetailsDropdownContent>
<CardHeader>
<h3>Versions</h3>
Expand All @@ -149,7 +154,7 @@ function VersionSelector({
className="usa-link"
to={`/docs/schema/${ref}/${path}`}
onClick={() => {
setShowVersions(false)
setShowContent(false)
}}
>
{name || ref}
Expand All @@ -159,7 +164,7 @@ function VersionSelector({
</CardBody>
</DetailsDropdownContent>
)}
</>
</div>
)
}

Expand Down
Loading