redraw/dom/attribute

Implementation for HTML and SVG attributes usable in React and in browser. Contrarily to Lustre, every attributes can take arbitrary data, because they’re directly bind in the underlying component’s props.

All available attributes can be found in the React.dev documentation for detailed information, as well as on MDN.

Types

Attribute linked on an HTML or SVG node. Think about like a prop in React.

pub opaque type Attribute

Directionality of an element text.

pub type Dir {
  Ltr
  Rtl
}

Constructors

  • Ltr
  • Rtl

Inner HTML data are HTML that will not be verified sanitized. Be careful when using it. You should almost always prefer to use redraw/element/html.

pub type InnerHTML

Translate of a translatable element.

pub type Translate {
  Yes
  No
}

Constructors

  • Yes
  • No

Values

pub fn accept(types: List(String)) -> Attribute
pub fn accept_charset(types: List(String)) -> Attribute
pub fn access_key(value: String) -> Attribute
pub fn action(url: String) -> Attribute
pub fn action_(
  handler: fn(form_data.FormData) -> Nil,
) -> Attribute
pub fn alt(value: String) -> Attribute
pub fn aria(key: String, value: String) -> Attribute

Set aria attribute on the node. Should be used like aria("valuenow", "75").

pub fn attribute(key: String, content: a) -> Attribute

Generic attribute. key will be the key in the HTML attributes as-is, while content can be anything. content will be converted by React to strings, so be careful to not send complicated data structure, but booleans, strings numbers, etc. are plainly supported.

Documentation

pub fn auto_capitalize(value: String) -> Attribute
pub fn autocomplete(name: String) -> Attribute
pub fn autofocus(should_autofocus: Bool) -> Attribute
pub fn autoplay(should_autoplay: Bool) -> Attribute
pub fn checked(is_checked: Bool) -> Attribute
pub fn class(value: String) -> Attribute
pub fn class_name(value: String) -> Attribute

Alias of class.
Documentation

pub fn cols(val: Int) -> Attribute
pub fn content_editable(value: Bool) -> Attribute

If true, the browser lets the user edit the rendered element directly. This is used to implement rich text input libraries like Lexical. React warns if you try to pass React children to an element with content_editable(True) because React will not be able to update its content after user edits.
Documentation

pub fn controls(visible: Bool) -> Attribute
pub fn dangerously_set_inner_html(
  inner_html: InnerHTML,
) -> Attribute

Overrides the innerHTML property of the DOM node and displays the passed HTML inside. This should be used with extreme caution! If the HTML inside isn’t trusted (for example, if it’s based on user data), you risk introducing an XSS vulnerability.
Documentation

pub fn data(key: String, value: String) -> Attribute

Data attributes let you attach some string data to the element, for example data("fruit", "banana"). In React, they are not commonly used because you would usually read data from props or state instead.
Documentation

pub fn dir(value: Dir) -> Attribute

Specifies the text direction of the element.
Documentation

pub fn disabled(is_disabled: Bool) -> Attribute
pub fn download(filename: String) -> Attribute
pub fn draggable(value: Bool) -> Attribute

Specifies whether the element is draggable. Part of HTML Drag and Drop API.
Documentation

pub fn enctype(value: String) -> Attribute
pub fn enter_key_hint(value: String) -> Attribute

Specifies which action to present for the enter key on virtual keyboards.
Documentation

pub fn for(value: String) -> Attribute

For

pub fn form_action(action: String) -> Attribute
pub fn form_action_(
  handler: fn(form_data.FormData) -> Nil,
) -> Attribute

[Documentation](/// Documentation

pub fn form_enctype(value: String) -> Attribute
pub fn form_method(method: String) -> Attribute
pub fn form_novalidate(value: Bool) -> Attribute
pub fn form_target(target: String) -> Attribute
pub fn height(val: Int) -> Attribute
pub fn hidden(value: Bool) -> Attribute

Specifies whether the element should be hidden.
Documentation

pub fn href(url: String) -> Attribute
pub fn html_for(value: String) -> Attribute

Alias of for.
Documentation

pub fn id(value: String) -> Attribute

Specifies a unique identifier for this element, which can be used to find it later or connect it with other elements. Generate it with useId to avoid clashes between multiple instances of the same component.
Documentation

pub fn inner_html(html: String) -> InnerHTML

The inner_html data should be created as close to where the HTML is generated as possible. This ensures that all raw HTML being used in your code is explicitly marked as such, and that only variables that you expect to contain HTML are passed to dangerously_set_inner_html. It is not recommended to create the object inline like html.div([attribute.dangerously_set_inner_html(attribute.inner_html(markup))], [])
Documentation

pub fn input_mode(value: String) -> Attribute

Specifies what kind of keyboard to display (for example, text, number or telephone).
Documentation

pub fn is(value: String) -> Attribute

If specified, the component will behave like a custom element.
Documentation

pub fn item_prop(value: String) -> Attribute

Specifies which property the element represents for structured data crawlers.
Documentation

pub fn lang(value: String) -> Attribute

Specifies the language of the element.
Documentation

pub fn loop(should_loop: Bool) -> Attribute
pub fn max(val: String) -> Attribute
pub fn method(method: String) -> Attribute
pub fn min(val: String) -> Attribute
pub fn msg(uri: String) -> Attribute
pub fn name(name: String) -> Attribute
pub fn none() -> Attribute

none will not appear in HTML attributes. Use it for conditional rendering.

pub fn novalidate(value: Bool) -> Attribute
pub fn open(is_open: Bool) -> Attribute
pub fn pattern(regex: String) -> Attribute
pub fn placeholder(text: String) -> Attribute
pub fn readonly(is_readonly: Bool) -> Attribute
pub fn ref(ref: redraw.Ref(option.Option(a))) -> Attribute

A ref object from redraw.use_ref. Your ref will be filled with the DOM element for this node. Contrarily to JS React, when using a Ref, you’re forced to use an optional type here. Because when using this function, you want to get a reference from a real DOM node, meaning at the initialization of the reference, you won’t have any data. Use ref_ when you want full control over the ref you send to the Component.
Documentation

pub fn ref_(ref: fn(a) -> Nil) -> Attribute

A ref callback function. The callback will be provided with the DOM element for this node. Use this function to get control on the ref provided by the DOM node or the component.
Documentation

pub fn rel(relationship: String) -> Attribute
pub fn required(is_required: Bool) -> Attribute
pub fn role(value: String) -> Attribute

Specifies the element role explicitly for assistive technologies.

pub fn rows(val: Int) -> Attribute
pub fn selected(is_selected: Bool) -> Attribute
pub fn slot(value: String) -> Attribute

Specifies the slot name when using shadow DOM.
Documentation

pub fn spell_check(value: Bool) -> Attribute

If explicitly set to true or false, enables or disables spellchecking.
Documentation

pub fn src(value: String) -> Attribute
pub fn step(val: String) -> Attribute
pub fn style(styles: List(#(String, String))) -> Attribute
pub fn suppress_content_editable_warning(
  value: Bool,
) -> Attribute

If True, suppresses the warning that React shows for elements that both have children and content_editable(True) (which normally do not work together). Use this if you’re building a text input library that manages the contentEditable content manually.

pub fn suppress_hydration_warning(value: Bool) -> Attribute

If you use server rendering, normally there is a warning when the server and the client render different content. In some rare cases (like timestamps), it is very hard or impossible to guarantee an exact match. If you set suppressHydrationWarning to true, React will not warn you about mismatches in the attributes and the content of that element. It only works one level deep, and is intended to be used as an escape hatch. Don’t overuse it. Read about suppressing hydration errors.

pub fn tab_index(value: Int) -> Attribute

Overrides the default Tab button behavior. Avoid using values other than -1 and 0.
Documentation

pub fn target(value: String) -> Attribute
pub fn title(value: String) -> Attribute

Specifies the tooltip text for the element.
Documentation

pub fn translate(value: Translate) -> Attribute

Passing No excludes the element content from being translated.
Documentation

pub fn width(val: Int) -> Attribute
pub fn wrap(mode: String) -> Attribute
Search Document