Allow arbitrary data-* attributes on DOM elements in JSX
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 48/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- react
- 领域
- frontend
调研方向
首先检查 JsxDOM.domProps 和 JSX 属性验证逻辑,提案将它们确定为相关区域。使用静态和变量 data-* 值,通过小写 DOM 元素验证预期行为;当任意 data-* 属性无需扩展 JsxDOM.domProps 或使用自定义 JSX 模块即可编译时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Problem
Currently data-* attributes cannot be used directly on HTML elements in ReScript JSX.
Example:
<input data-component="true" />
This produces the compiler error:
The field data-component does not belong to type JsxDOM.domProps
To use data-* attributes developers currently need to:
- extend
JsxDOM.domProps - implement a custom JSX module
- bypass JSX with
React.createElement
This introduces unnecessary complexity for a very common HTML pattern and reduces JSX ergonomics.
Context
data-* attributes are part of the HTML standard and are widely used across the React ecosystem for:
- CSS state selectors
- design-system variants
- testing hooks (
data-testid) - UI libraries such as Radix UI, Headless UI, and similar component systems
Example commonly used in modern component libraries:
<button data-state="open" data-variant="primary" />
CSS:
button[data-state="open"] {
background: green;
}
This pattern is heavily used in modern design systems and utility-CSS ecosystems because it allows component state to be expressed declaratively and consumed by CSS.
Proposal
Allow arbitrary attributes matching the pattern:
data-*
on lowercase DOM elements in JSX without requiring them to be explicitly declared in JsxDOM.domProps.
This could be implemented as a special case in JSX attribute validation.
Benefits
- better interoperability with the React ecosystem
- easier migration of existing React / TypeScript codebases
- simpler implementation of design systems
- avoids the need for custom JSX infrastructure for a standard HTML feature
Expected developer experience
Developers should be able to write JSX like this without additional configuration:
<button data-state="open" data-variant="primary" />
In real-world usage these attributes often contain values coming from ReScript variables, component props, or state:
@react.component
let make = (~variant: string, ~isOpen: bool, ~count: int) => {
<button
data-state={isOpen ? "open" : "closed"}
data-variant={variant}
data-count={count}
>
{React.string("Click")}
</button>
}
This pattern is widely used in React codebases and design systems, where data-* attributes act as a bridge between component state and CSS.
- 主要语言
- ReScript
- 星标
- 517
- 派生
- 45
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rescript-lang/rescript-react 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
rescript-lang/rescript-react#145 ·
-
难度 5/5 一周以上 新手友好度 45/100
rescript-lang/rescript-react#147 · 2 条评论 ·
-
难度 5/5 一周以上 新手友好度 25/100
rescript-lang/rescript-react#111 · 3 条评论 ·
-
难度 4/5 3-5 天 新手友好度 25/100
rescript-lang/rescript-react#105 ·
-
难度 5/5 一周以上 新手友好度 25/100
rescript-lang/rescript-react#104 · 1 个 reaction ·
查看 rescript-lang/rescript-react 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
n0-computer/iroh#4550 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
nightscout/nocturne#1425 ·
-
ui/ux
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 75/100
docToolchain/docToolchain#1705 ·