Element: <oj-label>

Oracle® JavaScript Extension Toolkit (JET)
7.1.0

F18183-01

Signature:

class ojLabel

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:
  • 4.0.0
Module:
  • ojlabel

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 {ojLabel} from "ojs/ojlabel";

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

JET In Typescript

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


The oj-label component decorates the label text with a required icon and help icon. The user can interact with the help icon (on hover, on focus, etc) to display help description text or to navigate to an url for more help information.

For accessibility reasons, you need to associate the oj-label component to its JET form component. For most JET form components you do this using the oj-label's for attribute and the JET form component's id attribute. For a few JET form components (oj-radioset, oj-checkboxset, oj-color-palette, and oj-color-spectrum) you associate the oj-label component to its JET form component using the oj-label's id attribute and the JET form component's labelled-by attribute.


<oj-label for="inputtextid" show-required="[[isRequired]]"
help.definition="[[helpDef]]" help.source="[[helpSource]]">input label</oj-label>
<oj-input-text id="inputtextid" required="[[isRequired]]"><//oj-input-text>

<oj-label id="radiosetlabel" show-required="[[isRequired]]">radioset</oj-label>
<oj-radioset required="[[isRequired]]" labelled-by="radiosetlabel">
  <oj-option name="color" value="red">Red</oj-option>
  <oj-option name="color" value="blue">Blue</oj-option>
</oj-radioset>

<!--  You can bind the text as a child comment node or on a span element, but not on the
oj-label element. The knockout text binding is not supported on a JET custom element; -->
<oj-label for="input2"><!--ko text: input2Label --><!--/ko--></oj-label>

Touch End User Information

Target Gesture Action
Help Icon Tap and Hold Show the help definition in a popup
Tap If no help source, show the help definition in a popup. If help source, navigate to the url.

Keyboard End User Information

Target Key Action
Help Icon Enter If there is an url associated with help icon, navigate to the url.
Tab In Show the help definition in a popup.

Styling

Accessibility

For accessibility reasons, you need to associate the oj-label component to its JET form component. For most JET form components you do this using the oj-label's for attribute and the JET form component's id attribute. For more examples, refer to the JET form component's API jsdoc.

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

Class Description
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.

oj-label-accesskey Use this in a span around a single text character in the oj-label's text. It styles the character in a way that indicates to the user that this character is the accesskey. Use this in conjunction with the HTML accesskey attribute on the oj-label element.
oj-label-nowrap place on the oj-label element to have it not wrap when you don't want to use the responsive design classes (e.g., oj-md-labels-nowrap or oj-md-label-nowrap).
oj-label-inline place on the oj-label element to inline the label with the sibling dom element when you don't want to use the responsive design classes (e.g., oj-md-labels-inline).
oj-label-inline-top place on the oj-label element together with oj-label-inline to inline the label with the sibling dom element and have zero margin-top.

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.

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.

Attributes

for :string|null

The for attribute refers to the id of the element this oj-label element is associated with. Some JET form components support using oj-label's for attribute to point to its id attribute (e.g., oj-input-text, oj-slider), and others do not (e.g., oj-checkboxset).

For the oj-radioset, oj-checkboxset, oj-color-palette, and oj-color-spectrum components, instead of the for attribute, use the id attribute on oj-label with JET's form element's labelled-by attribute.

Refer to the JET's form element's documentation for more examples showing the use of for/id and the use of id/labelled-by.

Default Value:
  • null
Since:
  • 4.0.0
Names
Item Name
Property for
Property change event forChanged
Property change listener attribute (must be of type function) on-for-changed

help :Object|null

The help information that goes on the oj-label. The help attributes are:
  • definition - this is the help definition text. It is what shows up when the user hovers over the help icon, or tabs into the help icon, or press and holds the help icon on a mobile device. No formatted text is available for help definition attribute.
  • source - this is the help source url. If present, a help icon will render next to the label. For security reasons we only support urls with protocol http: or https:. If the url doesn't comply we ignore it and throw an error. Pass in an encoded URL since we do not encode the URL.
Properties:
Name Type Argument Description
definition string | null <optional>
help definition text
source string | null <optional>
help source url
Default Value:
  • {'definition' :null, 'source': null}
Since:
  • 4.0.0
Names
Item Name
Property help
Property change event helpChanged
Property change listener attribute (must be of type function) on-help-changed

label-id :string|null

label-id sets the id attribute on the internal label element. The use case where this may be needed is if you are using a <div aria-labelledby> and for accessibility reasons you need to point to the oj-label's label element. This should be a corner case. Most often you'd use oj-label's for attribute to associate with a form component's id attribute or use oj-label's id attribute to associate with a JET form component's labelled-by attribute.
Default Value:
  • null
Since:
  • 4.0.0
Names
Item Name
Property labelId
Property change event labelIdChanged
Property change listener attribute (must be of type function) on-label-id-changed

(nullable) show-required :boolean

Whether this label should have a required icon. It is recommended that you bind the show-required attribute to the same binding as the required attribute on the associated JET form component to make sure they are in sync.
Default Value:
  • false
Since:
  • 4.0.0
Names
Item Name
Property showRequired
Property change event showRequiredChanged
Property change listener attribute (must be of type function) on-show-required-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.tooltip-help :string

Used for the default help icon tooltip.. Most likely the application developer would use the oj-label's help.definition property to specify the help definition text per oj-label element.

Default Value:
  • "Help"
Since:
  • 4.0.0
Names
Item Name
Property translations.tooltipHelp

(nullable) translations.tooltip-required :string

Used for the default required icon tooltip.

Default Value:
  • "Required"
Since:
  • 4.0.0
Names
Item Name
Property translations.tooltipRequired

Methods

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');

refresh() → {void}

Refreshes the component with all the current attributes.

Call refresh if the id changes, though changing the id shouldn't be needed.

Also, call refresh after required or help changes. The locale could have changed in the meantime, and refresh is needed to update the required and help tooltips.

There should be no need to call refresh for other attribute changes.
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");