MCPcopy Create free account
hub / github.com/UI5/webcomponents / _selectItem

Method _selectItem

packages/main/src/ComboBox.ts:1398–1438  ·  view source on GitHub ↗
(e: CustomEvent<ListItemClickEventDetail>)

Source from the content-addressed store, hash-verified

1396 }
1397
1398 _selectItem(e: CustomEvent<ListItemClickEventDetail>) {
1399 const item = e.detail.item as ComboBoxItem;
1400
1401 this._selectedItemText = item.text || "";
1402 this._selectionPerformed = true;
1403
1404 const sameItemSelected = this.value === this._selectedItemText;
1405 const sameSelectionPerformed = this.value.toLowerCase() === this.filterValue.toLowerCase();
1406
1407 if (sameItemSelected && sameSelectionPerformed) {
1408 this._fireChangeEvent(); // Click on an already typed, but not memoized value shouold also trigger the change event
1409 return this._closeRespPopover();
1410 }
1411
1412 this.value = this._selectedItemText;
1413 // On first item select the _useSelectedValue is still false.
1414 // In case the item has a value property, we set the _useSelectedValue to true to start working with the value instead with the text.
1415 if (!this._useSelectedValue && item.value !== undefined) {
1416 this._useSelectedValue = true;
1417 }
1418
1419 // Always set selectedValue when the item has a value property, regardless of _useSelectedValue state
1420 if (item.value !== undefined) {
1421 this.selectedValue = item.value;
1422 } else if (this._useSelectedValue) {
1423 // Only clear selectedValue if we were using it before
1424 this.selectedValue = undefined;
1425 }
1426
1427 if (!item.selected) {
1428 this.fireDecoratorEvent("selection-change", {
1429 item,
1430 });
1431 }
1432
1433 this._fireChangeEvent();
1434 this._closeRespPopover();
1435
1436 // reset selection
1437 this.inner.setSelectionRange(this.value.length, this.value.length);
1438 }
1439
1440 _onItemFocus() {
1441 this._itemFocused = true;

Callers

nothing calls this directly

Calls 2

_fireChangeEventMethod · 0.95
_closeRespPopoverMethod · 0.95

Tested by

no test coverage detected