Spec: Empty addressable content fields with placeholders
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 202
- Forks
- 43
- PR merge metrics
- No merged PRs in 30d
Description
Here's a proposal for an official recommendation (spec?) to create "empty addressable content fields with placeholders" inside a contenteditable.
Recommended markup for making an element addressable with the caret:
<div contenteditable="true">
<p><br></p>
</div>
Why?
- the
<br>element ensures there's a single addressable caret position. If you added a zero-width-space instead, or any other character, you'd end up with two addressable caret positions. - most editors are already handling it this way (e.g. ProseMirror
<p><br class="ProseMirror-trailingBreak"></p>
To add a placeholder, use an empty class and a placeholder attribute and CSS to display it:
<div contenteditable="true">
<p class="empty" placeholder="Enter text"><br></p>
</div>
[contenteditable="true"] [placeholder].empty::before {
color: #ccc;
content: attr(placeholder);
}
Considerations:
- In my opinion
<div></div>without the<br>should not be addressable with the caret.- When developing editors very often those leaf-nodes become addressable accidentally. You'd have to write
<div contenteditable="false"></div>to avoid that. - Already some browsers skip caret positions here, with keyboard movement. See #500
- however, this may break some existing apps, that rely on
<div></div>being addressable (though that doesn't work in all browsers)
- When developing editors very often those leaf-nodes become addressable accidentally. You'd have to write
Known issues (only related to placeholder rendering/behavior):
- https://github.com/w3c/editing/issues/523
- https://github.com/w3c/editing/issues/501
- https://github.com/w3c/editing/issues/502
- https://github.com/w3c/editing/issues/523
- https://github.com/w3c/editing/issues/498
- https://github.com/w3c/editing/issues/499 (this would become a non-issue if the placeholder rendering issue were all resolved)
Contributor guide
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 with the proposed contenteditable markup, placeholder CSS, and the linked issues #523, #501, #502, #498, and #499. Determine whether the editing task force wants a formal recommendation and resolve the stated browser and compatibility considerations; done means an agreed specification or explainer, not just an implementation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- html
- Domain
- frontend, web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100