This page is still under construction.
This section outlines the various widgets and controls that are defined in XUL. It does not attempt to cover the basic layout containers (box, stack, grid and popup), nor does it attempt to cover the specialized document root containers (window, wizard, dialog, page and overlay). Layout is covered in section 2, and the root elements are covered in section 4 (not yet completed).
interface XULElement : Element { attribute DOMString id; attribute DOMString className; // Layout properties attribute DOMString align; attribute DOMString dir; attribute DOMString flex; attribute DOMString ordinal; attribute DOMString orient; attribute DOMString pack; // Properties for hiding elements. attribute boolean hidden; attribute boolean collapsed; // Property for hooking up to broadcasters attribute DOMString observes; // Properties for hooking up to popups attribute DOMString menu; attribute DOMString contextMenu; attribute DOMString tooltip; // Width/height properties attribute DOMString width; attribute DOMString height; attribute DOMString minWidth; attribute DOMString minHeight; attribute DOMString maxWidth; attribute DOMString maxHeight; // Position properties attribute DOMString left; attribute DOMString top; // Tooltip and status info attribute DOMString tooltipText; attribute DOMString statusText; attribute boolean allowEvents; // RDF Properties attribute DOMString ref; attribute DOMString datasources; // Persistence attribute DOMString persist; readonly attribute CSSStyleDeclaration style; NodeList getElementsByAttribute(DOMString name, DOMString value); };
id
className
align
dir
flex
ordinal
orient
pack
hidden
collapsed
observes
menu, contextMenu, tooltip
width, minWidth, maxWidth
height, minHeight, maxHeight
tooltipText
statusText
allowEvents
style
getElementsByAttribute
name
of type DOMString
value
of type DOMString
NodeList
View the remaining desc/label compliance issues in Bugzilla.
View the description/label test page (only works in Mozilla)
The description is one of the basic building blocks of XUL and is defined using the description tag. It is typically used in dialogs to provide explanatory text that describes the purpose of a given UI element.
A description is nothing more than a specialized CSS2 block. As such, it obeys all of the rules of blocks and can contain arbitrary markup.
<description style="border:1px solid red; width: 100px"> This text can be <html:b>bold</html:b> and can wrap to several lines. </description>
For simple single-line descriptions that contain no markup, a shorthand syntax is available. The value attribute can be used to specify the text of the description.
<description style="border:1px solid blue" value="Single line description with no markup allowed."/>
Most XUL widgets (e.g., buttons, menus, trees, etc.) operate under similar principles. Namely they are capable of containing arbitrary markup, but they also support a shorthand syntax using attributes.
[Editor's Note: In Mozilla, there are two deprecated tags used to describe descriptions: text and html. These two tags have been consolidated into the single description tag.]
Single line descriptions support text cropping through the use of the crop attribute. Its possible values are start, center and end. A description will be cropped if the computed width of the description exceeds the description's preferred width (as determined by the XUL layout system).
In all three cases (start, center, and end), the text string is reduced until the contents of the string are as close to the desired width as possible. The values determine how the string is reduced. In start cropping, characters are removed from the front of the string until the reduced string and ellipses fit within the desired width. In center cropping, characters are removed from the center of the string (at each step in the reduction, the middle character of the current string is removed), until the reduced string and the ellipses fit. In end cropping, the characters are removed from the end of the string, and the ellipses are appended to the reduced string.
<hbox> <description width="50" crop="end" value="This string will be cropped to fit."/> <textbox flex="1"/> </hbox>
[Editor's Note: The CSS3 Text Module defines rules for the cropping of arbitrary wrapping text, e.g., for blocks. Until this specification is fully defined, only the single-line form of a description will support cropping. Multi-line descriptions will ignore the crop attribute. This applies to all other XUL controls that support cropping as well.]
A label can be associated with a control (e.g., with a listbox) using the control attribute. The value of this attribute is the ID of the control element elsewhere in the document. This attribute is analogous to the for attribute supported in HTML 4.0.
<hbox> <label control="username" accesskey="e" value="Enter your User ID:"/> <textbox id="username" flex="1"/> </hbox>
Labels also support access keys. These can be specified using the accesskey attribute. This attribute is only meaningful if the label has also specified an associated control using the 'control' attribute. If so, then the user agent will associate the access key specified with the label's associated control.
interface XULDescriptionElement : XULElement { attribute boolean disabled; attribute boolean crop; attribute DOMString value; };
disabled
crop
value
interface XULLabelElement : XULDescriptionElement { attribute boolean accessKey; attribute DOMString control; };
accessKey
control
Another basic building block of XUL is the image. It is declared using the image tag, and its behavior is similar to the HTML4.0 img element.
The resource to use for an image can be specified either using a src attribute referencing the URI of the image to load, or using the CSS2 'list-style-image' property.
<image style="border: 3px solid blue" src="http://www.mozilla.org/images/mozilla-banner.gif"/>
If the image's preferred size is not the same as the actual size of the image, then the image will be scaled to fit in the space provided.
<image style="width: 200px; border: 3px solid blue" src="http://www.mozilla.org/images/mozilla-banner.gif"/>
interface XULImageElement : XULElement { attribute DOMString src; };
src
XUL supports a lightweight element called a spacer, designed simply to introduce space between two elements. It is specified using the spacer tag.
There are two types of spacers: springs and struts. A strut is an inflexible spacer element that introduces a fixed amount of space between two objects. The spacer specified below can be inserted between two objects to create a 20 pixel gap.
<spacer width="20"/>
A spring is a flexible spacer that can be used to introduce a flexing gap between two objects.
<spacer flex="1"/>
[Editor's Note: In Mozilla, the <spring> element serves the same purpose. Because the name spring implies that the object is flexible by default, this tag has been deprecated in favor of the <spacer> element.]
A separator element can be used to insert a visual separator between two elements. It can be used in toolbars to separate buttons, within menus to separate menu items, and within dialogs to provide clear separation between controls. Like a spacer the separator can be made flexible.
Controls in XUL come in two varieties. The first type of control is called a labeled control. It is a single atomic element (e.g., a button) that can be associated with a specific action. The second type of control is a select control (e.g., a list box), which presents a set of options to a user. Every control implements the XULControlElement interface, which includes methods for focusing and blurring the control and support for the connection of controllers (see section 5 for information about commands and controllers). Controls also have a notion of being enabled or disabled. Examples of controls include list boxes, buttons and checkboxes. Each XUL control is covered in its own section below.
interface XULControlElement : XULElement { attribute boolean disabled; attribute long tabIndex; readonly attribute XULControllers controllers; void focus(); void blur(); };
disabled
tabIndex
controllers
focus
blur
A labeled control is a single atomic control that performs a specific action when invoked. Labeled controls such as buttons support shorthands that allow you to specify information about the label or image associated with the widget (as well as cropping and access key information for that label). These controls implement the XULLabeledControlElement interface.
interface XULLabeledControlElement : XULControlElement { attribute DOMString crop; attribute DOMString image; attribute DOMString label; attribute DOMString accessKey; attribute DOMString command; void doCommand(); };
crop
image
label
accessKey
command
doCommand
All labeled controls generate a command event when they are invoked. A command handler can be attached to the labeled control to listen to the event. The oncommand shorthand attribute can be used on any XUL element to attach a 'command' listener to that element.
<button label="Hello World" oncommand="alert('I was invoked!');"/>
View the remaining dialog button compliance issues in Bugzilla.
View the dialog button test page (only works in Mozilla)
The button tag in XUL describes the traditional button control used in dialogs. It is a labeled control (see the XULLabeledControlElement interface described above).
The label attribute, if specified, describes a single line of text that should appear on the face of the button.
<button label="Apply";/>
A command handler can be placed on a button using either the oncommand attribute or the DOM addEventListener method with an event argument of 'command'. When the button is invoked, a command event is generated and the command handler will then be executed.
<button label="Alert!" oncommand="alert('Button pressed!');/>
The accesskey attribute describes the character within the button text that should contain the access key. If activated, a command event will be generated on the button.
<button accesskey="i" label="Hit ALT+I" oncommand="alert('Button pressed!');/>
The image attribute or the CSS2 'list-style-image' property can be used to specify an image that will be displayed on the face of the button. This is a shorthand syntax for specifying an image that will appear before the text of the button.
Although the 'label' and 'image' properties of the button are convenient as a shorthand syntax, the content of the button can be specified using child elements to provide more flexibility over the alignment and orientation of the button's components. In most themes a button is a box with a horizontal orientation.
<button> <label width="100"> This text should really be wrapped, since it is quite long. Arbitrary <b>markup</b> is supported. </label> </button>
<button> <image src="dummyicon.gif"/> <label> The image appears to the left of the text. </label> </button>
<button orient="vertical"> <image src="dummyicon.gif"/> <label> The image appears above the text. </label> </button>
<button type="menu"> <label> Menu Button </label> <menupopup> <menuitem label="Item One"/> </menupopup> </button>
If a button has no type attribute specified but a menu is connected to the button (either implicitly or explicitly) then the button's type will be changed to 'menu'. Therefore the type attribute typically does not need to be specified for menu buttons.
If the popup has no position specified, then the default position for the menu will be 'after_start'. For more details on popup positioning, see section 2.4.
The open attribute is used to programmatically show and hide the popup attached to the menupopup. A value of 'true' indicates that the popup should appear. A value of 'false' indicates that the popup should be hidden. This attribute can also be used to query the current state of the popup.
A dual menu button is a button whose menu is attached through a separate visible component, e.g., a dropdown that is adjacent to the button. This type of button is used when the button itself can still support an action when clicked, but there are also additional commands accessible via the dropdown. This button can be specified using a type attribute with a value of 'menu-button'.
A dual menu button automatically cancels any command events that originate within the dropdown. It does this so that the command handler on the button need not check its target. A single handler attached to the menupopup can still field all the menu item command events for the menu items.
<button type="menu-button" oncommand="alert('Button invoked.');"> <label> Dual Menu Button </label> <menupopup oncommand="alert('Menu item invoked.')"> <menuitem label="Item One"/> <menuitem label="Item Two"/> </menupopup> </button>
A button that toggles between a depressed and undepressed state is called a checkbox button. A checkbox button can be specified using a type attribute with a value of 'checkbox'. Command handlers can be hooked up to the button. The command event will not fire on the button until after the checked state has changed.
The checked attribute indicates whether or not the button is currently depressed. A value of 'true' indicates that the button is depressed. A value of 'false' indicates the button is not currently depressed.
A checkbox button can be placed into a mixed state using the checkState property. This property has values of 0, 1, and 2, where 0 is unchecked, 1 is checked, and 2 is indeterminate (e.g., mixed). A push button will never enter the mixed state automatically, but once placed into it, the button will cycle back to a checked state when pressed again.
The author can disable the automatic push behavior in order to gain precise control over when the button checks and unchecks. The autocheck attribute indicates whether or not the button should automatically perform the check. If omitted, a default value of 'true' is assumed.
Checkbox buttons that are designed to be placed in a group such that only one button can be pressed at a time are called radio buttons. These buttons are specified in XUL using the type attribute with a value of 'radio'.
Radio buttons must be siblings of one another, and they are grouped together using the group attribute. Once grouped together, only one button can be checked at any given point in time. The checked attribute when set to 'true' on a radio button indicates that the button is the current selection in the radio button group.
The autoCheck property can be used to disable the automatic setting/unsetting behavior that occurs when a radio is activated. If set to 'false' on a button, then when the button is activated, it will not be checked, nor will any other buttons be unchecked.
There are four special types of buttons that are typically found in dialogs. They are as follows:
These four special buttons are specified using the dlgtype attribute on the button. When the type is specified, the label does not have to be specified. The default text for that type of button will be inserted automatically. The possible values of the dlgtype attribute are: accept, cancel, help and details.
<button dlgtype="cancel"/>
interface XULButtonElement : XULLabeledControlElement { attribute DOMString type; attribute DOMString dlgType; // For buttons of type="menu" only. attribute boolean open; // For buttons of type="checkbox" and type="radio" only. attribute boolean checked; attribute long checkState; attribute boolean autoCheck; // For buttons of type="radio" only. attribute DOMString group; };
type
dlgType
open
checked
checkState
autoCheck
A toolbar button is a specialized button designed for use within a toolbar element. A toolbar button is declared using the toolbarbutton tag. It supports all the button types specified above (e.g., menu, menu-button, checkbox).
<toolbarbutton label="Reload" image="reload.gif"/>
Typically themes will define a toolbar button as a box with a vertical orientation. If the image and label shortcuts are used, the image will appear above the text. Like its dialog button cousin, the toolbar button supports both direction and orientation for fine-grained control over the placement of the image relative to the label.
A checkbox is a box with an associated label that can appear in either a checked state, an unchecked state, or an indeterminate state. It is traditionally used in dialogs to represent a boolean choice. Command handlers can be hooked up to a checkbox. The command event will not fire on the checkbox until after the checked state has changed.
<checkbox label="Click me to check and uncheck."/>
The checked attribute indicates whether or not the checkbox is currently checked. A value of 'true' indicates that the checkbox should be checked. A value of 'false' indicates that the checkbox is unchecked.
A checkbox can be placed into a mixed state using the checkState property. This property has values of 0, 1, and 2, where 0 is unchecked, 1 is checked, and 2 is indeterminate (e.g., mixed). A checkbox will never enter the mixed state automatically, but once placed into it, the checkbox will cycle back to a checked state when pressed again.
The author can disable the automatic toggle behavior in order to gain precise control over when the checkbox checks and unchecks. The autocheck attribute indicates whether or not the checkbox should automatically perform the check. If omitted, a default value of 'true' is assumed.
Checkboxes support all the features of labeled controls, including access keys, cropping, and the ability to specify image and label shorthands for the checkbox. In most themes, a checkbox is a box with a horizontal orientation. To gain control over the position of the checkbox relative to its image and label, orientation and direction can be used.
<checkbox orient="vertical" label="Vertically oriented checkbox"/>
interface XULCheckboxElement : XULLabeledControlElement { attribute boolean checked; attribute long checkState; attribute boolean autoCheck; };
checked
checkState
autoCheck
In XUL, a select control is a widget that presents a set of choices to a user. Select widgets contain individual items and track the user's selection, which can be either a single item or multiple items, depending on the type of the select widget.
There are five basic select widgets in XUL: the radio group, the tab strip, the list box, the menu list and the outliner. They are each covered in their own sections following the definition of the select element interfaces.
All select controls implement the XULSelectControlElement interface. This interface contains methods for tracking which item within the control is selected and for tracking the current value of the entire control (as determined by the value of the selected element).
interface XULSelectControlElement : XULControlElement { attribute XULSelectControlItemElement selectedItem; attribute long selectedIndex; attribute DOMString value; XULSelectControlItemElement appendItem(DOMString label, DOMString value); XULSelectControlItemElement insertItemAt(long index, DOMString label, DOMString value); XULSelectControlItemElement removeItemAt(long index); };
selectedItem
selectedIndex
value
appendItem
label
of type DOMString
value
of type DOMString
XULSelectConrolitemElement
insertItemAt
index
of type long
label
of type DOMString
value
of type DOMString
XULSelectConrolitemElement
insertItemAt
index
of type long
XULSelectConrolitemElement
interface XULSelectControlItemElement : XULElement { attribute boolean disabled; attribute DOMString crop; attribute DOMString image; attribute DOMString label; attribute DOMString accessKey; attribute DOMString command; attribute DOMString value; readonly attribute boolean selected; readonly attribute XULSelectControlElement control; void doCommand(); };
disabled
crop
image
label
accessKey
command
selected
value
control
doCommand
Radio groups are designed to present a set of mutually exclusive options to a user in a dialog. A radio group is declared using the radiogroup tag. It contains radio elements as children. A radio element always belongs to the nearest enclosing radio group.
A radio group is a box with a default vertical orientation. The radio group extends XULSelectControlElement and therefore it can be focused.
An entire radio group can be disabled using the 'disabled' attribute. If the radio group is disabled, then none of the radio items can be accessed. If the radio group is enabled, individual radio items can still be disabled (effectively excluding them from the list of available choices) by setting the disabled attribute on the items.
<radiogroup> <radio label="Item One"/> <radio label="Item Two"/> <radio label="Item Three"/> </radiogroup>
Note in the above example, no item was initially selected. A radio group will automatically select the first item in the layout model (e.g., accounting for box direction and ordinal groups) if no items are selected.
To indicate that a radio item should be selected initially, the selected attribute can be used on a radio element.
<radiogroup> <radio label="Item One"/> <radio selected="true" label="Item Two"/> <radio label="Item Three"/> </radiogroup>
The selectedItem property can be used to obtain the current selected radio item from the radio group. It can also be used to select a specific radio item. Alternatively the selected property/attribute can be used on a radio item to query for its selected state.
Whenever the selection changes on a radiogroup, a 'select' event fires on the radio group. A handler can be attached to the radiogroup to listen for changes in selection. The handler will fire after the selection has changed.
<radiogroup onselect="alert('The new selected item is: ' + this.selectedItem + '\n');"> <radio label="Item One"/> <radio selected="true" label="Item Two"/> <radio label="Item Three"/> </radiogroup>
Data values can be associated with individual radio items using the value attribute. If the radio item becomes selected, its 'value' attribute becomes the value of the radio group itself.
<radiogroup onselect="alert('The new value of the radio group is: ' + this.value + '\n');"> <radio label="Item One" value="1"/> <radio selected="true" label="Item Two" value="3"/> <radio label="Item Three" value="29"/> </radiogroup>
A radio group is a XULSelectControlElement, and a radio item is a XULSelectControlItemElement.
A tab in XUL is a XULSelectControlItemElement that must always be used as part of an enclosing XULSelectControlElement called a tab strip. The tab strip itself is declared using the tabs element. Individual tabs are declared using the tab element.
The tabs element is normally used in conjunction with an enclosing tab box to provide a complete tab control that can be used to switch between a set of visible panels by selecting the individual tabs. For a complete description of the tab box, see section 3.9.
Like other select controls, the tab strip tracks a selected item, the current active tab and can have a value associated with individual tabs and with the control itself. Whenever the active tab changes a 'select' event fires.
<tabs onselect="alert('The new value of the tabs is: ' + this.value + '\n');"> <tab label="Tab One" value="1"> <tab label="Tab Two" value="2"> <tab label="Tab Three" value="3"> </tabs>
The tab strip also supports the selectedItem and selectedIndex properties.
<menulist> <menupopup> <menuitem label="Item One"> <menuitem label="Item Two"> <menuitem selected="true" label="Item Three"> </menupopup> </menulist>
A menu list is declared using the menulist tag. Individual menu items are declared using the menuitem tag and are placed within a menupopup tag.
Values can be associated with individual items, and the menulist also fires a 'select' event whenever its selected item changes.
A menu list, unlike other select control elements, supports the specification of a label using the label shorthand attribute. This label is displayed on the face of the menu list. Menu lists also support the longhand form of the label using the label element.
<menulist label="Empty"/> <menulist> <label>Empty</label> <menupopup/> </menulist>
Menu lists, in addition to supporting individual menu items, also support the use of menus to provide nested hierarchies of submenus. The menus themselves are declared using the menu tag. The menus are not considered items in the menu list, and they cannot be selected. Only menu items within a menu list can actually be selected. Menus are simply used to group related items within a list under a common heading.
<menulist> <menupopup> <menu label="Menu One"> <menupopup> <menuitem label="Item One"/> <menuitem label="Item Two"/> </menupopup> </menu> <menuitem label="Item Three"/> </menupopup> </menulist>
For more information on menus and menu items, see section 3.xxx. For more information on the menupopup element, see section 2.4.
The open property can be used to dynamically open and close a menu list. When set to true, the menu list is opened. When set to false, the menu list is closed.
An editable menu list provides a dropdown list of choices as well as a text field that can be used to enter a value that may not correspond to an item in the list. This widget is also known as a combo box because the user can use either the text field or the list to set the value of the control.
An editable menu list is specified using the editable attribute or property with a value of 'true'. Instead of a static label on the face of the menu list, the widget instead contains a text field that can be used to enter text.
The inputField property can be used to obtain the XULTextBoxElement that represents the input field. For more information on the API supported by text box, see section 3.xxx. When using an editable menu list, the value of the widget always corresponds to the current value of the text field. Selecting an item from within the list sets the value of the text field and the value of the menu list.
The menu list interface extends the XULSelectControlItemElement interface and contains some additional functionality for supplying a label on the menu list and for opening and closing the menu list.
interface XULMenuListElement : XULSelectControlElement { attribute boolean editable; attribute boolean open; attribute DOMString label; attribute DOMString crop; attribute DOMString image; // For editable menu lists only. readonly attribute XULTextBoxElement inputField; };
editable
<listbox> <listitem label="Item One"/> <listitem label="Item Two"/> <listitem label="Item Three"/> </listbox>
The rows attribute can be used to specify the number of visible rows to display. If this is set, the list will fix itself to the height required. If omitted, the normal rules of the enclosing layout object apply, e.g., the list box can be made flexible, be set to a specified height, etc.
<listbox rows="4"> <listitem label="Item One"/> <listitem label="Item Two"/> <listitem label="Item Three"/> <listitem label="Item Four"/> <listitem label="Item Five"/> <listitem label="Item Six"/> <listitem label="Item Seven"/> <listitem label="Item Eight"/> </listbox>
By default a list box only allows one item to be selected at a time. This behavior can be customized using the seltype attribute. Its possible values are 'single' and 'multiple'. The default is 'single'.
There are two properties for accessing the first selected item in the list. These properties are selectedIndex and selectedItem. The index is 0-based, which means that the first item in the list has an index of 0. The index can be set to -1 to deselect all items in the list.
For lists that support multiple selection, the selectedItems property can be used to obtain a NodeList of all the currently selected items. The items are sorted in the order that they occur in the list. The list of selected items is "live", and remains up to date as elements are selected and deselected.
Whenever the selection of a list box changes, a select event fires on the listbox. This event can be listened for with an 'onselect' shorthand attribute.
<listbox onselect="alert('The index of the new selected item is: ' + this.selectedIndex + '\n')"> ... </listbox>
Just as with radio items a value can be stored with each list item using the value attribute. The value of the list box itself becomes the value of the first selected item in the list box. The list box can also be set to its own unique value using the value attribute.
<listbox onselect="alert('The new value of the listbox is: + this.value + '\n')"> <listitem label="One" value="3"/> <listitem label="Two" value="9"/> <listitem label="Three" value="27"/> </listbox>
.....
A group box is used to group controls together in a dialog. It is traditionally rendered as a grooved box with a caption embedded within the border. A group box is declared using the groupbox tag. The caption for a group box is declared using the caption tag.
A caption for a group box is a XULLabeledControlElement. Therefore it is a horizontal box that supports label and image shorthands. A group box behaves just like a vertical box except for the way it handles captions. If a caption is encountered as a child of a group box, it is embedded within the group box's border and does not participate in the box layout with the other group box children.
<groupbox> <caption label="Group Box Caption"/> <description flex="1"> The interior of the group box. </description> </groupbox>
A group box is a XULElement.