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

ReferenceManyField - emptyText ignored #6518

Closed
olliebennett opened this issue Aug 19, 2021 · 2 comments
Closed

ReferenceManyField - emptyText ignored #6518

olliebennett opened this issue Aug 19, 2021 · 2 comments

Comments

@olliebennett
Copy link
Contributor

olliebennett commented Aug 19, 2021

There appears to be no way to display an empty state message when there are no results from a <ReferenceManyField />, despite docs suggesting the emptyText (common) field is supported.

What you were expecting:

When no results are returned for a referenced field, I expected my <ReferenceManyField /> to display the text defined in its emptyText attribute.

What happened instead:

Nothing is displayed except the <ReferenceManyField />'s label attribute.

Steps to reproduce:

Using the code sandbox below, view the show screen of any Post without comments.

Related code:

CodeSandbox (forked from simple example) -> https://codesandbox.io/s/boring-swirles-zpxq5

Entirely unchanged except to add:

emptyText='There are no comments for this post'

in /posts/PostShow.tsx line ~ 101.

Other information:

The ReferenceManyField docs say that " also accepts the common field props." and emptyText is a common field prop.

Environment

  • React-admin version: 3.17.2
  • Last version that did not exhibit the issue (if applicable): UNKNOWN
  • React version: 17.0.2
  • Browser: Firefox
  • Stack trace (in case of a JS error): N/A
@olliebennett
Copy link
Contributor Author

olliebennett commented Aug 19, 2021

I discovered the same is also true of ArrayField, and subsequently found discussion on #6179 covering the rationale.

TL;DR emptyText isn't supposed to work; it's a documentation issue.

The workaround is to use the child (eg. Datagrid's) empty attribute;

<ReferenceManyField ...>
  <Datagrid empty={<p>There are no comments for this post</p>}>
    ...

or, to style your text the same as a normal emptyText...

import Typography from '@material-ui/core/Typography'

<ReferenceManyField ...>
  <Datagrid empty={<Typography component='span' variant='body2'>There are no comments for this post</Typography>}>
    ...

Feel free to close this issue, although hopefully it will help someone coming across this limitation in future.

@fzaninotto
Copy link
Member

Yep, I'll close this issue as a duplicate of #6179. Thanks for the detailed report anyway!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants