This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 17814 - it makes no sense to limit the placeholder attribute to values of the same direction as the <input>
Summary: it makes no sense to limit the placeholder attribute to values of the same di...
Status: RESOLVED FIXED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: Unsorted
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-18 06:53 UTC by contributor
Modified: 2015-08-31 19:08 UTC (History)
8 users (show)

See Also:


Attachments
placholder direction/bidi fix with dir=auto (50.65 KB, image/png)
2015-01-30 07:41 UTC, Binyamin
Details

Description contributor 2012-07-18 06:53:56 UTC
This was was cloned from bug 15488 as part of operation convergence.
Originally filed: 2012-01-10 05:10:00 +0000
Original reporter: Aharon Lanin <aharon.lists.lanin@gmail.com>

================================================================================
 #0   Aharon Lanin                                    2012-01-10 05:10:18 +0000 
--------------------------------------------------------------------------------
Currently, the HTML spec (http://dev.w3.org/html5/spec/Overview.html#text-rendered-in-native-user-interfaces) states that "text from elements (either attribute values or the contents of elements) is expected to be rendered in a manner that honors the directionality of the element from which the text was obtained." While this is usually what one wants, there are cases that it is does not suit the placeholder attribute.

For example, say that one has a Hebrew or Arabic page containing an <input type="text"> intended for the user to enter a snippet of JavaScript. One would then make it <input type="text" dir="ltr">, since JavaScript code is always LTR. One might want a placeholder on the input, however, that would be in the language of the rest of the page, and thus RTL. According to the spec, however, it would be displayed in LTR, and thus garbled. Another example would be an <input type="tel">, since telephone numbers are always LTR, but one would might easily want an RTL placeholder on it.

We had a similar problem with the title attribute in https://www.w3.org/Bugs/Public/show_bug.cgi?id=10818: the title's value sometimes needs to have one direction while the element needs another. With the title attribute, however, we at least had a workaround: wrap the element in a span, move the title to the span, and set the dir attribute on both elements as each needs. This does not work for placeholder because placeholder does not work on a <span>.

Two possible solutions to this problem are:

1. define a placeholderdir attribute for <input>.

2. always display the placeholder as if it had dir=auto.

The second possibility is not perfect, but at least setting the placeholder description explicitly is more easily done by prefixing it with an &lrm; or &rlm; than by wrapping it in LRE|RLE and PDF characters.
================================================================================
 #1   Ian 'Hixie' Hickson                             2012-02-03 06:38:27 +0000 
--------------------------------------------------------------------------------
Why would it be garbled? dir=rtl isn't an override, just an embedding. The most it would do is change the positioning of punctuation (easily fixed with explicit embedding information) or the alignment.

I guess I don't mind if we make it dir=auto, but I really find this allergy to Unicode bidi formatting characters to be getting out of control. This is an extreme edge case, we shouldn't add an attribute for it.
================================================================================
 #2   Aharon Lanin                                    2012-02-05 11:11:58 +0000 
--------------------------------------------------------------------------------
> Why would it be garbled? [...] The most
> it would do is change the positioning of punctuation

Well, first of all, misplaced punctuation is already sufficiently annoying.
But it can certainly get worse. For example, let's say that I have a site named "foo", with my own set of user accounts. The account names are limited to Latin letters, numbers, periods, underscores, and dashes. I support user interfaces in several languages, including RTL ones. Since "foo" is my brand, it remains "foo" in all locales.

Where the English UI has an <input type="text" placeholder="your foo username">, an RTL one has it as <input type="text" dir="ltr" placeholder="YOUR foo USERNAME">. (I am using the convention of uppercase Latin for RTL characters here to make this example intelligible to all readers.)

Why did I make it dir="ltr"? So that a username like john.doe will not go through the stage of looking like ".john" while being typed, with the caret jumping around and/or being displayed in strange places.

To be intelligible, my placeholder has to be displayed RTL, as:

EMANRESU foo RUOY

Instead, because of the dir=ltr, it is displayed in LTR, as

RUOY foo EMANRESU

This is as intelligible as "username OOF your" would be in English.

So, I try to fix it by making my input dir="auto". It does not help, since the spec says that the value of any attribute has to be displayed in the element's *directionality*. This is either "ltr" or "rtl", never "auto". And for an empty <input> (which it has to be for the placeholder to be displayed), the dir=auto evaluates to "ltr" directionality.

> This is an extreme edge case

Not at all. My guess is that a very significant percentage of inputs is for types of data that has to be LTR, such as numeric data (e.g. phone number, age, item count) and always-ltr text data like the username above. In a well-designed RTL page, these should all be marked with dir=ltr. And once dir=auto becomes available in more browsers, most of the rest should be marked with dir=auto. In either case, the placeholder will be displayed LTR, and thus will be garbled in an RTL page if it (besides containing some RTL words):
- starts with a number, or
- ends with punctuation, or
- contains an LTR word (e.g. a brand name)

> easily fixed with explicit embedding information

There is nothing easy about using LRE/RLE + PDF for the average human being. By and large, users do not even know that they exist. They can not generate them on their keyboards, and if they could, their invisibility makes it a challenge to edit the placeholder later. And if they type them as entities, they wind up becoming discombobulated. For example, here is what "&#8234;hello&#8236;" looks like once I substitute actual RTL character for the "hello":

placeholder="&#8234;שלום&#8236;"

Having said all this and hopefully shown that the problem is real, I must admit that I do not know of a solution that really makes me happy.
================================================================================
Comment 1 Ian 'Hixie' Hickson 2012-08-28 21:20:48 UTC
People don't know about these characters because they haven't needed to use them. But if they want this to work, then they need to use them. So I don't see why this would remain a truism forever.

There's nothing more magical or difficult about &#x202B; than <span dir=rtl>, IMHO. If anything, I would say that the mistake we made was ever using high-level markup for this character-level issue, as it means that every time we have a non-markup-level problem, we are stuck. If we had always used Unicode's characters, we could have avoided a whole class if issues.

I've added some examples of this in the spec.
Comment 2 contributor 2012-08-28 21:20:57 UTC
Checked in as WHATWG revision r7292.
Check-in comment: Add example showing bidi in placeholder=''
http://html5.org/tools/web-apps-tracker?from=7291&to=7292
Comment 3 Aharon Lanin 2013-04-11 11:35:30 UTC
The solution offered by the fix for https://www.w3.org/Bugs/Public/show_bug.cgi?id=17829, i.e. to use dir=auto on an input with placeholder, should be good enough for most use cases, IMO.
Comment 4 Binyamin 2015-01-29 07:57:43 UTC
What is wrong to apply dir=auto for placeholder Shadow DOM? Please consider this approach!

See testcase http://jsbin.com/cimiwi/1/quiet - placholder direction/bidi fails on all cases.

https://html.spec.whatwg.org/multipage/forms.html#the-placeholder-attribute proposed <input placeholder="&#x202B;text&#x202E;"> does not fix the issue.
Comment 5 Ian 'Hixie' Hickson 2015-01-29 23:09:46 UTC
I don't understand comment 4; can you elaborate? What specification change are you requesting?
Comment 6 Binyamin 2015-01-30 07:41:53 UTC
Created attachment 1567 [details]
placholder direction/bidi fix with dir=auto

All you need to fix the issue is to specify dir=auto for placholder in Shadow DOM.
Comment 7 Ian 'Hixie' Hickson 2015-03-04 18:57:43 UTC
dir=auto isn't a solution here for the same reason it's not a solution in general: it can't reliably pick the right direction.

I don't understand why (short of browser bugs) the current proposed solution (explicit bidi formatting characters in the text) wouldn't work.
Comment 8 Domenic Denicola 2015-08-29 05:18:22 UTC
Per comment 3 this is fixed. Comment 4 onward seem to be a complaint about the Blink implementation and its use of shadow DOM, which the commenter things is incorrect. It doesn't appear to be a spec bug. Please let us know if I misunderstood.
Comment 9 Binyamin 2015-08-29 19:34:56 UTC
(In reply to Domenic Denicola from comment #8)
> Per comment 3 this is fixed. Comment 4 onward seem to be a complaint about
> the Blink implementation and its use of shadow DOM, which the commenter
> things is incorrect. It doesn't appear to be a spec bug. Please let us know
> if I misunderstood.

Are you saying that <span title="שלום לכם!" dir=auto>Hello there!</span> and <input placholder="שלום לכם!" value="Hello there!" dir=auto> "title" and "placholder" text by specs expected to be RTL and text/input value would be LTR because of dir=auto? If yes, then it is now only browsers issue, because currently no browsers behaviors so.
Comment 10 Aharon Lanin 2015-08-31 19:00:56 UTC
Yes, the spec expects the title & placeholder text in the example in comment 9 to be rtl, and the text inside the span/input to be ltr.

And yes, no browser implements this yet, although there seems to be some action in Mozilla and Chrome.

Please see:
https://www.w3.org/Bugs/Public/show_bug.cgi?id=17829
https://bugzilla.mozilla.org/show_bug.cgi?id=1169986
https://code.google.com/p/chromium/issues/detail?id=494553
https://bugs.webkit.org/show_bug.cgi?id=145498

I have no visibility into Microsoft, but as far as I know they have yet to implement dir=auto in IE at all :-(