Skip to content

Block v3 placeholders sometimes missing #1007

@allanemerson

Description

@allanemerson

Describe the bug
When using inline editing in blocks v3, the placeholder can sometimes be missing. This is because the placeholder is shown via CSS when the target element is :empty, but whitespace in the code can prevent :empty from working.

To Reproduce
Steps to reproduce the behavior:

  1. In the render template, include whitespace in the element with the ACF attributes.
  2. The editor experience can be buggy as shown in the video below.
  3. Remove the whitespace in the template and the placeholder is more stable.

Expected behavior
The placeholder should be visible when the field is empty, not the element, because the element can have whitespace due to code formatting.

Screenshots or Video
CSS rule: https://screenshot.electricpulp.com/CKLzlHfq9h4CZkpXcyMF
Whitespace preventing the rule: https://screenshot.electricpulp.com/62ljqcQnnJ0ynCfND65l
Preheading without white space (stable), heading with white space (unstable): https://screenshot.electricpulp.com/fDbBddzyyL6LTC8kjcV5

Code
Tabbed/intended code causes instability:

<div class="hero__preheading" <?= acf_inline_text_editing_attrs('pre_heading', ['placeholder' => 'Add a pre heading (optional)']); ?>>
    <?= get_field('pre_heading') ?>
</div>

Whitespace removed works:

<div class="hero__preheading" <?= acf_inline_text_editing_attrs('pre_heading', ['placeholder' => 'Add a pre heading (optional)']); ?>><?= get_field('pre_heading') ?></div>

Version Information:

  • WordPress Version 6.9.4
  • PHP Version 8.2
  • ACF Pro 6.7.1
  • Chrome Version 146.0.7680.154

Additional context
Possible solution: rather than relying on :empty, check the field value for non-null and then toggle a class on the target element. The ::before used for the placeholder can then be shown with that class.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions