reactjs - 为什么 react wai-aria 不在camelCase 中?

标签 reactjs accessibility naming-conventions wai-aria camelcasing

来自 react docs

Note that all aria-* HTML attributes are fully supported in JSX. Whereas most DOM properties and attributes in React are camelCased, these attributes should be hyphen-cased (also known as kebab-case, lisp-case, etc) as they are in plain HTML:


AFAIK,每个 HTML 属性在 react 中都被重命名为驼峰命名法。
有什么理由可以解释为什么aria-*是保留原名吗?
奖金,有没有人知道,应该是<input autoFocus='autofocus'/><input autofocus='autofocus'/> .前者看起来是正确的,因为我的编辑器没有发出任何警告。但是属性名和它的值不一致吗?
应该也是autocompleteautoComplete ,而 auto 之间没有连字符和 complete在原始属性名称中?

最佳答案

React API 引用提供了一些关于此的信息。在 DOM Elements , 它说:

In React, all DOM properties and attributes (including event handlers) should be camelCased. For example, the HTML attribute tabindex corresponds to the attribute tabIndex in React. The exception is aria-* and data-* attributes, which should be lowercased. For example, you can keep aria-label as aria-label.



栏目All Supported HTML AttributesautoCompleteautoFocus作为预期的名称。

现在,这实际上并没有回答为什么 aria-*属性仍然是小写的,但至少它清楚地说明了它们应该如何使用。

推测:也许这与 React 版本 15 和 16 之间发生的更改有关。博客文章“DOM Attributes in React 16”解释说,React 16 现在允许自定义属性,而之前已将其删除。它描述了一些担忧,即内部属性白名单已成为维护负担,需要简化。现在可以在 JSX 中包含任意属性。我不知道这在内部是如何工作的,但我想 aria-*属性在内部白名单的故事中起着一定的作用。例如,WAI-ARIA 1.1 最近引入了几个新的 aria-*属性和 WAI Personalization Semantics Content Module工作草案介绍了很多aui-*属性。这两个都需要列入白名单。

关于reactjs - 为什么 react wai-aria 不在camelCase 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52398380/

相关文章:

c# - 帮我命名这个属性 (C#)

javascript - 使用 Redux 理解 HOC

android - 如何将可访问性焦点转移到 RecyclerView 在某些操作上的第一个元素上?

javascript - 与 webpack 一起安装时未定义 React

html - 如何使仅包含图像的按钮可访问?

ios - 辅助功能Voiceover读取不带“点”的语义版本补丁

C# 类命名约定 : Is it BaseClass or ClassBase or AbstractClass

Java add() 方法约定

javascript - javascript中函数参数从哪里来?

javascript - 对作为 props 传递的函数点击使用react,HOC 会被执行多次