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
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
Values
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.
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 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 draggable(value: Bool) -> Attribute
Specifies whether the element is draggable. Part of HTML Drag and Drop API.
Documentation
pub fn enter_key_hint(value: String) -> Attribute
Specifies which action to present for the enter key on virtual keyboards.
Documentation
pub fn form_action_(
handler: fn(form_data.FormData) -> Nil,
) -> Attribute
[Documentation](/// Documentation
pub fn hidden(value: Bool) -> Attribute
Specifies whether the element should be hidden.
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 none() -> Attribute
none
will not appear in HTML attributes. Use it for conditional rendering.
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 role(value: String) -> Attribute
Specifies the element role explicitly for assistive technologies.
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 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 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 type_(name: String) -> Attribute