AdvancedCustomFields / AdvancedCustomFields/acf
Block v3 placeholders sometimes missing
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 945
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
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:
- In the render template, include whitespace in the element with the ACF attributes.
- The editor experience can be buggy as shown in the video below.
- 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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the block v3 inline-editing case with whitespace in the ACF-attribute element, then inspect the CSS rule and the placeholder behavior shown in the linked screenshots. Done means the placeholder remains visible for an empty field even when the template contains formatting whitespace.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100