Element: <oj-dialog>

Oracle® JavaScript Extension Toolkit (JET)
7.1.0

F18183-01

Signature:

class ojDialog

QuickNav

Attributes

JET Custom Elements

JET components are implemented as custom HTML elements. In addition to the component attributes documented in this page, JET components also support standard HTML global attributes like id and aria-label.

The JET data binding syntax can be used to define both component and global attributes through the use of dynamically evaluated expressions. All attributes (component and global) support attribute-level binding by prefixing the attribute name with ":" (e.g. :id="[...]"). When using attribute-level binding, all expression values are treated as strings. Additionally, component attributes support property-level binding by using the attribute name directly with no ":" prefix. When using property-level binding, the expressions should evaluate to the types documented by the corresponding attributes. Property-level binding is strongly recommended over attribute-level binding for component attributes.

A detailed description of working with custom HTML elements can be found in: JET Custom Element Usage.



PREVIEW: This is a preview API. Preview APIs are production quality, but can be changed on a major version without a deprecation path.

Version:
  • 7.1.0
Since:
  • 0.6.0
Module:
  • ojdialog

Module usage

See JET Module Loading for an overview of module usage within JET.

Typescript Import Format
//To typecheck the element APIs, import as below.
import {ojDialog} from "ojs/ojdialog";

//For the transpiled javascript to load the element's module, import as below
import "ojs/ojdialog";

JET In Typescript

A detailed description of working with JET elements and classes in your typescript project can be found at: JET Typescript Usage.


JET Dialog Component

Description: Themeable, WAI-ARIA-compliant dialog component. A dialog is a floating window that typically contains a title bar and a content area. The dialog window can be moved by dragging on the title area, and closed with the 'x' icon (by default). Dialogs can also be resized by dragging on edges or corners of the dialog component.

If the content length exceeds the maximum height, a scrollbar will automatically appear.

A bottom button bar and semi-transparent modal overlay layer are common options that can be added.

Styling

Class(es) Description
oj-dialog-title

Class used to format the title. Automatically created headers use oj-dialog-title to format the title. For user-defined headers, you may want to use the oj-dialog-title so that the title in your user-defined header is stylistically similar to a default title.

oj-dialog-footer-separator

A separator between the dialog body and the dialog footer can be added by using a second style class (oj-dialog-footer-separator) in the footer. So use:

  • oj-dialog-footer oj-dialog-footer-separator
to add a footer separator to the dialog. Note that for themes that have a built-in footer separator (specifically the iOS theme), this class has no effect.

See the demo section for a live example of the footer separator.

oj-progress-bar-embedded

Optional markup. Used to format a progress bar embedded in the dialog header.

oj-focus-highlight Under normal circumstances this class is applied automatically. It is documented here for the rare cases that an app developer needs per-instance control.

The oj-focus-highlight class applies focus styling that may not be desirable when the focus results from pointer interaction (touch or mouse), but which is needed for accessibility when the focus occurs by a non-pointer mechanism, for example keyboard or initial page load.

The application-level behavior for this component is controlled in the theme by the $focusHighlightPolicy SASS variable; however, note that this same variable controls the focus highlight policy of many components and patterns. The values for the variable are:

  • nonPointer: oj-focus-highlight is applied only when focus is not the result of pointer interaction. Most themes default to this value.
  • all: oj-focus-highlight is applied regardless of the focus mechanism.
  • none: oj-focus-highlight is never applied. This behavior is not accessible, and is intended for use when the application wishes to use its own event listener to precisely control when the class is applied (see below). The application must ensure the accessibility of the result.

To change the behavior on a per-instance basis, the application can set the SASS variable as desired and then use event listeners to toggle this class as needed.

Note that the dialog component wraps additional divs around the user's content and also performs other DOM manipulations. Thus, the user should be careful if they wish to engage in advanced coding approaches. In general, it is best to target DOM elements by id or class name (e.g., developers should not rely on relative positioning of dialog DOM elements).

Focus

Upon opening a dialog, focus is automatically moved to the first item that matches the following:

  1. The first element within the dialog with the autofocus attribute
  2. The first :tabbable element within the dialog body
  3. The first :tabbable element within the dialog footer
  4. The dialog's close button
  5. The dialog itself

While open, the dialog widget ensures that tabbing cycles focus between elements within the dialog itself, not elements outside of it. Modal dialogs additionally prevent mouse users from clicking on elements outside of the dialog.

Upon closing a dialog, focus is automatically returned to the element that had focus when the dialog was opened.

See also the oj-focus-highlight discussion.

Touch End User Information

Target Gesture Action
Dialog Close Icon Tap Close the dialog.

Keyboard End User Information

The JET Dialog can be closed with keyboard actions:

Target Key Action
Dialog Esc Close the dialog.
Dialog Close Icon Enter or Space Close the dialog.

Sizing

Dialog dimensions, including height, width, min-width, max-width, min-height and max-height are defined with css variables. The default dialog dimensions are the following:

  • height: auto
  • width: 300px
  • min-width: 200px
In most cases, you will want to use the default height:auto, since this will automatically adjust the height based on the content. Users can change the dialog dimensions using style attributes:

<oj-dialog id="wideDialog" title="Wide Dialog" style="width: 400px; min-width: 100px; max-width 500px;">
   <div slot="body">
      <p> Dialog Text
   </div>
</oj-dialog>

Accessibility

role

By default, the role will be set to dialog. This can be observed by inspecting the DOM:

 <div class="ojdialog ..." role="dialog">
This can be changed using the role attribute. WAI-ARIA recommends that role="dialog" be used if the dialog expects input (such as text input), otherwise, use the role attribute to assign role="alertdialog".

aria-labelledby

For both default and user-defined headers, the dialog component takes care of aria-labelledby for you. The aria-labelledby attribute is generated automatically (and set to the id of the header's title). For user-defined headers, the title div is identified by the div that has the oj-dialog-title class. Note that user-defined headers must have a title div (in order to meet accesibility requirements).

See also the oj-focus-highlight discussion.

Reparenting

When dialogs are open, they will be reparented into a common container in the document body and reparented back when closed. Within this container in the body, dialogs will always be top rooted but other types of dialogs used within an open dialog will be reparented within the dialog's layer. The dialog's layer defines its z-index weight "stacking context" and marked by the "oj-dialog-layer" style. The goal of this design is to maintain as much of the page author's document structure while avoiding most of the clipping and positioning issues of a completely inline design. Dialogs are assigned the same z-index values The layering between dialog peers reflect the opening order. In addition, the dialog that has active focus will be assigned a greater z-index by way of the "oj-focus-within" pseudo selector applied with "oj-dialog-layer" selector. The page author has control over z-index weights by way of the "oj-dialog-layer" selector.

There are known caveats with this design. However, these scenarios are considered "bad use" based on our JET dialog/popup strategy.

  1. Events raised within the dialog will not bubble up to the dialog's original ancestors. Instead, listeners for menu events should be applied to either the dialog's root element, or the document.
  2. Likewise, developers should not use CSS descendant selectors, or similar logic, that assumes that the dialog will remain a child of its original parent.
  3. Dialogs containing iframes are problematic. The iframe elements "may" fire a HTTP GET request for its src attribute each time the iframe is reparented in the document.
  4. If an iframe is added to the dialog's body, it must not be the first or last tab stop within the dialog or keyboard and VoiceOver navigation will not remain within the dialog.
  5. In some browsers, reparenting a dialog that contains elements having overflow, will cause these overflow elements to reset their scrollTop.

Reading direction

Setting the reading direction (LTR or RTL) is supported by setting the "dir" attribute on the <html> element of the page. As with any JET component, in the unusual case that the reading direction is changed post-init, the dialog must be refresh()ed, or the page must be reloaded.

Additional Examples

The following defines a basic dialog, with an ok button in the footer:


<oj-dialog id="dialogWithFooter" dialog-title="Dialog with Footer" style="width: 400px; min-width: 100px; max-width 500px;">
   <div slot="body">
      <p> Dialog Text
   </div>
   <div slot="footer">
      <oj-button id="okButton"> OK </oj-button>
   </div>
</oj-dialog>

Note that you will need to define your own event handlers for the ok and close buttons (see the demos for examples of this).

A dialog with user-defined header is shown next. Arbitrary header content can be defined using a user-defined header.


<oj-dialog id="dialog" dialog-title="Dialog Title">
   <div slot="header">
      <span id="dialog-title-id" class="oj-dialog-title"> User Defined Header</span>
   </div>
   <div slot="body">
      <p> Dialog Text
   </div>
</oj-dialog>

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.

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 default slot is the dialog's body. The <oj-dialog> element accepts DOM nodes as children for the default slot. The default slot can also be named with "body". For styling, the default body slot will be rendered with the oj-dialog-body class.

Since:
  • 4.0.0

body

The body slot is for the dialog's body area. The <oj-dialog> element accepts DOM nodes as children with the body slot. For styling, the body slot will be rendered with the oj-dialog-body class. Note that "body" is the default slot.

Since:
  • 4.0.0

contextMenu

The contextMenu slot is set on the oj-menu within this element. This is used to designate the JET Menu that this component should launch as a context menu on right-click, Shift-F10, Press & Hold, or component-specific gesture. If specified, the browser's native context menu will be replaced by the JET Menu specified in this slot.

The application can register a listener for the Menu's ojBeforeOpen event. The listener can cancel the launch via event.preventDefault(), or it can customize the menu contents by editing the menu DOM directly, and then calling refresh() on the Menu.

To help determine whether it's appropriate to cancel the launch or customize the menu, the ojBeforeOpen listener can use component API's to determine which table cell, chart item, etc., is the target of the context menu. See the JSDoc of the individual components for details.

Keep in mind that any such logic must work whether the context menu was launched via right-click, Shift-F10, Press & Hold, or component-specific touch gesture.

The footer slot is for the dialog's footer area. The <oj-dialog> element accepts DOM nodes as children with the footer slot. For styling, the footer slot will be rendered with the oj-dialog-footer class.

Since:
  • 4.0.0

The header slot is for the dialog's header area. The <oj-dialog> element accepts DOM nodes as children with the header slot. For styling, the header slot will be rendered with the oj-dialog-header class.

If a header slot is not specified by the user, a header will automatically be created. The automatically generated header will contain a close button, and the header title will be set to the dialog title.
Since:
  • 4.0.0

Attributes

cancel-behavior :"icon"|"escape"|"none"

Specifies the cancel behavior of the dialog. The default value depends on the theme. In the alta-web theme, the default is "icon", and in alta-android, alta-ios and alta-windows themes, the default is "none".

Note that the cancelBehavior applies to both automatic and user-defined headers. So by default, a user-defined header in the alta-web theme will have a system generated close icon.

Supported Values:
Value Description
"escape" The dialog will close when it has focus and user presses the escape (ESC) key. A close icon will not be created.
"icon" A close icon will automatically be created. The dialog will close when it has focus and user presses the escape (ESC) key.
"none" A close icon will not be created. No actions will be associated with the escape key.
Default Value:
  • "icon"
Names
Item Name
Property cancelBehavior
Property change event cancelBehaviorChanged
Property change listener attribute (must be of type function) on-cancel-behavior-changed

dialog-title :string|null

Specify the title of the dialog. null is the default.
Names
Item Name
Property dialogTitle
Property change event dialogTitleChanged
Property change listener attribute (must be of type function) on-dialog-title-changed

drag-affordance :"title-bar"|"none"

Specifies the drag affordance. The default value depends on the theme. In the alta-web theme, the default is "title-bar", and in alta-android, alta-ios and alta-windows themes, the default is "none".
Supported Values:
Value Description
"none" The dialog will not be draggable.
"title-bar" The dialog will be draggable by the title bar.
Default Value:
  • "title-bar"
Names
Item Name
Property dragAffordance
Property change event dragAffordanceChanged
Property change listener attribute (must be of type function) on-drag-affordance-changed

initial-visibility :"hide"|"show"

Set the initial visibility of the dialog.
Supported Values:
Value Description
"hide" The dialog will stay hidden until the open() method is called.
"show" The dialog will automatically open upon initialization.
Default Value:
  • "hide"
Names
Item Name
Property initialVisibility
Property change event initialVisibilityChanged
Property change listener attribute (must be of type function) on-initial-visibility-changed

modality :"modal"|"modeless"

Defines the modality of the dialog.
Supported Values:
Value Description
"modal" The dialog is modal. Interactions with other page elements are disabled. Modal dialogs overlay other page elements.
"modeless" Defines a modeless dialog.
Default Value:
  • "modal"
Names
Item Name
Property modality
Property change event modalityChanged
Property change listener attribute (must be of type function) on-modality-changed

position :oj.ojDialog.Position

Position object is used to establish the location the dialog will appear relative to another element. oj.ojDialog.Position defines "my" alignment "at" the alignment "of" some other thing which can be "offset" by so many pixels.

The "my" and "at" properties defines aligment points relative to the dialog and other element. The "my" property represents the dialog's alignment where the "at" property represents the other element that can be identified by "of". The values of these properties describe horizontal and vertical alignments.

Deprecated v3.0.0 jQuery UI position syntax; Use of a percent unit with "my" or "at" is not supported.
Names
Item Name
Property position
Property change event positionChanged
Property change listener attribute (must be of type function) on-position-changed

position.at :Object

Defines which position on the target element ("of") to align the positioned element against.
Names
Item Name
Property position.at

position.at.horizontal :"start"|"end"|"left"|"center"|"right"

Supported Values:
Value Description
"center"
"end" evaluates to "right" in LTR mode and "left" in RTL mode.
"left"
"right"
"start" evaluates to "left" in LTR mode and "right" in RTL mode.
Default Value:
  • "center"
Names
Item Name
Property position.at.horizontal

position.at.vertical :"top"|"center"|"bottom"

Supported Values:
Value
"bottom"
"center"
"top"
Default Value:
  • "center"
Names
Item Name
Property position.at.vertical

position.collision :"flip"|"fit"|"flipfit"|"none"

Rule for alternate alignment.
Supported Values:
Value Description
"fit" Shift the element away from the edge of the window.
"flip" 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.
"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.
"none" No collision detection.
Default Value:
  • "fit"
Names
Item Name
Property position.collision

position.my :Object

Defines which edge on the dialog to align with the target ("of") element.
Names
Item Name
Property position.my

position.my.horizontal :"start"|"end"|"left"|"center"|"right"

Supported Values:
Value Description
"center"
"end" evaluates to "right" in LTR mode and "left" in RTL mode.
"left"
"right"
"start" evaluates to "left" in LTR mode and "right" in RTL mode.
Default Value:
  • "center"
Names
Item Name
Property position.my.horizontal

position.my.vertical :"top"|"center"|"bottom"

Supported Values:
Value
"bottom"
"center"
"top"
Default Value:
  • "center"
Names
Item Name
Property position.my.vertical

position.of :string|Object

Which element to position the dialog against. 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.
Default Value:
  • "window"
Names
Item Name
Property position.of

position.offset :Object

Defines a point offset in pixels from the ("my") alignment.
Names
Item Name
Property position.offset

position.offset.x :number

Horizontal aligment offset.
Default Value:
  • 0
Names
Item Name
Property position.offset.x

position.offset.y :number

Vertical alignment offset.
Default Value:
  • 0
Names
Item Name
Property position.offset.y

resize-behavior :"resizable"|"none"

Specifies the resizeBehavior of the dialog. The default value depends on the theme. In the alta-web theme, the default is "resizable", and in alta-android, alta-ios and alta-windows themes, the default is "none".
Supported Values:
Value Description
"none" The dialog will not be interactively resizable.
"resizable" Thie dialog will be interactively resizable.
Default Value:
  • "resizable"
Names
Item Name
Property resizeBehavior
Property change event resizeBehaviorChanged
Property change listener attribute (must be of type function) on-resize-behavior-changed

translations :object|null

A collection of translated resources from the translation bundle, or null if 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.

Names
Item Name
Property translations
Property change event translationsChanged
Property change listener attribute (must be of type function) on-translations-changed

(nullable) translations.label-close-icon :string

Label for the dialog close button.

See the translations attribute for usage examples.

Default Value:
  • "Close"
Since:
  • 3.0
Names
Item Name
Property translations.labelCloseIcon

Events

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.
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Argument Description
element Element <not nullable>
target of animation
action "open" | "close" The action that is ending the animation. The number of actions can vary from component to component. Suggested values are:
  • "open" - when a dialog component is opened
  • "close" - when a dialog component is closed

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 calling event.preventDefault.
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Argument Description
action "open" | "close" The action that is starting the animation. The number of actions can vary from component to component. Suggested values are:
  • "open" - when a dialog component is opened
  • "close" - when a dialog component is closed
element Element <not nullable>
target of animation
endCallback function():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.

ojBeforeClose

Triggered before the dialog is dismissed via the close() method. The close can be cancelled by calling event.preventDefault().
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
event Event a custom event

ojBeforeOpen

Triggered before the dialog is launched via the open() method. The open can be cancelled by calling event.preventDefault().
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
event Event a custom event

ojClose

Triggered after the dialog is dismissed via the close() method.
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
event Event a custom event

ojFocus

Triggered after focus has been transfered to the dialog.
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
event Event a custom event

ojOpen

Triggered after the dialog is launched via the open() method.
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
event Event a custom event

ojResize

Triggered when the dialog is being resized.
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
originalEvent Object the underlying UI Event object
originalPosition Object the original CSS position of the dialog
originalSize Object the original size of the dialog
position Object the current CSS position of the dialog
size Object the current size of the dialog

ojResizeStart

Triggered when the user starts resizing the dialog.
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
originalEvent Object the underlying UI Event object
originalPosition Object the original CSS position of the dialog
originalSize Object the original size of the dialog
position Object the current CSS position of the dialog
size Object the current size of the dialog

ojResizeStop

Triggered when the user stops resizing the dialog.
Properties:

All of the event payloads listed below can be found under event.detail.

Name Type Description
originalEvent Object the underlying UI Event object
originalPosition Object the original CSS position of the dialog
originalSize Object the original size of the dialog
position Object the current CSS position of the dialog
size Object the current size of the dialog

Methods

close() → {void}

Closes the dialog.
Fires:
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
property string The property name to get. Supports dot notation for subproperty access.
Since:
  • 4.0.0
Returns:
Type
any
Example

Get a single subproperty of a complex property:

let subpropValue = myComponent.getProperty('complexProperty.subProperty1.subProperty2');

isOpen() → {boolean}

Returns true if the dialog is currently open. This method does not accept any arguments.

The "open" state reflects the period of time the dialog is visible, including open and close animations.
Returns:
true if the dialog is open.
Type
boolean

open() → {void}

Opens the dialog.
Fires:
Returns:
Type
void

refresh() → {void}

Refresh the dialog. Typically used after dynamic content is added to a dialog.
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
properties Object An object containing the property and value pairs to set.
Since:
  • 4.0.0
Returns:
Type
void
Example

Set 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
property string The property name to set. Supports dot notation for subproperty access.
value any The new value to set the property to.
Since:
  • 4.0.0
Returns:
Type
void
Example

Set a single subproperty of a complex property:

myComponent.setProperty('complexProperty.subProperty1.subProperty2', "someValue");

Type Definitions

Position

Properties:
Name Type Argument Description
my oj.ojDialog.PositionAlign <optional>
Defines which edge on the popup to align with the target ("of") element.
at oj.ojDialog.PositionAlign <optional>
Defines which position on the target element ("of") to align the positioned element against.
offset oj.ojDialog.PositionPoint <optional>
Defines a point offset in pixels from the ("my") alignment.
of string | oj.ojDialog.PositionPoint <optional>
Which element to position the popup against. 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.
collision "flip" | "fit" | "flipfit" | "none" <optional>
Rule for alternate alignment.

  • "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.
  • "none" no collision detection.

PositionAlign

Properties:
Name Type Argument Description
vertical "top" | "bottom" | "center" <optional>
Vertical alignment.
horizontal "start" | "end" | "left" | "center" | "bottom" <optional>
Horizontal alignment.

  • "start" evaluates to "left" in LTR mode and "right" in RTL mode.
  • "end" evaluates to "right" in LTR mode and "left" in RTL mode.

PositionPoint

Properties:
Name Type Argument Description
x number <optional>
Horizontal aligment offset.
y number <optional>
Vertical alignment offset.