XUL Programmer's Reference Manual

<menu>

Attributes Common Children
value <menupopup>
flex <menuseparator />
key <separator /> 
disabled  
id  
class  
acceltext  
accesskey  
crop  
orient  
autostretch  
oncommand  

The <menu> element usually appears as a child of a <menubar>, but doesn't have to. Menus popup in various places: as context menus overlaying content, at the bottom of the browser, and so on. Typically, a menu has a <menupopup> as a child. A menu can only contain a single menupopup as a direct child, though submenus can be defined by creating menus as children of menupopups. In the menupopup a number of menu items are defined. A simple File menu is defined as follows:

 
<menu value="File">
    <menupopup>
       <menuitem value="Open" />
       <menuitem value="Close" oncommand="window.close()"/>
       <menuseparator/>
       <menuitem value="Save" />
       <menuitem value="Exit"/>
    </menupopup>
</menu>
value
Description
value is a required attribute used for naming the menu element. 
Syntax
<menu value="string" />
Example
<menu value="File" /


Notes

None.
 
accesskey
Description
accesskey is an optional attribute for specifying a shortkey for a menu or menuitem. 
Syntax
<menu id="string" accesskey="character">


Example

<menu id="formatMenu" value="&formatMenu.label;" accesskey="&formatmenu.accesskey;">
    <menupopup id="formatMenuPopup">
      <menuitem id="pageProperties"/>
    </menupopup>
</menu>


Notes

Menus can have shortcut keys and accelerators defined. The shortcut key is a single letter that can be used (on some platforms) to quickly access the menu in combination with another key (e.g., ALT). The attribute for specifying this key is accesskey. Note that the accesskey should use a localized entity, as in the example above, to ensure that the character with the keys available on the keyboard.


 

disabled
Description
disabled is an optional attribute used to gray out menus and menuitems.


Syntax

<menu id="string" disabled="true | false" >
Example
<menu id="Edit" disabled="true" >
Notes
Maintain and check the state of disabled to see whether certain menu operations are available, as in the following example:
 
XXX INsert example from help stuff here XXX.
                        
acceltext
Description
acceltext is an optional attribute used to override the assembled acceltext for a menu or menuitem.
Syntax
<menu id="string" acceltext="string" >
Example
<menu id="Edit" acceltext="<Ctrl> + <X> (Cut)" >
Notes
Accelerator text is generated automatically by putting together the <key> and any modifier keys (e.g., the control key). When you do not specify the acceltext attribute for a key element defined as <key id="skip" key="s" and alt="true" />, for instance, the acceltext is S+Alt; if you supply a value for acceltext for this key, then that value overrides the default text.
 
key
Description
key is an optional attribute used to specify a key binding for the menu.


Syntax

<menu id="string" key="key identifier" >
Example
<menu id="Save" key="saveKey" >
Notes
None.
 
crop
Description
cropis an optional attribute for specifying which part of a menu's text, if any, will be cropped if it is too large.
Syntax
<menu id="string" value="Menu Name" crop="left | right | none" >
Example
<menu id="string" value="Very Long Menu Name" crop="none" >
Notes
None.

 
Last updated: 3/27/00 Ian Oeschger