Search code examples
javascripticonstooltipsapui5listitem

How to override listItem icon tooltip?


I am trying to change tooltip of icon which is in core: ListItem.

tooltip property of listItem is changing tooltip of whole item which is not what im looking for.

<core:ListItem icon="sap-icon://message-error" tooltip="someTooltip" />

Solution

  • Either you need to extend the core: ListItem OR you can use a workaround for your problem using sap.m.CustomListItem and specify the icon tooltip.

    View.xml

    <List items="{/items}">
      <CustomListItem>
        <HBox>
          <core:Icon size="2rem" width="50px" tooltip="{tooltipInfo}" src="{icon}" />               
          <VBox>
            <Link text="{title}"/>
            <Label text="{type}"/>
          </VBox>
        </HBox>
      </CustomListItem>
    </List>
    

    Controller.js

    var oModel = new sap.ui.model.json.JSONModel();
    oModel.setData({
      "items": [
         { "tooltipInfo": "Group1", "icon": "sap-icon://hint", "type": "Monitor", "title": "Tiles: a modern UI design pattern for overview & navigation."},
         { "tooltipInfo": "Group2", "icon": "sap-icon://inbox", "number": "89", "title": "Approve Leave Requests", "info": "Overdue", "infoState": "Error" },
         { "tooltipInfo": "Group3", "icon": "sap-icon://email", "type": "Create", "title": "Create Leave Requests", "info": "28 Days Left", "infoState": "Success" },
         { "tooltipInfo": "Group4", "icon": "sap-icon://travel-expense-report", "number": "281", "numberUnit": "euro", "title": "Travel Reimbursement", "info": "1 day ago" },
         { "tooltipInfo": "Group5", "icon": "sap-icon://loan", "number": "2380", "numberUnit": "euro", "title": "My Salary", "info": "8 days ago" },
         { "tooltipInfo": "Group6", "icon": "sap-icon://lab", "number": "1", "numberUnit": "Invention", "title": "Test Lab Reports","info": "8 Days Ago" }]
    });
    this.getView().setModel(oModel);
    

    Output

    enter image description here