React.Basic: how to use unsupported attributes?


I’m trying to create a Bootstrap 4 navbar in my React.Basic application.

Unfortunately, this requires use of some attributes which are unsupported by React.Basic, e.g. data-toggle, etc., as shown in this extract from

  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>

My naive attempt doesn’t work, and simply omitting these attributes fails to give satisfactory menu behaviour. Here’s the extract from my PureScript component:

    , R.button
      { className: "navbar-toggler"
      , type: "button"
      --, dataToggle: "collapse"
      --, dataTarget: "#navbarSupportedContent"
      --, ariaControls: "navbarSupportedContent"
      --, ariaExpanded: "false"
      --, ariaLabel: "Toggle navigation"
      , children: [ R.span { className: "navbar-toggler-icon" } ]

Is there some escape hatch in React.Basic for creating such components?


I think you should be able to do this with unsafeCreateDOMComponent:

element (unsafeCreateDOMComponent "button")
  { className: "navbar-toggler"
  , type: "button"
  , dataToggle: "collapse"


Thanks! That did the trick, once I realised I also had to quote the hyphen-separated attribute names, because there’s no automatic mapping of camelCase to kebab-case for these unsupported attributes.

    , element (unsafeCreateDOMComponent "button")
      { className: "navbar-toggler"
      , type: "button"
      , "data-toggle": "collapse"
      , "data-target": "#navbarSupportedContent"
      , "aria-controls": "navbarSupportedContent"
      , "aria-expanded": "false"
      , "aria-label": "Toggle navigation"
      , children: [ R.span { className: "navbar-toggler-icon" } ]