command
elementtype
label
icon
disabled
checked
radiogroup
title
attribute has special semantics on this element.interface HTMLCommandElement : HTMLElement { attribute DOMString type; attribute DOMString label; attribute DOMString icon; attribute boolean disabled; attribute boolean checked; attribute DOMString radiogroup;};
The command
element represents a command that the user can invoke.
A command can be part of a context menu or toolbar, using the menu
element, or can be put anywhere else in the page, to define a keyboard shortcut.
The type
attribute indicates the kind of command: either a normal command with an associated action, or a state or option that can be toggled, or a selection of one item from a list of items.
The attribute is an enumerated attribute with three keywords and states. The "command
" keyword maps to the Command state, the "checkbox
" keyword maps to the Checkbox state, and the "radio
" keyword maps to the Radio state. The missing value default is the Command state.
The element represents a normal command with an associated action.
The element represents a state or option that can be toggled.
The element represents a selection of one item from a list of items.
The label
attribute gives the name of the command, as shown to the user. The label
attribute must be specified and must have a value that is not the empty string.
The title
attribute gives a hint describing the command, which might be shown to the user to help him.
The icon
attribute gives a picture that represents the command. If the attribute is specified, the attribute's value must contain a valid non-empty URL potentially surrounded by spaces.
The disabled
attribute is a boolean attribute that, if present, indicates that the command is not available in the current state.
The distinction between disabled
and is subtle. A command would be disabled if, in the same context, it could be enabled if only certain aspects of the situation were changed. A command would be marked as hidden if, in that situation, the command will never be enabled. For example, in the context menu for a water faucet, the command "open" might be disabled if the faucet is already open, but the command "eat" would be marked hidden since the faucet could never be eaten.
The checked
attribute is a boolean attribute that, if present, indicates that the command is selected. The attribute must be omitted unless the type
attribute is in either the Checkbox state or the Radio state.
The radiogroup
attribute gives the name of the group of commands that will be toggled when the command itself is toggled, for commands whose type
attribute has the value "radio
". The scope of the name is the child list of the parent element. The attribute must be omitted unless the type
attribute is in the Radio state.
The type
IDL attribute must reflect the content attribute of the same name, limited to only known values.
The label
, icon
, disabled
, checked
, and radiogroup
IDL attributes must reflect the respective content attributes of the same name.
command
elements are not rendered unless they form part of a menu.
Here is an example of a toolbar with three buttons that let the user toggle between left, center, and right alignment. One could imagine such a toolbar as part of a text editor. The toolbar also has a separator followed by another button labeled "Publish", though that button is disabled.
<menu type="toolbar"> <command type="radio" radiogroup="alignment" checked="checked" label="Left" icon="icons/alL.png" onclick="setAlign('left')"> <command type="radio" radiogroup="alignment" label="Center" icon="icons/alC.png" onclick="setAlign('center')"> <command type="radio" radiogroup="alignment" label="Right" icon="icons/alR.png" onclick="setAlign('right')"> <hr> <command type="command" disabled label="Publish" icon="icons/pub.png" onclick="publish()"> </menu>