Skip to content

Add support for empty in Reference fields#10817

Merged
djhi merged 8 commits intonextfrom
empty
Jul 1, 2025
Merged

Add support for empty in Reference fields#10817
djhi merged 8 commits intonextfrom
empty

Conversation

@fzaninotto
Copy link
Member

@fzaninotto fzaninotto commented Jul 1, 2025

Problem

When using Reference fields (<ReferenceField>, <ReferenceOneField>, <ReferenceManyField>), to define a custom view for the empty case, developers have to create a custom child that reads the list context. This is super cumbersome.

Solution

Add support for the empty prop.

<ReferenceManyField
  reference="books"
  target="author_id"
  empty="no books"
>
    ...
</ReferenceManyField>

Additional Checks

  • Extract <ReferenceOneFieldBase> from <ReferenceOneField>
  • Extract <ReferenceManyFieldBase> from <ReferenceManyField>
  • Add <ReferenceField empty> prop
  • Add <ReferenceArrayField empty> prop
  • Add <ReferenceManyField empty> prop
  • Add <WithRecord empty> prop
  • Update doc
  • Add tests

The empty logic is in ra-core, so it can be reused for other UI kits.

The changes are backward compatible: emptyText is still supported where it was implemented, but it's deprecated.

Copy link
Contributor

@djhi djhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nice that we have more base components! 💯 That would be even nicer with stories and tests for those :)

@fzaninotto
Copy link
Member Author

It's nice that we have more base components! 💯 That would be even nicer with stories and tests for those :)

Done is better than perfect ;)

The base components are tested indirectly via MUI components.

@djhi djhi added this to the 5.10.0 milestone Jul 1, 2025
@djhi djhi merged commit b66f0ac into next Jul 1, 2025
15 checks passed
@djhi djhi deleted the empty branch July 1, 2025 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RFR Ready For Review

Development

Successfully merging this pull request may close these issues.

2 participants

Comments