Element: <oj-button>

Oracle® JavaScript Extension Toolkit (JET)
4.2.0

E91398-01

QuickNav

Attributes

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

Version:
  • 4.2.0
Since:
  • 0.6

JET Custom Elements

JET components are implemented as custom HTML elements. A detailed description of working with these elements can be found in: JET Custom Element Usage.

JET Button

Description: Themeable, WAI-ARIA-compliant push buttons, with appropriate styles for hover, active, checked, and disabled.

To create toggle buttons, see the JET Buttonset.

<oj-button id="myButton">
    <span>My Button</span>
</oj-button>

Push Buttons

Push buttons are ordinary buttons that do not stay pressed in when clicked. Push buttons are created from oj-button elements.

Anchor-based buttons are recommended only if native anchor functionality such as href navigation is desired. If only a click listener is needed, button-based buttons are recommended.

Buttonsets and Toolbars

The JET Buttonset component can be used to create toggle buttons or group related buttons, such as a group of radios or checkboxes. Buttonset provides visual and semantic grouping and WAI-ARIA-compliant focus management. See the Buttonset API doc for more information.

Also, buttons and buttonsets can be placed in a JET Toolbar. Like Buttonset, Toolbar is themable and provides WAI-ARIA-compliant focus management. See the Toolbar API doc for more information.

Touch End User Information

Target Gesture Action
Push Button Tap Push the button.
Toggle Button Tap Toggle the button.
Menu Button Tap Open the menu.

See also the Menu touch gesture doc.

Keyboard End User Information

Target Key Action
Push Button Enter or Space* Push the button.
Toggle Button Enter or Space Toggle the button.
Menu Button Enter, Space*, or DownArrow Open the menu.
Esc Close the menu.

* Some types of Push and Menu Buttons support Enter, not Space.

See the Menu keyboard doc for keystrokes that apply when focus is on the menu.

Accessibility

For accessibility, a JET Button must always have its default slot filled, even if it is icon-only.

See also the oj-focus-highlight discussion.

Disabled content: JET supports an accessible luminosity contrast ratio, as specified in WCAG 2.0 - Section 1.4.3 "Contrast", in the themes that are accessible. (See the "Theming" chapter of the JET Developer Guide for more information on which themes are accessible.) Note that Section 1.4.3 says that text or images of text that are part of an inactive user interface component have no contrast requirement. Because disabled content may not meet the minimum contrast ratio required of enabled content, it cannot be used to convey meaningful information.

Styling

The following CSS classes can be applied by the page author as needed.

Class Description
oj-button-sm
oj-button-lg
oj-button-xl
Makes the button small, large, or extra large. Is applied to the Button's root element.
oj-button-primary Draws attention to the button, often identifying the primary action in a set of buttons. Designed for use with a push button. In some themes, this class does nothing. Is applied to the Button's root element.
oj-button-confirm Identifies an action to confirm. Designed for use with a push button. Is applied to the Button's root element.
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.

Event Handling

It's most reliable to register click handlers directly on the button, rather than on an ancestor. For example, if any of the button's DOM is swapped out in a click handler (e.g. alternating the text and icon between "Play" and "Pause"), the bubbling will stop if the click target was part of the content that was removed in the swap.

In lieu of a shared listener on an ancestor, syntax like $( "#ancestor :oj-button" ).click( myFunc ); can be used to set a handler on many buttons at once.

Performance

In lieu of stamping a button in a table, dataGrid, or other container, consider placing a single Button outside the container that acts on the currently selected row or cell.

Setting Component State

Built-in KO bindings, like KO's disable binding, should not be used for state with a JS API, since that is tatamount to updating the DOM directly. The component attribute should be bound instead.

State with no JS API should be set by manipulating the DOM directly in an allowable way, and then calling refresh() on the affected component(s). E.g. the reading direction (LTR / RTL) is changed by by setting the "dir" attribute on the <html> node and calling refresh().

When using a built-in Knockout binding, keep in mind that those bindings do not execute the necessary refresh() call after updating the DOM. Updates that flow from the component to the observable, as a result of user interaction, are not problematic. But updates in the other direction, that programmatically update the DOM because the observable changed, will not be picked up until the next refresh().

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 elements can have up to two types of child content:

  • Any child element with a slot attribute will be moved into that named slot, e.g. <span slot='startIcon'>...</span>. All supported named slots are documented below. Child elements with unsupported named slots will be removed from the DOM.
  • Any child element lacking a slot attribute will be moved to the default slot, also known as a regular child. This is documented under the "Default" heading below.

Default

The default slot is the button's text label. The <oj-button> element accepts plain text or DOM nodes as children for the default slot. A default slot label is required for all buttons for accessibility purposes. The label can be hidden using the display attribute.

If a text node is provided it will be wrapped in a span.

Examples

Initialize the Button with child content specified:

<oj-button>
  <span>myValue</span>
</oj-button>

Initialize the Button with data-bound child content specified in a span:

<oj-button>
  <span data-bind='text: myText'></span>
</oj-button>

Initialize the Button with data-bound child content specified without a container element:

<oj-button>
  <!-- ko text: myText --><!--/ko-->
</oj-button>

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 and demos 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.

Example

Initialize the component with a context menu:

<oj-some-element>
    <-- use the contextMenu slot to designate this as the context menu for this component -->
    <oj-menu slot="contextMenu" style="display:none" aria-label="Some element's context menu">
...
    </oj-menu>
</oj-some-element>

endIcon

The endIcon slot is the button's end icon. The <oj-button> element accepts DOM nodes as children with the endIcon slot.

Example

Initialize the Button with child content specified for the endIcon:

<oj-button>
  <span>myValue</span>
  <span slot='endIcon' class='myIconClass'></span>
</oj-button>

startIcon

The startIcon slot is the button's start icon. The <oj-button> element accepts DOM nodes as children with the startIcon slot.

Example

Initialize the Button with child content specified for the startIcon:

<oj-button>
  <span slot='startIcon' class='myIconClass'></span>
  <span>myValue</span>
</oj-button>

Attributes

<static> chroming :string

Indicates in what states the button has chrome (background and border).

The default chroming varies by theme and containership as follows:

  • If the button is in a buttonset or toolbar, then the default chroming is the current chroming value of the nearest such container.
  • Else, if $buttonChromingOptionDefault is set in the current theme as seen in the example below, then that value is the chroming default.
  • Else, the default chroming is "full".

Once a value has been set on this button attribute, that value applies regardless of theme and containership.

Supported Values:
Name Type Description
"full" string In typical themes, full-chrome buttons always have chrome.
"half" string In typical themes, half-chrome buttons acquire chrome only in their hover, active, and selected states. Half-chroming is recommended for buttons in a toolbar. (This is the toolbar default in most themes.)
"outlined" string In typical themes, outlined buttons are similar to half-chrome buttons, but have a border in the default state.
Names
Item Name
Property chroming
Property change event chromingChanged
Property change listener attribute (must be of type function) on-chroming-changed
Examples

Initialize the Button with the chroming attribute specified:

<oj-button chroming='half'></oj-button>

Get or set the chroming property after initialization:

// getter
var chromingValue = myButton.chroming;

// setter
myButton.chroming = 'half';

Set the default in the theme (SCSS) :

$buttonChromingOptionDefault: half !default;

<static> disabled :boolean

Disables the button if set to true.

After create time, the disabled state should be set via this API, not by setting the underlying DOM attribute.

Default Value:
  • false
Names
Item Name
Property disabled
Property change event disabledChanged
Property change listener attribute (must be of type function) on-disabled-changed
Examples

Initialize the Button with the disabled attribute specified:

<oj-button disabled='true'></oj-button>

Get or set the disabled property after initialization:

// getter
var disabledValue = myButton.disabled;

// setter
myButton.disabled = true;

<static> display :string

Whether to display both the label and icons ("all") or just the icons ("icons"). In the latter case, the label is displayed in a tooltip instead, unless a tooltip was already supplied at create time.

For accessibility, a JET Button must always have a label set via the default slot, even if it is icon-only.

Supported Values:
Name Type Description
"all" string Display both the label and icons.
"icons" string Display only the icons.
Default Value:
  • "all"
Names
Item Name
Property display
Property change event displayChanged
Property change listener attribute (must be of type function) on-display-changed
Examples

Initialize the Button with the display attribute specified:

<oj-button display='icons'></oj-button>

Get or set the display property after initialization:

// getter
var displayValue = myButton.display;

// setter
myButton.display = 'icons';

translations :Object

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 this component has translations, their documentation immediately follows this doc entry.

Default Value:
  • an object containing all resources relevant to the component, or null if none
Names
Item Name
Property translations
Property change event translationsChanged
Property change listener attribute (must be of type function) on-translations-changed
Examples

Initialize the component, overriding some translated resources and leaving the others intact:

<!-- Using dot notation -->
<oj-some-element translations.some-key='some value' translations.some-other-key='some other value'></oj-some-element>

<!-- Using JSON notation -->
<oj-some-element translations='{"someKey":"some value", "someOtherKey":"some other value"}'></oj-some-element>

Get or set the translations property after initialization:

// Get one
var value = myComponent.translations.someKey;

// Set one, leaving the others intact. Always use the setProperty API for 
// subproperties rather than setting a subproperty directly.
myComponent.setProperty('translations.someKey', 'some value');

// Get all
var values = myComponent.translations;

// Set all.  Must list every resource key, as those not listed are lost.
myComponent.translations = {
    someKey: 'some value',
    someOtherKey: 'some other value'
};

Methods

getProperty(property) → {*}

Retrieves a value for a property or a single subproperty for complex properties.
Parameters:
Name Type Description
property string The property name to get. Supports dot notation for subproperty access.
Returns:
Type
*
Example

Get a single subproperty of a complex property:

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

refresh()

Refreshes the component.

setProperties(properties)

Performs a batch set of properties.
Parameters:
Name Type Description
properties Object An object containing the property and value pairs to set.
Example

Set a batch of properties:

myComponent.setProperties({"prop1": "value1", "prop2.subprop": "value2", "prop3": "value3"});

setProperty(property, value)

Sets a property or a single subproperty for complex properties and notifies the component of the change, triggering a [property]Changed event.
Parameters:
Name Type Description
property string The property name to set. Supports dot notation for subproperty access.
value * The new value to set the property to.
Example

Set a single subproperty of a complex property:

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