Skip to content

fix(ui): adds new sidebar provider to help address tooltip and popup positioning inside the sidebar #11510

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
8 changes: 7 additions & 1 deletion packages/ui/src/elements/AddNewRelation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import type { Props } from './types.js'

import { PlusIcon } from '../../icons/Plus/index.js'
import { useAuth } from '../../providers/Auth/index.js'
import { useSidebar } from '../../providers/Sidebar/index.js'
import { useTranslation } from '../../providers/Translation/index.js'
import { Button } from '../Button/index.js'
import { useDocumentDrawer } from '../DocumentDrawer/index.js'
import { Popup } from '../Popup/index.js'
import * as PopupList from '../Popup/PopupButtonList/index.js'
import { Tooltip } from '../Tooltip/index.js'
import './index.scss'
import { Tooltip } from '../Tooltip/index.js'
import { useRelatedCollections } from './useRelatedCollections.js'

const baseClass = 'relationship-add-new'
Expand All @@ -41,6 +42,10 @@ export const AddNewRelation: React.FC<Props> = ({
!relatedToMany ? relatedCollections[0] : undefined,
)

// If this field is in a sidebar we want to make sure it's using the sidebar ref for boundingRef in the Popup
// This helps us avoid any overflow related issues
const { ref: sidebarRef } = useSidebar()

const [popupOpen, setPopupOpen] = useState(false)
const { i18n, t } = useTranslation()
const [showTooltip, setShowTooltip] = useState(false)
Expand Down Expand Up @@ -170,6 +175,7 @@ export const AddNewRelation: React.FC<Props> = ({
{relatedCollections.length > 1 && (
<Fragment>
<Popup
boundingRef={sidebarRef}
button={
ButtonFromProps ? (
ButtonFromProps
Expand Down
5 changes: 3 additions & 2 deletions packages/ui/src/elements/DocumentFields/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import React, { useMemo } from 'react'

import { useFormInitializing, useFormProcessing } from '../../forms/Form/context.js'
import { RenderFields } from '../../forms/RenderFields/index.js'
import { SidebarProvider } from '../../providers/Sidebar/index.js'
import { Gutter } from '../Gutter/index.js'
import './index.scss'

Expand Down Expand Up @@ -90,7 +91,7 @@ export const DocumentFields: React.FC<Args> = ({
</Gutter>
</div>
{hasSidebarFields ? (
<div className={`${baseClass}__sidebar-wrap`}>
<SidebarProvider className={`${baseClass}__sidebar-wrap`}>
<div className={`${baseClass}__sidebar`}>
<div className={`${baseClass}__sidebar-fields`}>
<RenderFields
Expand All @@ -104,7 +105,7 @@ export const DocumentFields: React.FC<Args> = ({
/>
</div>
</div>
</div>
</SidebarProvider>
) : null}
</div>
)
Expand Down
31 changes: 31 additions & 0 deletions packages/ui/src/providers/Sidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use client'
import React, { createContext, useContext, useRef } from 'react'

export type Theme = 'dark' | 'light'

export type SidebarContext = {
ref: React.RefObject<HTMLDivElement>
}

const initialContext: SidebarContext = {
ref: null,
}

const Context = createContext(initialContext)

export const SidebarProvider: React.FC<{
children?: React.ReactNode
className?: string
}> = ({ children, className }) => {
const ref = useRef<HTMLDivElement>(null)

return (
<Context.Provider value={{ ref }}>
<div className={className} ref={ref}>
{children}
</div>
</Context.Provider>
)
}

export const useSidebar = (): SidebarContext => useContext(Context)
Loading