brazier/attribute

Types

An attribute or event listener on an element.

pub opaque type Attribute(msg)

Values

pub fn action(url: String) -> Attribute(msg)
pub fn alt(text: String) -> Attribute(msg)
pub fn aria(name: String, value: String) -> Attribute(msg)

An aria-<name> attribute.

pub fn attribute(name: String, value: String) -> Attribute(msg)

An attribute with any name.

These are programming errors and crash:

  • an inline event attribute such as onclick: use brazier/event;
  • srcdoc: use unsafe_srcdoc;
  • a data-brazier-* name, which Brazier’s client reads and only the render sets (data-brazier-key for element.keyed, data-brazier-stream for brazier/stream.render, data-brazier-on-* for brazier/event, and the others the client uses). Four are app API and allowed: data-brazier-hook (hook), data-brazier-hook-watch (watch), data-brazier-preserve-children (ignore_updates) and data-brazier-external (a link the client does not navigate);
  • attributeName with a value containing href (href, xlink:href): an SVG <animate> or <set> targeting a link’s URL would change it after the URL policy has checked it;
  • a name with characters outside a-z A-Z 0-9 - _ : ..

Names match case-insensitively, as HTML attribute names do.

URL attributes (href, src, action, formaction, poster, cite, xlink:href) go through the URL policy. A refused value produces no attribute and logs a warning.

pub fn autofocus(on: Bool) -> Attribute(msg)
pub fn boolean(name: String, on: Bool) -> Attribute(msg)

A boolean attribute: present with an empty value when on is true, absent otherwise. A name attribute refuses crashes either way.

pub fn checked(on: Bool) -> Attribute(msg)
pub fn cite(url: String) -> Attribute(msg)
pub fn class(name: String) -> Attribute(msg)
pub fn classes(names: List(#(String, Bool))) -> Attribute(msg)

Several classes, each included when its flag is true.

pub fn cols(cols: Int) -> Attribute(msg)
pub fn data(name: String, value: String) -> Attribute(msg)

A data-<name> attribute. data("brazier-key", ..) and the other reserved data-brazier-* names crash, as in attribute.

pub fn disabled(on: Bool) -> Attribute(msg)
pub fn draggable(on: Bool) -> Attribute(msg)
pub fn for(id: String) -> Attribute(msg)
pub fn formaction(url: String) -> Attribute(msg)
pub fn hook(name: String) -> Attribute(msg)

Attach a client hook registered with Brazier.hooks in JavaScript. LiveView’s phx-hook.

pub fn href(url: String) -> Attribute(msg)
pub fn id(id: String) -> Attribute(msg)
pub fn ignore_updates() -> Attribute(msg)

Leave this element’s children to client code: the client morph does not touch them after the first render. LiveView’s phx-update="ignore".

pub fn map(
  attribute: Attribute(a),
  f: fn(a) -> b,
) -> Attribute(b)

Map the message of an event listener. Plain attributes are unchanged.

pub fn max(value: String) -> Attribute(msg)
pub fn method(method: String) -> Attribute(msg)
pub fn min(value: String) -> Attribute(msg)
pub fn name(name: String) -> Attribute(msg)
pub fn none() -> Attribute(msg)

An attribute that renders nothing.

pub fn placeholder(text: String) -> Attribute(msg)
pub fn poster(url: String) -> Attribute(msg)
pub fn readonly(on: Bool) -> Attribute(msg)
pub fn rel(rel: String) -> Attribute(msg)
pub fn required(on: Bool) -> Attribute(msg)
pub fn role(role: String) -> Attribute(msg)
pub fn rows(rows: Int) -> Attribute(msg)
pub fn selected(on: Bool) -> Attribute(msg)
pub fn src(url: String) -> Attribute(msg)
pub fn step(value: String) -> Attribute(msg)
pub fn style(property: String, value: String) -> Attribute(msg)

One inline style declaration. Several style attributes on the same element are joined with ;.

pub fn styles(
  properties: List(#(String, String)),
) -> Attribute(msg)

Several inline style declarations as one style attribute, in order. An empty list adds no attribute. Like style, it joins with any other style attributes on the same element.

pub fn tabindex(index: Int) -> Attribute(msg)
pub fn target(target: String) -> Attribute(msg)
pub fn title(text: String) -> Attribute(msg)
pub fn type_(type_: String) -> Attribute(msg)
pub fn unsafe_srcdoc(html: String) -> Attribute(msg)

An <iframe> srcdoc attribute: html is the whole document the iframe shows. Its markup is not escaped or checked, and unless the iframe has a sandbox attribute without allow-scripts and allow-same-origin together, its scripts run with the page’s origin. Like element.unsafe_raw_html, never pass it text that a user controls.

The value is attribute-escaped, as every value is; the browser decodes it back to html.

pub fn value(value: String) -> Attribute(msg)
pub fn watch(attributes: List(String)) -> Attribute(msg)

Attribute names whose changes call the hook’s updated callback, even when the element’s children are ignored.

✨ Search Document