Usage
Signature:
interface MenuElement
- Typescript Import Format
- //To typecheck the element APIs, import as below.
 import { MenuElement } from "ojs/ojmenu";
 //For the transpiled javascript to load the element's module, import as below
 import "ojs/ojmenu";
For additional information visit:
Note: Application logic should not interact with the component's properties or invoke its methods until the BusyContext indicates that the component is ready for interaction.
Styling
- 
        CSS Variables
| Name | Type | Description | 
|---|---|---|
| --oj-menu-icon-size | <length> | Menu icon size | 
| --oj-menu-icon-to-edge-padding | <length> | Padding between icon and menu edge | 
| --oj-menu-text-to-start-icon-padding | <length> | Padding between text and start icon | 
| --oj-menu-text-to-end-icon-padding | <length> | Padding between text and end icon | 
| --oj-menu-text-to-edge-padding | <length> | Padding between text and menu edge | 
| --oj-menu-divider-margin | <length> | Menu divider margin | 
| --oj-menu-sheet-margin-horizontal | <length> | Menu horizontal margin when displayed as a sheet | 
| --oj-menu-item-text-color | <color> | Menu item text color | 
| --oj-menu-icon-color | <color> | Menu icon color | 
Slots
JET components that allow child content support slots. Please see the slots section of the JET component overview doc for more information on allowed slot content and slot types.
- 
    
    Default
- 
    
      The <oj-menu> element accepts oj-optionandoj-menu-select-manyas child elements. See the oj-option documentation for details about accepted children and slots.
Attributes
- 
    
    disabled :boolean
- 
    
      Disables the menu if set totrue.- Default Value:
- false
 
 NamesItem Name Property disabledProperty change event disabledChangedProperty change listener attribute (must be of type function, see Events and Listeners for additional information.) on-disabled-changed
- 
    
    open-options :oj.ojMenu.OpenOptions
- 
    
      A collection of settings impacting the launch of a menu. These openOptionsmay be accessed and overridden individually or collectively, as seen in the examples.The values set here can be overridden on a per-launch basis by passing the corresponding params into the open method. Those per-launch values can be further customized by a ojBeforeOpen listener. The built-in menu button and context menu functionality overrides some of the Menu's openOptions, for WAI-ARIA compliance and other reasons. Thus, if the app really wants to customize those values, it must do so in aojBeforeOpenlistener. If the built-in menu button or context menu functionality is modified in this way, it is the app's responsibility to ensure that the result is both correct and accessible.NamesItem Name Property openOptionsProperty change event openOptionsChangedProperty change listener attribute (must be of type function, see Events and Listeners for additional information.) on-open-options-changed
- 
    
    open-options.display :"auto"|"dropDown"|"sheet"
- 
    
      Determines whether the menu is displayed as a drop down menu or a sheet menu. The default value is "auto", in which case the behavior depends on the type of device, as determined by theConfig.getDeviceRenderModemethod. If the application is running on a phone device, the menu will display as a sheet. Otherwise, the menu will display as a drop down.Sheet menus are not appropriate when submenus are present. Thus, menus having submenus are always displayed as a drop down, regardless of the values of this option. - Default Value:
- "auto"
 
- Since:
- 2.1.0
 
 Supported Values:Value Description autoDisplays the menu as a sheet or drop down, depending on the screen width. dropDownDisplays the menu as a drop down. sheetDisplays the menu as a sheet. NamesItem Name Property openOptions.display
- 
    
    open-options.initial-focus :"none"|"menu"|"firstItem"
- 
    
      Determines focus behavior when the menu is initially opened.- Default Value:
- "menu"
 
 Supported Values:Value Description firstItemFocuses the first menu item (e.g. MenuButton DownArrow behavior). menuFocuses the menu itself, with no menu item focused (e.g. typical Context Menu behavior). noneLeaves focus where it is, e.g. on the launching component. The application must verify that the result is accessible. NamesItem Name Property openOptions.initialFocus
- 
    
    open-options.launcher :string|Element
- 
    
      The DOM node (which may or may not be a JET element) that launches this menu. This node must be focusable, as focus is returned to it upon menu dismissal. The launcher must either be specified in this component option, or on each menu launch -- see open() and ojBeforeOpen. - Default Value:
- null
 
 NamesItem Name Property openOptions.launcher
- 
    
    open-options.position :Object
- 
    
      Determines the position of a drop down menu when launched via the open()method or via menu button or context menu functionality. Ignored for sheet menus.The "my" and "at" properties define alignment points relative to the menu and other element. The "my" property represents the menu's alignment where the "at" property represents the other element that can be identified by "of" or defauts to the launcher when the menu opens. The values of these properties describe horizontal and vertical alignments. - JET supports startandendvalues whereverleftandrightare supported. Thestartvalue means "left in LTR; right in RTL", while theendvalue means "right in LTR; left in RTL."
 Menu also supports the following extended syntax for the offield:- The "event"keyword means "position the menu relative to the UI event that opened the menu."
- The "launcher"keyword means "position the menu relative to the launcher element."
 By default, when the offield is not set, the menu is positioned relative to the launcher.The default position value varies between menus and submenus as follows: - Top level menu default: { my: { horizontal: "start", vertical: "top" }, at: { horizontal: "start", vertical: "bottom" }, offset: { x: 0, y: 0 }, collision: "flipfit" }
- Submenu default: { my: { horizontal: "start", vertical: "top" }, at: { horizontal: "end", vertical: "top" }, offset: { x: 0, y: 0 }, collision: "flipfit" }
 NamesItem Name Property openOptions.position
- JET supports 
- 
    
    open-options.position.at :Object
- 
    
      Defines which position on the target element ("of") to align the positioned element against.NamesItem Name Property openOptions.position.at
- 
    
    open-options.position.at.horizontal :"start"|"end"|"left"|"center"|"right"
- 
    
      Defines the horizontal alignment of what the menu is aligned to. For top-level menus, the default value is "start". For submenus, the default value is "end".Supported Values:Value Description centerendevaluates to "right" in LTR mode and "left" in RTL mode. leftrightstartevaluates to "left" in LTR mode and "right" in RTL mode. NamesItem Name Property openOptions.position.at.horizontal
- 
    
    open-options.position.at.vertical :"top"|"center"|"bottom"
- 
    
      Defines the vertical alignment of what the menu is aligned to. For top-level menus, the default value is "bottom". For submenus, the default value is "top".Supported Values:Value bottomcentertopNamesItem Name Property openOptions.position.at.vertical
- 
    
    open-options.position.collision :"flip"|"fit"|"flipfit"|"flipcenter"|"none"
- 
    
      Rule for alternate alignment.- Default Value:
- 'flipfit'
 
 Supported Values:Value Description fitshift the element away from the edge of the window. flipthe element to the opposite side of the target and the collision detection is run again to see if it will fit. Whichever side allows more of the element to be visible will be used. flipcenterfirst applies the flip rule and follows with center alignment. flipfitfirst applies the flip logic, placing the element on whichever side allows more of the element to be visible. Then the fit logic is applied to ensure as much of the element is visible as possible. noneno collision detection. NamesItem Name Property openOptions.position.collision
- 
    
    open-options.position.my :Object
- 
    
      Defines which edge on the menu to align with the target ("of") element.NamesItem Name Property openOptions.position.my
- 
    
    open-options.position.my.horizontal :"start"|"end"|"left"|"center"|"right"
- 
    
      Defines the horizontal alignment of the menu.- Default Value:
- 'start'
 
 Supported Values:Value Description centerendevaluates to "right" in LTR mode and "left" in RTL mode. leftrightstartevaluates to "left" in LTR mode and "right" in RTL mode. NamesItem Name Property openOptions.position.my.horizontal
- 
    
    open-options.position.my.vertical :"top"|"center"|"bottom"
- 
    
      Defines the vertical alignment of the menu.- Default Value:
- 'top'
 
 Supported Values:Value bottomcentertopNamesItem Name Property openOptions.position.my.vertical
- 
    
    open-options.position.of :string|Object
- 
    
      Which element to position the menu against. The default is thelauncherargument passed to theopenmethod. If the value is a string, it should be a selector or the literal string value ofwindow. Otherwise, a point of x,y. When a point is used, the values are relative to the whole document. Page horizontal and vertical scroll offsets need to be factored into this point - see UIEvent pageX, pageY.NamesItem Name Property openOptions.position.of
- 
    
    open-options.position.offset :Object
- 
    
      Defines a point offset in pixels from the ("my") alignment.NamesItem Name Property openOptions.position.offset
- 
    
    open-options.position.offset.x :number
- 
    
      Horizontal alignment offset.- Default Value:
- 0
 
 NamesItem Name Property openOptions.position.offset.x
- 
    
    open-options.position.offset.y :number
- 
    
      Vertical alignment offset.- Default Value:
- 0
 
 NamesItem Name Property openOptions.position.offset.y
- 
    
    translations :object|null
- 
    
      A collection of translated resources from the translation bundle, or nullif this component has no resources. Resources may be accessed and overridden individually or collectively, as seen in the examples.If the component does not contain any translatable resource, the default value of this attribute will be null. If not, an object containing all resources relevant to the component.If this component has translations, their documentation immediately follows this doc entry. NamesItem Name Property translationsProperty change event translationsChangedProperty change listener attribute (must be of type function, see Events and Listeners for additional information.) on-translations-changed
- 
    
    (nullable) translations.aria-focus-skip-link :string
- 
    
      Label assigned to a hidden anchor tag used for accessibility navigation on platforms supporting VoiceOver. The link is injected before the first menu item. It is used for establishing VO cursor focus. Activation of the link will move focus to the first menu item. - Deprecated:
-  
Since Description 18.0.0This resource was introduced as a workaround for an issue that has since been fixed, and is no longer used by oj-menu. 
 - Default Value:
- "Focus is within the menu, double tap or swipe to move focus to the first menu item."
 
- Since:
- 18.0.0
 
- See:
 NamesItem Name Property translations.ariaFocusSkipLink
- 
    
    (nullable) translations.label-cancel :string
- 
    
      Label for the "Cancel" menu item. See the translations attribute for usage examples. - Deprecated:
-  
Since Description 18.0.0This is not in the Redwood UX specification. 
 - Default Value:
- "Cancel"
 
- Since:
- 18.0.0
 
 NamesItem Name Property translations.labelCancel
Events
- 
        
    
    
      ojAction
- 
    
    
    Triggered when a menu item (other than the built-in "Cancel" item) is selected. To ensure keyboard accessibility, the only correct, supported way to react to the selection of a menu item is to listen for this event. Click listeners should not be used. To find the value of the menu item that triggered an action event, the event.target.value should be used. See Events and Listeners for additional information. - Deprecated:
-  
Since Description 10.0.0This event is no longer supported, use the ojMenuAction event instead. 
 - Since:
- 10.0.0
 
 
- 
        
    
    
      ojAnimateEnd
- 
    
    
    Triggered when a default animation has ended, such as when the component is being opened/closed or a child item is being added/removed. This event is not triggered if the application has called preventDefault on the animateStart event.- Deprecated:
-  
Since Description 12.1.0This web component no longer supports this event. 
 - "open" - when a menu element is opened
- "close" - when a menu element is closed
 Properties:All of the event payloads listed below can be found under event.detail. See Events and Listeners for additional information.Name Type Argument Description action"open" | "close" The action that triggered the animation. 
 The number of actions can vary from element to element. Suggested values are:elementElement <not nullable> 
 target of animation 
- 
        
    
    
      ojAnimateStart
- 
    
    
    Triggered when a default animation is about to start, such as when the component is being opened/closed or a child item is being added/removed. The default animation can be cancelled by callingevent.preventDefault.- Deprecated:
-  
Since Description 12.1.0This web component no longer supports this event. 
 - "open" - when a menu element is opened
- "close" - when a menu element is closed
 Properties:All of the event payloads listed below can be found under event.detail. See Events and Listeners for additional information.Name Type Argument Description action"open" | "close" The action that triggers the animation. 
 The number of actions can vary from element to element. Suggested values are:elementElement <not nullable> 
 target of animation endCallbackfunction():void <not nullable> 
 If the event listener calls event.preventDefault to cancel the default animation, it must call the endCallback function when it finishes its own animation handling and any custom animation has ended. 
- 
        
    
    
      ojBeforeOpen
- 
    
    
    Triggered before this menu is launched via the open method or via menu button or context menu functionality. The launch can be cancelled by calling event.preventDefault().The event.detail.openOptionspayload field contains the settings being used for this menu launch, resulting from merging theopenOptionspassed toopen(), if any, with theopenOptionscomponent option.This field is "live", meaning that the listener can alter fields such as positionto affect this launch without affecting the component option. Since these changes are applied to the merged object, they supersede both theopenOptionspassed toopen()and theopenOptionscomponent option.If any of the above techniques are used to alter the built-in menu button or context menu functionality, it is the app's responsibility to ensure that the result is both correct and accessible. Properties:All of the event payloads listed below can be found under event.detail. See Events and Listeners for additional information.Name Type Description openOptionsoj.ojMenu.OpenOptions effecting the open operation 
- 
        
    
    
      ojClose
- 
    
    
    Triggered after this menu is closed. - Since:
- 2.0.0
 
 Properties:All of the event payloads listed below can be found under event.detail. See Events and Listeners for additional information.Name Type Description eventEvent a custom event 
- 
        
    
    
      ojMenuAction
- 
    
    
    Triggered when a menu item (other than the built-in "Cancel" item) is selected. To ensure keyboard accessibility, the only correct, supported way to react to the selection of a menu item is to listen for this event. Click listeners should not be used. To find the value of the menu item that triggered an menu action event, the event.detail.selectedValue should be used. - Since:
- 10.0.0
 
 Properties:All of the event payloads listed below can be found under event.detail. See Events and Listeners for additional information.Name Type Description selectedValueany The value of current selected menu item. 
- 
        
    
    
      ojOpen
- 
    
    
    Triggered after this menu is launched via the open method or via menu button or context menu functionality. - Since:
- 2.0.0
 
 Properties:All of the event payloads listed below can be found under event.detail. See Events and Listeners for additional information.Name Type Description eventEvent a custom event 
Methods
- 
        
    
    
      close : {void}
- 
    
    
    Closes the menu. This method does not accept any arguments.Returns:- Type
- void
 
- 
        
    
    
      getProperty(property) : {any}
- 
    
    
    Retrieves the value of a property or a subproperty. The return type will be the same as the type of the property as specified in this API document. If the method is invoked with an incorrect property/subproperty name, it returns undefined.Parameters:Name Type Description propertystring The property name to get. Supports dot notation for subproperty access. - Since:
- 4.0.0
 
 Returns:- Type
- any
 ExampleGet a single subproperty of a complex property: let subpropValue = myComponent.getProperty('complexProperty.subProperty1.subProperty2');
- 
        
    
    
      open(event, openOptions) : {void}
- 
    
    
    Launches this menu after firing the ojBeforeOpen event. Listeners to that event can cancel the launch via event.preventDefault(). If the launch is not canceled, then the the open event is fired after the launch.This method's optional openOptionsparam can be used to specify per-launch values for the settings in the corresponding component options, without altering those options. Those per-launch values can be further customized by aojBeforeOpenlistener.Menus launched manually (as opposed to those launched by built-in functionality such as the menu button and context menu functionality) must be launched via this API, not by simply unhiding the Menu DOM (such as via jQuery's show()API.Parameters:Name Type Argument Description eventEvent <optional> 
 What triggered the menu launch. May be null. May be omitted if subsequent params are omitted.openOptionsoj.ojMenu.OpenOptions <optional> 
 Options to merge with the openOptionsoption. May benull. May be omitted if subsequent params are omitted.Fires:- oj.ojMenu#event:ojBeforeOpen
- oj.ojMenu#event:ojOpen
 Returns:- Type
- void
 
- 
        
    
    
      refresh : {void}
- 
    
    
    Refreshes the disclosed state of the menu. JET elements require arefresh()after the DOM is programmatically changed underneath the component. The menu will implicitly refresh each time it is open. Calling refresh before the menu is open will trigger any content contained within anoj-deferto disclose before the menu is actually open.Returns:- Type
- void
 
- 
        
    
    
      setProperties(properties) : {void}
- 
    
    
    Performs a batch set of properties. The type of value for each property being set must match the type of the property as specified in this API document.Parameters:Name Type Description propertiesObject An object containing the property and value pairs to set. - Since:
- 4.0.0
 
 Returns:- Type
- void
 ExampleSet a batch of properties: myComponent.setProperties({"prop1": "value1", "prop2.subprop": "value2", "prop3": "value3"});
- 
        
    
    
      setProperty(property, value) : {void}
- 
    
    
    Sets a property or a subproperty (of a complex property) and notifies the component of the change, triggering a [property]Changed event. The value should be of the same type as the type of the attribute mentioned in this API document.Parameters:Name Type Description propertystring The property name to set. Supports dot notation for subproperty access. valueany The new value to set the property to. - Since:
- 4.0.0
 
 Returns:- Type
- void
 ExampleSet a single subproperty of a complex property: myComponent.setProperty('complexProperty.subProperty1.subProperty2', "someValue");
Type Definitions
- 
    
    OpenOptions
- 
    
    
    
     
  Properties:Name Type Argument Description displaystring <optional> 
 Determines whether the menu is displayed as a drop down menu or a sheet menu. initialFocusstring <optional> 
 Determines focus behavior when the menu is initially opened. launcherstring | Element <optional> 
 The DOM node (which may or may not be a JET element) that launches this menu. positionoj.ojMenu.Position <optional> 
 Determines the position of a drop down menu when launched. Ignored for sheet menus. 
- 
    
    Position
- 
    
    
    
     
  - "flip" the element to the opposite side of the target and the collision detection is run again to see if it will fit. Whichever side allows more of the element to be visible will be used.
- "fit" shift the element away from the edge of the window.
- "flipfit" first applies the flip logic, placing the element on whichever side allows more of the element to be visible. Then the fit logic is applied to ensure as much of the element is visible as possible.
- flipcenter first applies the flip rule and follows with center alignment.
- "none" no collision detection.
 Properties:Name Type Argument Description atoj.ojMenu.PositionAlign <optional> 
 Defines which position on the target element ("of") to align the positioned element against. collision"flip" | "fit" | "flipfit" | "flipcenter" | "none" <optional> 
 Rule for alternate alignment. myoj.ojMenu.PositionAlign <optional> 
 Defines which edge on the menu to align with the target ("of") element. ofstring | oj.ojMenu.PositionPoint <optional> 
 Which element to position the menu against. The default is the launcherargument passed to theopenmethod.If the value is a string, it should be a selector or the literal string value of window. Otherwise, a point of x,y. When a point is used, the values are relative to the whole document. Page horizontal and vertical scroll offsets need to be factored into this point - see UIEvent pageX, pageY.offsetoj.ojMenu.PositionPoint <optional> 
 Defines a point offset in pixels from the ("my") alignment. 
- 
    
    PositionAlign
- 
    
    
    
     
  - "start" evaluates to "left" in LTR mode and "right" in RTL mode.
- "end" evaluates to "right" in LTR mode and "left" in RTL mode.
 Properties:Name Type Argument Description horizontal"start" | "end" | "left" | "center" | "bottom" <optional> 
 Horizontal alignment. vertical"top" | "bottom" | "center" <optional> 
 Vertical alignment. 
- 
    
    PositionPoint
- 
    
    
    
     
  Properties:Name Type Argument Description xnumber <optional> 
 Horizontal alignment offset. ynumber <optional> 
 Vertical alignment offset.