Element: <oj-input-search>

Oracle® JavaScript Extension Toolkit (JET)
20.1.0

G60074-01

Since:
  • 9.0.0
Module:
  • ojinputsearch

Note: This component is not supported in the following themes: Alta

QuickNav

Attributes


JET Input Search

Description: JET Input Search provides support for entering search text.

JET Input Search displays an input field that a user can type into, as well as an optional dropdown list of suggestions.

An Input Search that shows only an input field can be created with the following markup.


<oj-input-search aria-label='Search'>
</oj-input-search>

An Input Search that shows an input field with a dropdown list of suggestions can be created with the following markup.


<oj-input-search suggestions='[[dataProvider]]'
                 aria-label='Search'>
</oj-input-search>

Input Search will only show up to a maximum of 12 suggestions in the dropdown list. The list could show most recently used searches or high confidence suggested results. It is intended to help the user enter search text in order to conduct a subsequent search. It is up to the application to conduct the search and display results elsewhere on the page.

An application should register a listener for the ojValueAction event in order to be notified when the user submits search text. The application should then conduct the search and display the results.


<oj-input-search on-oj-value-action='[[handleValueAction]]'
                 aria-label='Search'>
</oj-input-search>

If an application provides a separate search button, then it may choose to ignore ojValueAction events and instead bind to the value. When the search button is clicked, the application would conduct a search with the currently set value.


<oj-input-search value='{{searchText}}'
                 aria-label='Search'>
</oj-input-search>
<oj-button on-oj-action='[[conductSearch]]'>
  Search
</oj-button>

The value property is guaranteed to be up-to-date at the time the ojValueAction event is dispatched.

Note: Input Search is not a full-fledged form control and does not support some of the common features of form controls. For example, it is not expected to be used in an oj-form-layout, it does not support a label, and it does not support assistive text.

Touch End User Information

Target Gesture Action
Input Field Tap If the drop down is not open, expand the drop down list. Otherwise, close the drop down list.

Keyboard End User Information

Target Key Action
Input field Enter Set the input text as the value.
Input field UpArrow or DownArrow If the drop down is not open, expand the drop down list.
Input field Esc Collapse the drop down list. If the drop down is already closed, do nothing.
Input field Tab In Set focus to the Input Search.

Accessibility

It is up to the application developer to set an aria-label on the Input Search.


Usage

Signature:

interface InputSearchElement<K,D>

Generic Parameters
ParameterDescription
KType of key of the dataprovider
DType of data from the dataprovider
Typescript Import Format
//To typecheck the element APIs, import as below.
import { InputSearchElement } from "ojs/ojinputsearch";

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

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 Classes

.oj-input-search-hero
Render a larger search field that is more prominent on the page
Example
<oj-input-search class="oj-input-search-hero">
 <!-- Content -->
 </oj-input-search>

Category: form-control-max-width

In the Redwood theme the default max width of a text field is 100%. These max width convenience classes are available to create a medium or small field.
The class is applied to the root element.

Classes:

.oj-form-control-max-width-sm
Sets the max width for a small field.
.oj-form-control-max-width-md
Sets the max width for a medium field.

Category: form-control-width

In the Redwood theme the default width of a text field is 100%. These width convenience classes are available to create a medium or small field.
The class is applied to the root element.

Classes:

.oj-form-control-width-sm
Sets the width for a small field.
.oj-form-control-width-md
Sets the width for a medium field.

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.

suggestionItemTemplate

Note: When the template is executed for each item, it will have access to the binding context containing the following properties: oj.ojInputSearch.SuggestionItemTemplateContext

The suggestionItemTemplate slot is used to specify the template for rendering each suggestion in the dropdown list. The slot must be a <template> element.

When the template is executed for each suggestion, it will have access to the binding context containing the following properties:

  • $current - an object that contains information for the current suggestion. (See the table below for a list of properties available on $current)
  • alias - if the data-oj-as attribute was specified on the template, the value will be used to provide an application-named alias for $current.

If no suggestionItemTemplate is specified, the component will render based on the value of the suggestionItemText property.

Properties of $current:
Name Type Argument Description
data D The data for the current suggestion
index number The zero-based index of the current suggestion
key K The key of the current suggestion
metadata ItemMetadata.<Key> The metadata for the current suggestion
searchText (string|null) <optional>
The search text entered by the user

Attributes

autocomplete :"on"|"off"

Specifies whether the component will enable the autocomplete type ahead feature.
Default Value:
  • 'on'
Names
Item Name
Property autocomplete
Property change event autocompleteChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-autocomplete-changed

placeholder :string

The placeholder text to set on the element. The placeholder specifies a short hint that can be displayed before the user selects or enters a value.
Default Value:
  • ''
Names
Item Name
Property placeholder
Property change event placeholderChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-placeholder-changed

(readonly) raw-value :(string|null)

The rawValue is the read-only property for retrieving the current value from the input field in string form.

The rawValue updates on the 'input' javascript event, so the rawValue changes as the value of the input is changed. If the user types in '1,200' into the field, the rawValue will be '1', then '1,', then '1,2', ..., and finally '1,200'. Then when the user blurs or presses Enter the value property gets updated.

This is a read-only attribute so page authors cannot set or change it directly.

Default Value:
  • null
Supports writeback:
  • true
Names
Item Name
Property rawValue
Property change event rawValueChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-raw-value-changed

suggestion-item-text :keyof D|(itemContext: ojcommontypes.ItemContext<K, D>) => string

Specifies the text string to render for a suggestion. This attribute can be set to either:
  • a string that specifies the name of a top level data field to render as text, or
  • a callback function that takes a context object and returns the text string to display

By default, the component will attempt to render a 'label' data field as text.

This text will be rendered for the selected value of the component. It will also be rendered for each suggestion in the dropdown if no suggestionItemTemplate is provided. When rendered for the dropdown suggestions, default matching search term highlighting will still be applied.

Default Value:
  • 'label'
Names
Item Name
Property suggestionItemText
Property change event suggestionItemTextChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-suggestion-item-text-changed

suggestions :(oj.ojInputSearch.DataProvider.<K, D>|null)

Data for the InputSearch suggestions. This data is used to populate the list of suggestions in the dropdown. When a user selects a suggestion from the dropdown, the ojValueAction event will contain the data for that suggestion. If no suggestions data is provided, then the dropdown will not be shown. Note that the InputSearch only shows up to a maximum of 12 suggestions in the dropdown even if there are more suggestions available in the data.

Note that the suggestion-item-text attribute allows for customizing the rendering of each suggestion. If it is not specified, then the component will attempt to render as text the 'label' field in the suggestion by default.

Default Value:
  • null
Names
Item Name
Property suggestions
Property change event suggestionsChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-suggestions-changed

value :(string|null)

The value of the element.
Default Value:
  • null
Supports writeback:
  • true
Names
Item Name
Property value
Property change event valueChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-value-changed

Events

ojValueAction

Note: The event detail contains the following properties: oj.ojInputSearch.ValueDetail<Key, Data>

Triggered when search text is submitted by the user, even if the text hasn't changed. Submission is triggered by the enter key, either to directly submit text or to select a highlighted value from the suggestions dropdown, or by selecting a value from the dropdown using a mouse or touch gesture. Note that the value property is guaranteed to be up-to-date at the time the ojValueAction event is dispatched.

See Events and Listeners for additional information.

Methods

getProperty(property) : {any}

Retrieves the value of a property or a subproperty.
Parameters:
Name Type Description
property string The property name to get. Supports dot notation for subproperty access.
Returns:
Type
any

setProperties(properties) : {void}

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

setProperty(property, value) : {void}

Sets a property or a single subproperty for complex properties and notifies the component of the change, triggering a corresponding event.
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.
Returns:
Type
void

Type Definitions

Documentation-only Types

Note: Type definitions in this section have been provided for documentation purposes and cannot be imported into application code.

DataProvider<K,D>

The interface for DataProvider
Properties:
Name Type Argument Description
addEventListener (type: string, callback: EventListenerOrEventListenerObject | null, options: boolean | AddEventListenerOptions | undefined) => void The **`addEventListener()`** method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target. [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener)
containsKeys (parameters: ojInputSearch.FetchByKeysParameters<K>) => Promise<ContainsKeysResults<K>> Check if rows are contained by keys
createOptimizedKeyMap (initialMap: Map<K, D> | undefined) => Map<K, D> <optional>
Returns an empty Map which will efficiently store Keys returned by the DataProvider
createOptimizedKeySet (initialSet: Set<K> | undefined) => Set<K> <optional>
Return an empty Set which is optimized to store keys
dispatchEvent (event: Event) => boolean The **`dispatchEvent()`** method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/dispatchEvent)
fetchByKeys (parameters: ojInputSearch.FetchByKeysParameters<K>) => Promise<FetchByKeysResults<K, D>> Fetch rows by keys
fetchByOffset (parameters: ojInputSearch.FetchByOffsetParameters<D>) => Promise<FetchByOffsetResults<K, D>> Fetch rows by offset
fetchFirst FetchFunc<K, D> Fetch the first block of data
getCapability oj.ojInputSearch.DedupCapability Determines whether this DataProvider defines certain features.
getTotalSize function Returns a Promise which resolves to the total size which is -1 if unknown count.
isEmpty function Returns a string that indicates if this data provider is empty. Valid values are: "yes": this data provider is empty. "no": this data provider is not empty. "unknown": it is not known if this data provider is empty until a fetch is made.
removeEventListener (type: string, callback: EventListenerOrEventListenerObject | null, options: boolean | EventListenerOptions | undefined) => void The **`removeEventListener()`** method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener)

DedupCapability

Properties:
Name Type
type "none" | "global" | "iterator"

FetchAttribute

Properties:
Name Type Argument Description
attributes Array<string | ojInputSearch.FetchAttribute> <optional>
Optional attributes property which specifies at least which attributes of the value we want to include. If not specified then the default attributes are included. If the value is a primitive then this is ignored. Expressions like "!" and "@default" are also supported. e.g. ['!lastName', '@default'] for everything except 'lastName'. For only 'firstName' and 'lastName' we'd have ['firstName', 'lastName']. Order does not matter when
name string The name of the attribute or sub object or related object.

FetchByKeysParameters<K>

The interface for FetchByKeysParameters
Properties:
Name Type Argument Description
attributes Array<string | ojInputSearch.FetchAttribute> <optional>
attributes to include in the result. If specified, then at least these set of attributes will be included in each row results. If not specified then the default attributes will be included.
keys Set<K>
scope "global" | "local" <optional>
signal AbortSignal <optional>
Optional signal to be assocated with fetchByKeys request so that the request can be aborted this signal later

FetchByOffsetParameters<D>

The interface for FetchByOffsetParameters
Properties:
Name Type Argument Description
attributes Array<string | ojInputSearch.FetchAttribute> <optional>
attributes to include in the result. If specified, then at least these set of attributes will be included in each row results. If not specified then the default attributes will be included.
clientId symbol <optional>
Optional symbol that can uniquely identify the consumer of the DataProvider.
filterCriterion Filter<D> <optional>
filter criterion to apply.
includeFilteredRowCount "enabled" | "disabled" <optional>
Optional property to request that the total filtered row count be included in the fetch result.
offset number
signal AbortSignal <optional>
Optional signal to be assocated with fetchByOffset request so that the request can be aborted this signal later
size number <optional>
# of rows to fetch starting from offset. If fewer than that number of rows exist, the fetch will succeed but be truncated.
sortCriteria Array.<oj.ojInputSearch.SortCriterion.<D>> <optional>
sort criteria to apply.

SortCriterion<D>

Properties:
Name Type Description
attribute keyof D sort attribute.
direction "ascending" | "descending" sort direction.

SuggestionItemTemplateContext<K,D>

Properties:
Name Type Argument Description
data D The data for the current suggestion
index number The zero-based index of the current suggestion
key K The key of the current suggestion
metadata ItemMetadata.<Key> The metadata for the current suggestion
searchText (string|null) <optional>
The search text entered by the user

ValueDetail<K,D>

Properties:
Name Type Argument Description
itemContext ojcommontypes.ItemContext.<Key, Data> <optional>
The data provider context for the search text, if available.
previousValue string <optional>
The previous search text.
value string <optional>
The search text.