TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Add dir=“auto” to your inputs and textareas

397 点作者 ducaale超过 1 年前

26 条评论

drex04超过 1 年前
This is indeed an easy way to fix text rendering in your inputs and textareas. However, you&#x27;ll also need to do the same for elements that render the submitted text. And once you encounter bidirectional text (e.g. an English product name within an Arabic paragraph), that opens up another whole can of worms...<p>Note also that there&#x27;s currently a regression in Chrome that affects how RTL text is rendered in inputs with dir=&#x27;auto&#x27;. They just shipped a fix though so it should be included in the next release.
评论 #37240553 未加载
评论 #37237411 未加载
pharrington超过 1 年前
MDN always comes to the rescue: <a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;HTML&#x2F;Global_attributes&#x2F;dir" rel="nofollow noreferrer">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;HTML&#x2F;Global_att...</a>
TacticalCoder超过 1 年前
&gt; As someone living in the bubble that is the United States, it can be hard to think externally. But every so often I am reminded there is a world outside of my own.<p>There is a world outside the US but you don&#x27;t <i>have</i> to support it, depending on what your site does. I&#x27;m not american. I&#x27;m not even a native english speaker. And 99% of the sites I go to are perfectly fine if they don&#x27;t allow neither usernames nor posts containing RTL characters.<p>If it&#x27;s not solved at the browser or OS level, I&#x27;ve got about zero obligation to support this.<p>And, no, this is not about oppressing minorities.
评论 #37248211 未加载
评论 #37248062 未加载
评论 #37248643 未加载
rendall超过 1 年前
&gt; <i>The first results page of Google never lies...</i><p>I have something to tell you that will help you solve your problem, but you should sit down first, because it&#x27;s probably going to make you sad...
评论 #37241600 未加载
amluto超过 1 年前
Sadly, both the website and the linked codepen render the source quite poorly. The period is in the wrong place! The rendered HTML is fine.<p>I assume this is just the Unicode bidirectional algorithm failing, as it is wont to do. I imagine that a special cased algorithm that understood that HTML tags (the stuff between &lt; and &gt; inclusive) should render as atomic things, internally LTR, but without imposing their direction on surrounding characters.<p>In this example, the algorithm should be willing to switch direction in the middle of the sequence “.&lt;“
评论 #37237216 未加载
ssddanbrown超过 1 年前
On a related note, support for &quot;logical properties&#x2F;values&quot;[1] has become mature in recent years. These are alternatives to directional-based properties (top&#x2F;left&#x2F;bottom&#x2F;right) which are adaptable to switching content&#x2F;text directions.<p>[1] <a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;CSS&#x2F;CSS_logical_properties_and_values" rel="nofollow noreferrer">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;CSS&#x2F;CSS_logical...</a>
评论 #37240392 未加载
groby_b超过 1 年前
Uh.<p>If I search for textarea and BiDi text, in pretty much all variations I can think of <a href="https:&#x2F;&#x2F;www.w3.org&#x2F;International&#x2F;talks&#x2F;1602-oman" rel="nofollow noreferrer">https:&#x2F;&#x2F;www.w3.org&#x2F;International&#x2F;talks&#x2F;1602-oman</a> is one of the top links.<p>And right in there, the &quot;What if you don&#x27;t know the direction in advance&quot; section, <a href="https:&#x2F;&#x2F;www.w3.org&#x2F;International&#x2F;talks&#x2F;1602-oman&#x2F;#advance" rel="nofollow noreferrer">https:&#x2F;&#x2F;www.w3.org&#x2F;International&#x2F;talks&#x2F;1602-oman&#x2F;#advance</a><p>I assume the problem is that the author doesn&#x27;t really know the space, and so didn&#x27;t even know that &quot;BiDi&quot; is the right search term here. (For &quot;bi-directional text&quot;, since you don&#x27;t want to specify a writing direction)<p>I don&#x27;t even fault them for thinking &quot;the results are wrong&quot; - they aren&#x27;t, if you search for RTL they&#x27;re the right answer. But you won&#x27;t know that until you know the space a bit better. This highlights a problem with relying on the Internet for answers - it doesn&#x27;t know what you don&#x27;t know. Sit down with anybody who&#x27;s dealt with BiDi for a while, and one of their first questions will be &quot;Do you mean RTL or BiDi&quot;?<p>So, if you can, ask people, not software. Especially if you don&#x27;t know the space.
评论 #37238088 未加载
bsmth超过 1 年前
I&#x27;d also add a link here to `dirname` which is an interesting one for including text directionality of text input in form submissions: <a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;HTML&#x2F;Attributes&#x2F;dirname" rel="nofollow noreferrer">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;HTML&#x2F;Attributes...</a>
jesprenj超过 1 年前
PSA: Assume dir=&quot;auto&quot; if none provided in browsers you develop.
评论 #37238588 未加载
ketanmaheshwari超过 1 年前
Slightly related: I recently learned that vim has `:set rl` to make a text go from right to left. (`:set norl` to come back to regular)
评论 #37239200 未加载
评论 #37240604 未加载
评论 #37239482 未加载
评论 #37239058 未加载
andrewmcwatters超过 1 年前
Yeah, as far as I&#x27;m concerned, this is a deficiency of language detection. Specific types of input types should auto rtl based on the user agent&#x27;s locale usage.<p>A number of other automatic behaviors exist simply when you change your primary language, and this is one of them that should change by default. You&#x27;ll know this by experience if you speak another language and occasionally flip your primary language over. All the sites you browse start respecting your lang and locale settings.<p>Other technical or format-specific inputs should retain their relevant direction.
评论 #37238730 未加载
评论 #37248217 未加载
javajosh超过 1 年前
This is good advice, but the problem is that there is so much good advice about webdev (and everything) that one tends to form a FIFO queue in one&#x27;s brain such that the advice is inevitably lost.
miduil超过 1 年前
There is also this shortcut of ctrl+shift+x to switch to RTL. Which is really funny when you do it on Twitter since it flips the entire user interface.
评论 #37238123 未加载
评论 #37239214 未加载
评论 #37243687 未加载
评论 #37237471 未加载
lakomen超过 1 年前
Why is that not default?
评论 #37264726 未加载
评论 #37266397 未加载
bjoli超过 1 年前
I find it rather baffling that people don&#x27;t seem to spend any time reading specs. I haven&#x27;t done anything even remotely serious in HTML since about 2003, and I know about (and have used) the dir attribute.<p>it is one of maybe 12 global non-event attributes.
评论 #37266444 未加载
qingcharles超过 1 年前
OK, now does that work OK for sites that are vertical input? ;)<p><a href="http:&#x2F;&#x2F;khumuunbichig.montsame.mn&#x2F;index.php?command=newsall&amp;readnews=1170" rel="nofollow noreferrer">http:&#x2F;&#x2F;khumuunbichig.montsame.mn&#x2F;index.php?command=newsall&amp;r...</a>
distantsounds超过 1 年前
or don&#x27;t, because using fancy quotes in your HTML will have it not render properly.<p>mods, pls fix the title.
评论 #37238601 未加载
londons_explore超过 1 年前
Why in 2023 is this still an issue?<p>Frameworks and browsers should be designed that if you totally ignore rtl support, the browser&#x2F;framework just does some usable default.<p>Just like if you don&#x27;t set a font size, the browser chooses one for you. Or if you don&#x27;t specify the background color, one is chosen for you.
评论 #37236919 未加载
评论 #37236686 未加载
评论 #37237501 未加载
评论 #37237298 未加载
评论 #37238669 未加载
评论 #37238304 未加载
评论 #37237223 未加载
divbzero超过 1 年前
<i>dir</i> is a global attribute that can be set on any HTML element:<p><a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;HTML&#x2F;Global_attributes&#x2F;dir" rel="nofollow noreferrer">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;HTML&#x2F;Global_att...</a><p>What I don’t understand is why <i>dir=&quot;auto&quot;</i> isn’t set as the default value, allowing browsers to choose text direction based on the <i>lang</i> attribute or the text content.
评论 #37240274 未加载
评论 #37239958 未加载
评论 #37240422 未加载
whywhywhywhy超过 1 年前
This should be the operating systems problem to solve not developers of every website ever. Same with spellchecking, emojis, copy&#x2F;paste etc.
评论 #37238040 未加载
评论 #37237285 未加载
ssdspoimdsjvv超过 1 年前
It always bugs me in CSS and HTML that &quot;auto&quot; does not equal &quot;default&quot;
评论 #37238029 未加载
评论 #37238338 未加载
bad_alloc超过 1 年前
To the people wondering why this is still an issue: Most tech is very US- or west-centered. My name contains an Umlaut (ü), which causes me trouble much more often than should be the case. A colleague of mine even changed their name by substituting ä foe ae, to avoid this issue. We still have the benefit of mostly ASCII names mind you. It can get a lot worse.
评论 #37239949 未加载
评论 #37239597 未加载
评论 #37240426 未加载
crazygringo超过 1 年前
This seems like an odd thing for developers to have to do.<p>Why isn&#x27;t it done by default by the browser? What <i>is</i> the browser default? (Strangely, MDN docs don&#x27;t seem to indicate.) And if it&#x27;s not already this, why not?
评论 #37239302 未加载
wnoise超过 1 年前
Why isn&#x27;t this the default?
评论 #37238729 未加载
评论 #37237681 未加载
tracker1超过 1 年前
Seems to me, that should be the default behavior.
评论 #37238934 未加载
Pxtl超过 1 年前
It is so ridiculous that this doesn&#x27;t happen by default. Normally I&#x27;m against breaking changes, but in this case? The default is dumb and wrong. Inclusivity should always be the starting point, and manual hacks should be the exception.
评论 #37238947 未加载