JSX: disabled should accept true/false instead of `unit`
Nobody has claimed this yet.
- Dominant language
- OCaml
- Stars
- 179
- Forks
- 63
- Avg merge
- 5h
- Merged PRs (30d)
- 22
Description
Given this code:
<button disabled={()}> "my button" </button>
To have a button that isn't disabled, I have to duplicate the code logic or use pure function syntax instead of doing it directly in JSX syntax.
Update: This is a very awkward Button component that were written to allow this:
module Button = {
open Tyxml.Html;
let createElement = (~title=?, ~cls=?, ~disabled=?, ~children, ()) => {
let a = {
let or_append = (value, cb, attrs) => {
switch (value) {
| None => attrs
| Some(value) => [cb(value), ...attrs]
};
};
let attrs = [];
let attrs =
attrs
|> or_append(title, title => a_title(title))
|> or_append(cls, cls => a_class(cls));
let attrs =
switch (disabled) {
| Some(true) => [a_disabled(), ...attrs]
| Some(false)
| None => attrs
};
attrs;
};
button(~a, children);
};
};
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how JSX attributes reach Tyxml.Html, using the disabled attribute in the issue and the Button.createElement example as entry points. Determine where disabled currently accepts unit and how boolean values should map to the generated attribute. Done means JSX accepts true/false without duplicated component logic and preserves the enabled-button behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ocaml
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100