Fmlib_browser.AttributeAttributes of Dom Elements.
There are four types of attributes:
Sometimes the distinction between properties and attributes is quite subtle. To the best of my knowledge each added attribute adds a property with the same name (except when the name is a javascript keyword like "class") to the html element. But not all properties even if it is a string value adds an attribute to the element.
There are many specific attributes which can shadow names. See the corresponding chapter in Html.
val style : string -> string -> 'msg tstyle key value Add a style attribute to the html element.
Examples:
style "color" "red"
style "margin" "20px"val class_ : string -> 'msg tclass_ value specifies a CSS class.
NOTE: Currently this should not be used in combination with class_list. If both attributes are used, they overwrite each other.
val class_list : (string * bool) list -> 'msg tclass_list classes
Allows conveniently specifying multiple classes. Each class comes with a condition and is only added to the element if that condition is true.
Example:
let view_contact (c: contact): msg Html.t =
div
[
class_list
[
("contact", true);
("contact-favourite", c.is_favourite);
("contact-online", c.status = Online);
("contact-offline", c.status = Offline);
("contact-busy", c.status = Busy);
]
]
[
text c.full_name
]NOTE: Currently this should not be used in combination with class_. If both attributes are used, they overwrite each other.
property key value Add a javascript property to the html element.
val attribute : string -> string -> 'msg tattribute key value Add an attribute to the html element.
Examples:
attribute "id" "my_element"
attribute "class" "container"val handler :
string ->
Event_flag.stop ->
Event_flag.prevent ->
'msg Decoder.t ->
'msg thandler event_type stop_flag prevent_flag decoder
Attribute representing an event listener on an html element. The two flags decide if the event is propagated upwards in the dom tree and if default action (some events like clicking on an anchor element cause default actions in the browser) is prevented.
The decoder decodes the javascript event object into a message of type 'msg.
Starting from the event object information from the whole dom tree up to the root can be decoded. Each event object has a target (which is the element on which it is fired). The target element has a tag name, can have various properties etc. For more details on event objects see the event api.
The function handler is the most generic function to add an event handler to a dom element. All specific handler below are implemented using this generic function.
map f a Map an attribute creating messages of type 'a to an attribute creating messages of type 'b.
Some often used handlers. More complex handler can be implemented by using handler.
on event_type decoder
is equivalent to handler event_type Event_flag.no_stop Event_flag.no_prevent decoder
val on_click : 'msg -> 'msg ton_click m produce the message m on mouse click.
val on_mouseenter : 'msg -> 'msg ton_mouseenter m Produce the message m when the mouse enters the element.
val on_mouseleave : 'msg -> 'msg ton_mouseleave m Produce the message m when the mouse leaves the element.
val on_keydown : (string -> 'msg) -> 'msg ton_keydown f
Produce the message f key on the keydown event with key.
val on_keyup : (string -> 'msg) -> 'msg ton_keyup f
Produce the message f key on the keyup event with key.
val on_input : (string -> 'msg) -> 'msg tval accept : string -> 'msg tval accept_charset : string -> 'msg tval accesskey : string -> 'msg taccesskey value
Keyboard shortcut to activate or add focus to the element.
Elements: all
val action : string -> 'msg tval alpha : bool -> 'msg tval alt : string -> 'msg tval autocapitalize : string -> 'msg tautocapitalize value
Sets whether input is automatically capitalized when entered by user.
Elements: all
val autocomplete : string -> 'msg tautocomplete value
Indicates whether controls in this form can have their values automatically completed by the browser.
Elements: <form>, <input>, <select>, <textarea>
val autoplay : bool -> 'msg tval capture : string -> 'msg tcapture value
Specifies that file contents should be captured from a camera and/or microphone. Applies to type="file" input elements.
Elements: <input>
val checked : bool -> 'msg tchecked value
Indicates whether the checkbox (a type="checkbox" input element) should be checked. This not only sets the initial value of the input element, but also allows overriding the value after the user edited it.
Elements: <input>
val cite : string -> 'msg tcite value
Contains a URI which points to the source of the quote or change.
Elements: <blockquote>, <del>, <ins>, <q>
val colorspace : string -> 'msg tval cols : int -> 'msg tval colspan : int -> 'msg tval contenteditable : string -> 'msg tcontenteditable value
Indicates whether the element's content is editable.
Elements: all
val controls : bool -> 'msg tval coords : string -> 'msg tval crossorigin : string -> 'msg tval csp : string -> 'msg tcsp value
Specifies the Content Security Policy that an embedded document must agree to enforce upon itself.
Elements: <iframe>
val datetime : string -> 'msg tval decoding : string -> 'msg tval default : bool -> 'msg tdefault value
Indicates that the track should be enabled unless the user's preferences indicate something different.
Elements: <track>
val dir : string -> 'msg tdir value
Defines the text direction.
Elements: all
val dirname : string -> 'msg tdirname value
Specifies the name of a field that will contain the automatically determined text direction, when a form is submitted.
Elements: <input>, <textarea>
val disabled : bool -> 'msg tdisabled value
Indicates whether the user can interact with the element.
Elements: <button>, <fieldset>, <input>, <optgroup>, <option>, <select>, <textarea>
val download : string -> 'msg tval draggable : string -> 'msg tdraggable value
Defines whether the element can be dragged.
Elements: all
val enctype : string -> 'msg tval enterkeyhint : string -> 'msg tenterkeyhint value
Specifies what action label (or icon) to present for the enter key on virtual keyboards.
Elements: <textarea>, elements with "contenteditable" set
val elementtiming : string -> 'msg tval for_ : string -> 'msg tval form : string -> 'msg tform value
Indicates the form that is the owner of the element.
Elements: <button>, <fieldset>, <input>, <object>, <output>, <select>, <textarea>
val formaction : string -> 'msg tval formenctype : string -> 'msg tval formmethod : string -> 'msg tval formnovalidate : bool -> 'msg tformnovalidate value
Specifies that the form should not be validated when it is submitted. Overrides the form's novalidate attribute.
val formtarget : string -> 'msg tval headers : string -> 'msg tval height : int -> 'msg thidden value
Prevents rendering the element.
Elements: all
val hreflang : string -> 'msg tval id : string -> 'msg tid value
A unique value identifying the element.
Elements: all
val inputmode : string -> 'msg tinputmode value
Provides a hint about the type of data a user can enter.
Elements: <textarea>, elements with "contenteditable" set
val ismap : bool -> 'msg tval itemprop : string -> 'msg titemprop value
Allows adding properties to an item.
Elements: all
val label : string -> 'msg tval lang : string -> 'msg tlang value
Defines the language used in the element.
Elements: all
val loading : string -> 'msg tval list : string -> 'msg tval loop : bool -> 'msg tval max : string -> 'msg tval maxlength : int -> 'msg tmaxlength value
Defines the maximum number of characters allowed in the element.
Elements: <input>, <textarea>
val minlength : int -> 'msg tminlength value
Defines the minimum number of characters allowed in the element.
Elements: <input>, <textarea>
val media : string -> 'msg tval method_ : string -> 'msg tval multiple : bool -> 'msg tval muted : bool -> 'msg tval name : string -> 'msg tname value
Name of the element.
Elements: <button>, <form>, <fieldset>, <iframe>, <input>, <object>, <output>, <select>, <textarea>, <map>
val novalidate : bool -> 'msg tval open_ : bool -> 'msg tval pattern : string -> 'msg tpattern value
Defines a regular expression which the element's value will be validated against.
Elements: <input>
val ping : string -> 'msg tval placeholder : string -> 'msg tplaceholder value
Provides a hint to the user of what can be entered in the field.
Elements: <input>, <textarea>
val playsinline : bool -> 'msg tplaysinline value
Indicates that the video is to be played "inline"; that is, within the element's playback area.
Elements: <video>
val poster : string -> 'msg tval preload : string -> 'msg tval readonly : bool -> 'msg tval referrerpolicy : string -> 'msg tval rel : string -> 'msg tval required : bool -> 'msg trequired value
Indicates whether this element is required to fill out or not.
Elements: <input>, <select>, <textarea>
val reversed : bool -> 'msg treversed value
Indicates whether the list should be displayed in a descending order instead of an ascending order.
Elements: <ol>
val role : string -> 'msg trole value
Defines an explicit role for an element for use by assistive technologies.
Elements: all
val rows : int -> 'msg tval rowspan : int -> 'msg tval sandbox : string -> 'msg tval scope : string -> 'msg tval selected : bool -> 'msg tval size : int -> 'msg tval sizes : string -> 'msg tval span : int -> 'msg tval spellcheck : string -> 'msg tspellcheck value
Indicates whether spell checking is allowed for the element.
Elements: all
val src : string -> 'msg tval srcdoc : string -> 'msg tval srcset : string -> 'msg tval start : int -> 'msg tval step : float -> 'msg tval tabindex : int -> 'msg ttabindex value
Overrides the browser's default tab order and follows the one specified instead.
Elements: all
val target : string -> 'msg tval title : string -> 'msg ttitle value
Text to be displayed in a tooltip when hovering over the element.
Elements: all
val translate : string -> 'msg ttranslate value
Specifies whether the elements attribute values and text contents should be translated by automatic translation systems.
Elements: all
val type_ : string -> 'msg tval usemap : string -> 'msg tusemap value
The partial URL (starting with #) of an image map associated with the element.
Elements: <img>
val value : string -> 'msg tvalue value
Defines the value of the element. This not only sets the initial value of the input element, but also allows overriding the value after the user edited it.
Elements: <input>
val width : int -> 'msg tval wrap : string -> 'msg tval font_size : string -> 'msg tExample font_size "20px"
Abbreviates style "font-size" "20px".
val color : string -> 'msg tExample color "red"
Abbreviates style "color" "red".
val background_color : string -> 'msg tExample background_color "powderblue"
Abbreviates style "background-color" "powderblue".
+--------------------------------+
| margin |
| +----border-----------------+ |
| | padding | |
| | +---------------------+ | |
| | | | | |
| | | | | |
| | | content | | |
| | | | | |
| | +---------------------+ | |
| +---------------------------+ |
| |
+--------------------------------+val margin : string -> 'msg tExamples
margin "25px"
margin "25px 50px" top/bottom 25px, left/right 50px
margin "25px 50px 75px 100px" top, right, bottom, leftmargin str abbreviates style "margin" str
val padding : string -> 'msg tExamples
padding "25px"
padding "25px 50px" top/bottom 25px, left/right 50px
padding "25px 50px 75px 100px" top, right, bottom, leftpadding str abbreviates style "padding" str
val border_style : string -> 'msg tExamples
border_style "solid"
border_style "dotted"
border_style "dashed"border_style str abbreviates style "border-style" str
val border_width : string -> 'msg tExamples
border_width "3px"
border_width "thick"
border_width "medium"val border_color : string -> 'msg tExample
border_color "red"