Re: [whatwg] Should editable elements have placeholder attribute?

On Thu, Jun 14, 2012 at 1:11 AM, Ian Hickson <ian@hixie.ch> wrote:
> I strongly disagree. <input> and <textarea> are high-level constructs, so
> it's fine for them to be defined by the UA's platform. But contenteditable
> is a very low-level primitive. We can't just punt on how it interacts with
> CSS; otherwise people will have no way to reliably make UIs with it.

I don't know why you think contenteditable is "lower-level" than input/textarea.

>> In the end this is the check that I'm using at the moment (I didn't
>> perform extensive tests, just enough to check that it seemed to work)
>>
>> var value = data.replace( /[\n|\t]*/g, '' ).toLowerCase();
>> if ( !value || value == '<br>' || value == '<p>&nbsp;<br></p>' || value ==
>> '<p><br></p>' || value == '<p>&nbsp;</p>' )
>>     return true;
>
> Now there's a problem we should fix. Having five different representations
> of "nothing" seems like a terrible position for us to be in.

If you type some stuff and then delete it all, the desired result will
vary based on lots of factors, e.g.:

* Whether <div> or <p> is being used for paragraph separators.  Both
<p><br></p> and <div><br></div> might make sense for "nothing",
depending.  This is author-configurable using the
defaultParagraphSeparator command.

* Whether there was any styling present before.  If all the text was
previously bold, for instance, deleting everything might result in
something like <p><b><br></b></p>, because per spec, deletion doesn't
remove style tags from empty lines.

* Whether there was any other special markup.  If something (like
execCommand("insertHTML")) made the first line have <p id="foo">, then
deleting everything would result in <p id="foo"><br></p>.

* What the author specified as the initial contents of the editable
area.  If you have <div contenteditable><br></div> to start with, and
the user puts the cursor there and then types "foo" and then deletes
it, you'll go back to having just <br>, because nothing ever inserted
a <p> or <div> or anything.  (As soon as the user hits Enter, both the
old and new lines are wrapped in a paragraph separator per spec,
although only IE/Opera do this right now.)

Really, you can have any HTML markup at all in contenteditable, and we
can't avoid that.  There's not going to be any reliable way to figure
out what "nothing" is if you can't answer the same question for
arbitrary HTML.

Received on Sunday, 17 June 2012 09:50:34 UTC