rescript-lang / rescript-lang/rescript-react
Allow arbitrary data-* attributes on DOM elements in JSX
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- ReScript
- Star
- 517
- Fork
- 45
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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.
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách xem xét JsxDOM.domProps và logic xác thực thuộc tính JSX, những phần được đề xuất xác định là các khu vực liên quan. Xác minh hành vi mong đợi với các phần tử DOM viết thường bằng cách sử dụng các giá trị data-* tĩnh và biến; được coi là hoàn tất khi các thuộc tính data-* tùy ý có thể được biên dịch mà không mở rộng JsxDOM.domProps hoặc sử dụng một mô-đun JSX tùy chỉnh.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- react
- Lĩnh vực
- frontend
- Loại issue
- Tính năng
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 48/100