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

Details block: fix the fallback value for the Summary #68657

Open
2 of 6 tasks
afercia opened this issue Jan 14, 2025 · 3 comments · May be fixed by #68658
Open
2 of 6 tasks

Details block: fix the fallback value for the Summary #68657

afercia opened this issue Jan 14, 2025 · 3 comments · May be fixed by #68658
Labels
[Block] Details Affects the Details Block - used to display content which can be shown/hidden l10n Localization and translations best practices [Package] Block library /packages/block-library [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@afercia
Copy link
Contributor

afercia commented Jan 14, 2025

Description

To my understanding, the following code is supposed to provide a fallback text for the details summary, when it is empty:

const summary = attributes.summary ? attributes.summary : 'Details';

Not sure that's correct:

  • First of all, 'Details' is not translatable.
  • More importantly, even when the summary is left empty, attributes.summary returns a RichTextData object so that the condition is always true. Actually, this condition should check the content of the RichText component used for the Summary.

Introduced in #49808

Step-by-step reproduction instructions

  • Add a Details block.
  • Leave the Summary empty.
  • Add a paragraph in the details content and save.
  • Go to the front end.
  • Observe the Summary is empty.
  • Expected: to show the fallback text 'Details'.

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure
@afercia afercia added [Block] Details Affects the Details Block - used to display content which can be shown/hidden [Package] Block library /packages/block-library [Type] Bug An existing feature does not function as intended l10n Localization and translations best practices labels Jan 14, 2025
@afercia afercia changed the title Details block: fix the fallback value for teh Summary Details block: fix the fallback value for the Summary Jan 14, 2025
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Jan 14, 2025
@t-hamano
Copy link
Contributor

First of all, 'Details' is not translatable.

Unfortunately, we can't use the translate function in the save function, because it will be translated differently by the user and cause a block validation error.

I propose to remove the fallback text, i.e. display an empty summary tag if no summary text exists. I haven't found a better approach yet.

@t-hamano
Copy link
Contributor

Update:

I propose to remove the fallback text, i.e. display an empty summary tag if no summary text exists. I haven't found a better approach yet.

Using the render_callback function and the iAPI, we should be able to inject a translatable fallback text if the summary text is empty. In any case, the untranslatable summary text should be removed from the save function.

@afercia
Copy link
Contributor Author

afercia commented Jan 14, 2025

Yep I had the impression the fallback text wasn't in the right place in the save function to start with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Details Affects the Details Block - used to display content which can be shown/hidden l10n Localization and translations best practices [Package] Block library /packages/block-library [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants