/*! * SAPUI5 * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. */ import Text from "sap/m/Text"; import Icon from "sap/ui/core/Icon"; import * as SearchHelper from "sap/esh/search/ui/SearchHelper"; import { $TextSettings } from "sap/m/Text"; import Control from "sap/ui/core/Control"; import { MetadataOptions } from "sap/ui/base/ManagedObject"; import RenderManager from "sap/ui/core/RenderManager"; import TooltipBase from "sap/ui/core/TooltipBase"; export interface SearchTextSettings extends $TextSettings { icon?: Icon; } /** * Display search result attribute (text only, no navigation) on custom grid control tiles * */ /** * Constructs a new SearchText to display an attribute (text only, no navigation) on custom grid control tiles. * * @param {string} [sId] ID for the new control, generated automatically if no ID is given * @param {object} [text] Text to be displayed * @param {object} [maxlines] Maximum number of text lines to be displayed * @param {object} [wrapping] Text can wrap automatically within the given width * * @class * * This is the SAPUI5 search text control to display attributes of search results. * For attribute with navigation use control sap.esh.search.ui.SearchLink. * Use in combination with control SearchCompositeControl by the Enterprise Search Team. * * @extends sap.m.Text * * @author SAP SE * @version 1.150.1 * * @see https://help.sap.com/viewer/691cb949c1034198800afde3e5be6570/2.0.08/en-US/ce86ef2fd97610149eaaaa0244ca4d36.html SAP HANA Search Developer Guide * @see https://help.sap.com/docs/SAP_S4HANA_ON-PREMISE/90b263323d0a4976bcda415e6bd20ea4/d93d53ef27074bbf9a4849c4a4c3e360.html Enterprise Search in SAP S/4HANA * * * @constructor * @public * @alias sap.esh.search.ui.controls.resultview.SearchText * @since 1.93.0 * @name sap.esh.search.ui.controls.resultview.SearchText * */ /** * @namespace sap.esh.search.ui.controls */ export default class SearchText extends Text { static readonly metadata: MetadataOptions = { library: "sap.esh.search.ui.controls.resultview", properties: { maxLines: { type: "int", }, text: { type: "string", defaultValue: "", }, wrapping: { type: "boolean", defaultValue: true, }, }, aggregations: { _text: { type: "sap.m.Text", multiple: false, }, icon: { type: "sap.ui.core.Icon", multiple: false, }, }, }; constructor(sId?: string, settings?: SearchTextSettings) { super(sId, settings); } init(): void { this.setAggregation( "_text", new Text(this.getId() + "-Text", { text: this.getProperty("text"), maxLines: this.getProperty("maxLines"), wrapping: this.getProperty("wrapping"), }).addStyleClass("sapUshellSearchTextText") ); } /** * Assigns the given css class to the inner text control, because that's the way * it worked before the control was refactored to be a composite control. Now * an additional span element is added around the text control, see renderer method. * @param sStyleClass name of the css class to be added * @returns SearchText */ addStyleClass(sStyleClass: string): this { (this.getAggregation("_text") as Text).addStyleClass(sStyleClass); return this; } addStyleClassInternal(sStyleClass: string): this { super.addStyleClass(sStyleClass); return this; } setText(sText: string): this { this.setProperty("text", sText); (this.getAggregation("_text") as Text).setText(sText); return this; } setMaxLines(iMaxLines: int): this { this.setProperty("maxLines", iMaxLines); (this.getAggregation("_text") as Text).setMaxLines(iMaxLines); return this; } setWrapping(bWrapping: boolean): this { this.setProperty("wrapping", bWrapping); (this.getAggregation("_text") as Text).setWrapping(bWrapping); return this; } setIcon(icon: Icon): SearchText { if (icon instanceof Icon) { icon.addStyleClass("sapUshellSearchTextIcon"); this.setAggregation("icon", icon); } return this; } setTooltip(sTooltip?: string | TooltipBase): this { (this.getAggregation("_text") as Text).setTooltip(sTooltip); return this; } onAfterRendering(oEvent): void { super.onAfterRendering(oEvent); if (this.isDestroyed()) { return; } // move icon to the front of the text const iconDomRef = (this.getAggregation("icon") as Icon)?.getDomRef(); const textDomRef = (this.getAggregation("_text") as Text)?.getDomRef() as HTMLElement; if (iconDomRef) { textDomRef.insertBefore(iconDomRef, textDomRef.firstChild); } // recover bold tag with the help of text() in a safe way SearchHelper.boldTagUnescaper(textDomRef); SearchHelper.calculateTooltipForwordEllipsis(textDomRef); } static renderer = { apiVersion: 2, render: (rm: RenderManager, control: SearchText) => { rm.openStart("span", control); rm.class("sapUshellSearchText"); if (!control.getWrapping()) { rm.class("sapUshellSearchText-nowrap"); } const tooltip = control.getTooltip_AsString(); if (tooltip) { rm.attr("title", tooltip); } rm.openEnd(); const icon = control.getAggregation("icon") as Icon; if (icon) { rm.renderControl(icon as Icon); } rm.renderControl(control.getAggregation("_text")); rm.close("span"); }, }; }