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. For more examples,
see the label demos which show all the JET form controls with oj-label or refer to the JET
form component's API jsdoc.
<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
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 The application-level behavior for this component is controlled in the theme by the
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 a label element or oj-label element 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 elements can have up to two types of child content:
- Any child element with a
slotattribute 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
slotattribute will be moved to the default slot, also known as a regular child.
-
contextMenu
-
The contextMenu slot is set on the
oj-menuwithin 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>
Attributes
-
for :string|null
-
The
forattribute refers to the id of the element this oj-label element is associated with. Some JET form components support using oj-label'sforattribute to point to itsidattribute (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
forattribute, use theidattribute on oj-label with JET's form element'slabelled-byattribute.Refer to the JET's form element's documentation/demos for more examples showing the use of
for/idand the use ofid/labelled-by.- Default Value:
null
- Since:
- 4.0.0
Names
Item Name Property forProperty change event forChangedProperty change listener attribute (must be of type function) on-for-changedExample
Associate oj-label to the oj-input-text using the
forattribute on oj-label and theidattribute on oj-input-text during initialization.<oj-label for="inputId">Name:</oj-label> <oj-input-text id="inputId"></oj-input-text> -
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.
- Default Value:
{'definition' :null, 'source': null}
- Since:
- 4.0.0
Properties:
Name Type Argument Description definitionstring | null <optional>
help definition text sourcestring | null <optional>
help source url Names
Item Name Property helpProperty change event helpChangedProperty change listener attribute (must be of type function) on-help-changedExamples
Initialize the label with the help definition and help source:
<!-- Using dot notation --> <oj-label help.definition="some help definition" help.source="some external url">Name:</oj-label> <!-- Using JSON notation --> <oj-label help='{"definition":"some value", "source":"someurl"}'>Name:</oj-label>Set the
helpattribute, after initialization:// Set one, leaving the others intact. Use the setProperty API for // subproperties so that a property change event is fired. myComponent.setProperty('help.definition', 'some new value'); // Get all var values = myComponent.help; // Set all. Must list every key, as those not listed are lost. myComponent.help = { definition: 'some new value', source: 'some new url' }; -
label-id :string|null
-
label-idsets theidattribute 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'slabelelement. This should be a corner case. Most often you'd use oj-label'sforattribute to associate with a form component's id attribute or use oj-label'sidattribute to associate with a JET form component'slabelled-byattribute.- Default Value:
null
- Since:
- 4.0.0
Names
Item Name Property labelIdProperty change event labelIdChangedProperty change listener attribute (must be of type function) on-label-id-changedExamples
Initialize the label with the
label-idattribute:<oj-label label-id="labelId">Name:</oj-label>Set the attribute, after initialization:
// getter var labelid = myOjLabel.labelId; // setter myOjLabel.labelId = "myLabelId"; -
(nullable) show-required :boolean
-
Whether this label should have a required icon. It is recommended that you bind the
show-requiredattribute to the same binding as therequiredattribute on the associated JET form component to make sure they are in sync.- Default Value:
false
- Since:
- 4.0.0
Names
Item Name Property showRequiredProperty change event showRequiredChangedProperty change listener attribute (must be of type function) on-show-required-changedExamples
Initialize the oj-label with the
show-requiredattribute, binding form component'srequiredattribute to the same value.<oj-label show-required="[[isRequired]]">Name:</oj-label> <oj-input-text required="[[isRequired]]"></oj-input-text>Set the attribute, after initialization:
// getter var showRequired = myOjLabel.showRequired; // setter myOjLabel.showRequired = false; -
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.
Names
Item Name Property translationsProperty change event translationsChangedProperty change listener attribute (must be of type function) on-translations-changedExamples
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
translationsproperty 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' }; -
(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 a value for a property or a single subproperty for complex properties.
Parameters:
Name Type Description propertystring 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:
var subpropValue = myComponent.getProperty('complexProperty.subProperty1.subProperty2'); -
refresh() → {void}
-
Refreshes the component with all the current attributes.
Call refresh if the
idchanges, though changing theidshouldn't be needed.Also, call refresh after
There should be no need to call refresh for other attribute changes.requiredorhelpchanges. The locale could have changed in the meantime, and refresh is needed to update therequiredandhelptooltips.Returns:
- Type
- void
Example
document.getElementById("label1").setProperty("id","label2"); document.getElementById("label2").refresh(); -
setProperties(properties) → {void}
-
Performs a batch set of properties.
Parameters:
Name Type Description propertiesObject 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 single subproperty for complex properties and notifies the component of the change, triggering a [property]Changed event.
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
Example
Set a single subproperty of a complex property:
myComponent.setProperty('complexProperty.subProperty1.subProperty2', "someValue");