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
環境準備
我們還沒有檢查這個專案的環境設定檔。先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 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 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 85/100
-
area: dashboard bug perceived difficulty: 3
難度 2/5 1-3 小時 新手友好度 88/100
Nitjsefnie-Harness-Commons/daedalus#1179 ·
維護者通常 1 天內回覆
-
Aframe enhancement javascript
難度 1/5 1 小時以內 新手友好度 92/100
webarkit/Aframe-nft#17 ·
-
ai-driven-qa bug claude
難度 1/5 1 小時以內 新手友好度 75/100
linagora/twake-calendar-frontend#1434 · 1 則留言 ·
維護者通常 1 天內回覆