ocsigen / ocsigen/tyxml

JSX: disabled should accept true/false instead of `unit`

Open
#289 1 comment 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.