Skip to content

Commit

Permalink
fix: prevents Create banner from rendering when pane is collapsed
Browse files Browse the repository at this point in the history
  • Loading branch information
snorrees committed Oct 19, 2024
1 parent 9bfdd9d commit 34c3b96
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
useElementRect,
} from '@sanity/ui'
import {isHotkey} from 'is-hotkey-esm'
import {useCallback, useMemo, useState} from 'react'
import {type ReactNode, useCallback, useMemo, useState} from 'react'
import {useTranslation} from 'react-i18next'
import {
ChangeConnectorRoot,
Expand All @@ -25,7 +25,7 @@ import {type Path} from 'sanity-diff-patch'
import {styled} from 'styled-components'

import {TooltipDelayGroupProvider} from '../../../../ui-components'
import {Pane, PaneFooter, usePaneLayout} from '../../../components'
import {Pane, PaneFooter, usePane, usePaneLayout} from '../../../components'
import {DOCUMENT_PANEL_PORTAL_ELEMENT} from '../../../constants'
import {structureLocaleNamespace} from '../../../i18n'
import {useStructureTool} from '../../../useStructureTool'
Expand Down Expand Up @@ -85,6 +85,7 @@ export function DocumentLayout() {
const {features} = useStructureTool()
const {t} = useTranslation(structureLocaleNamespace)
const {collapsed: layoutCollapsed} = usePaneLayout()

const zOffsets = useZIndex()
const previewUrl = usePreviewUrl(value)

Expand Down Expand Up @@ -211,7 +212,9 @@ export function DocumentLayout() {
<DocumentPanelHeader ref={setHeaderElement} menuItems={menuItems} />

{createLinkMetadata && isCreateLinked(createLinkMetadata) && CreateLinkedBanner && (
<CreateLinkedBanner metadata={createLinkMetadata} />
<ShowWhenPaneOpen>
<CreateLinkedBanner metadata={createLinkMetadata} />
</ShowWhenPaneOpen>
)}

<DialogProvider position={DIALOG_PROVIDER_POSITION} zOffset={zOffsets.paneDialog}>
Expand Down Expand Up @@ -255,3 +258,12 @@ export function DocumentLayout() {
</GetFormValueProvider>
)
}

/**
* Prevents whatever is inside of it from rendering when the pane is collapsed.
* Needed locally as DocumentLayout does lives outside PaneContext, but is provided _somewhere_ within it.
*/
function ShowWhenPaneOpen(props: {children: ReactNode}) {
const {collapsed} = usePane()
return collapsed ? null : props.children
}

0 comments on commit 34c3b96

Please sign in to comment.