payload icon indicating copy to clipboard operation
payload copied to clipboard

Relationship field with admin appearance set to drawer is not working when the other collection is using richtext as title

Open Talaween opened this issue 1 year ago • 1 comments

Describe the Bug

if you have a relationship field, and set its admin appearance to drawer for example:

{
  name: 'question',
  type: 'relationship',
  relationTo: 'multiple-choice-questions',
  admin: {
    appearance: 'drawer',
  }
}

then in the multiple-choice-questions collection you have:

{
  slug: 'multiple-choice-questions',
  admin: {
    useAsTitle: 'question',
  },
  fields: [
    {
      name: 'question',
      type: 'richText',
      required: true,
    },
  ]
}

the drawer on the relationship will not work, it will behave strangely, first when try to click the question it tries to take you to the other document edit view and when you click return on broswer then the first collection you were working on becomes unresponsive

Link to the code that reproduces this issue

https://github.com/payloadcms/payload

Reproduction Steps

1- create a collection and give it one richtext field 2-make the richtext as title in colleciton admin property 3- create another colleciotn 4-make a relationship to the first collection in the secone one 5- set the field admin appearnace to drawer 6- run the project 7- go to admin panel 8- create one document for the first collection 9- try to link the created document using the drawer

Which area(s) are affected? (Select all that apply)

area: ui

Environment Info

Binaries:
  Node: 22.19.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  payload: 3.58.0
  next: 15.5.3
  @payloadcms/db-mongodb: 3.58.0
  @payloadcms/email-nodemailer: 3.58.0
  @payloadcms/graphql: 3.58.0
  @payloadcms/next/utilities: 3.58.0
  @payloadcms/payload-cloud: 3.58.0
  @payloadcms/plugin-cloud-storage: 3.58.0
  @payloadcms/plugin-import-export: 3.58.0
  @payloadcms/plugin-stripe: 3.58.0
  @payloadcms/richtext-lexical: 3.58.0
  @payloadcms/storage-s3: 3.58.0
  @payloadcms/translations: 3.58.0
  @payloadcms/ui/shared: 3.58.0
  react: 19.1.1
  react-dom: 19.1.1
Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Home
  Available memory (MB): 65274
  Available CPU cores: 32

Talaween avatar Oct 02 '25 22:10 Talaween

I've investigated this issue and found the root cause.

Root Cause

When a relationship field uses appearance: 'drawer' and the related collection has a richText field as useAsTitle, the custom cell component (Lexical's RscEntryLexicalCell) was being rendered via RenderCustomComponent, which bypassed RenderDefaultCell.

RenderDefaultCell is the client component responsible for reading the drawer context and setting up the onClick handler for item selection. Since the richText cell bypassed this, it received link: true (from server-side rendering) and rendered as a Link component that navigated away instead of selecting the item.

Solution

  1. Modified RenderDefaultCell to accept a customCell prop for custom cell components
  2. When a custom cell exists in a drawer context, wrap it with a button that captures clicks using onClickCapture and prevents nested Link components from navigating
  3. Updated renderCell.tsx to always use RenderDefaultCell, passing custom cells as a prop

This ensures all cells (custom or default) properly handle the drawer context for selection behavior.

I have a fix ready and will open a PR shortly.

RajeshKumar11 avatar Jan 19 '26 17:01 RajeshKumar11