Hello ,
I am looking for a way to add a custom icon to a tabView Page using the code below. The icon is placed in the images folder (\HOME\WebApps\TestApp\images). Tried different path references but the icon is not shown at all. I want to replace / update the icons during runtime to show different icons depending on the app state.
In the Tab component’s onMounted event, locate the corresponding HTML element and modify it manually.
const tabbarContents = this.all(
".fp-components-tabcontainer-tabbar-content"
);
if (tabbarContents && tabbarContents.length > 1) {
const iconElem = document.createElement("i");
iconElem.className =
"fp-components-tabcontainer-tabbar-icon";
// The name and path of your custom icon (relative to the controller project's file path)
iconElem.style.backgroundImage =
"url('./images/test.svg')";
iconElem.style.backgroundRepeat = "no-repeat";
iconElem.style.backgroundPosition = "center";
iconElem.style.backgroundSize = "contain";
iconElem.style.display = "inline-block";
iconElem.style.width = "20px";
iconElem.style.height = "20px";
// The relative index (starting from 0) of the tab you need to set.
tabbarContents[1].prepend(iconElem);
}
Thanks for your response. Added the code to a user function and connected it to the onMounted event. This will work. The custom icon is shown in the tab when the App is started the first time. However when changing the tabview the icon is gone. I assume when the tab view changes, the tab container is re-rendered or recreated, so that old element is replaced by a new one.
Do have any suggestions on how to solve this ?
My custom function
const addCustomIcon = async () => {
const tabbarContents = Instance.Tab_0.all(
".fp-components-tabcontainer-tabbar-content"
);
if (tabbarContents && tabbarContents.length > 1) {
const iconElem = document.createElement("i");
iconElem.className =
"fp-components-tabcontainer-tabbar-icon";
// The name and path of your custom icon (relative to the controller project's file path)
iconElem.style.backgroundImage =
"url('./images/1784285228818blackpadlock1172416.png')";
iconElem.style.backgroundRepeat = "no-repeat";
iconElem.style.backgroundPosition = "center";
iconElem.style.backgroundSize = "contain";
iconElem.style.display = "inline-block";
iconElem.style.width = "20px";
iconElem.style.height = "20px";
// The relative index (starting from 0) of the tab you need to set.
tabbarContents[0].prepend(iconElem);
}
}
export default addCustomIcon;
Aha, although I’m not sure which API you called to recreate or re-render the tab—I tried APIs such as addTab, activeViewIndex, and tabPosition—if you need it to be triggered immediately after the component has rendered, you’ll need to listen for the component’s lifecycle events.
In the API Documentation of AppStudio v1.3.0, the component lifecycle is introduced, and onMounted is only executed once during the component life.