use svg image for toolbaritem image instead of class

Any chance it is possible to use svg images instead of classes for toolbar items?

3 Replies 1 reply marked as answer

SK Satheesh Kumar Balasubramanian Syncfusion Team October 26, 2020 10:17 AM UTC

Hi Happy,

Greetings from Syncfusion support! 

We have validated your case and we suggest you to define the <img> tag with required attributes inside the Template element of Toolbar. We have prepared a sample based on your requirement and refer below code for that


@using Syncfusion.EJ2.Blazor.Navigations 
 
<SfToolbar>
    <ToolbarItems>
        <ToolbarItem Type="@ItemType.Button" Text="New" TooltipText="New Record">
            <Template>
                <img class="empImg" src="images/new.svg" />
            </Template>
        </ToolbarItem>
        <ToolbarItem Type="@ItemType.Button" Text="Delete" TooltipText="Delete Record">
            <Template>
                <img class="empImg" src="/images/Delete.svg" />
            </Template>
        </ToolbarItem>
        <ToolbarItem Type="@ItemType.Separator"></ToolbarItem>
    </ToolbarItems>
</SfToolbar>

Also, you can download this sample from the below link 

Regards 
Satheesh Kumar B


Marked as answer

HA HappyCamper October 26, 2020 02:25 PM UTC

ok, done that.  I guess I have to then also explicitly also add text after the image should I want text to show on the button, correct? (Setting the Text property when using the template doesn't set the text)  

Also, the hover over effect doesn't work when using the template.  Anything I need to do to easily reenable it?

Any chance that natively supporting svgs or images for the icons of a toolbaritem can be requested as a feature?  I'm sure there's a bunch of use cases where others would also like to use that as the standard.


SK Satheesh Kumar Balasubramanian Syncfusion Team October 27, 2020 05:37 PM UTC

Hi Happy, 
  
Thanks for your update. 
  
We have validated your reported case at our end and suggest you to define the SfButton inside template of Toolbar Item to overcome the hover over effect and doesn't set the text to Toolbar Item issue. 
  
Code snippet:  
@using Syncfusion.Blazor.Navigations 
@using Syncfusion.Blazor.Buttons 
  
<SfToolbar> 
    <ToolbarItems> 
        <ToolbarItem Text="New" TooltipText="New Record"> 
            <Template> 
                <div> 
                    <SfButton IsToggle="false"> 
                        <span>New</span> 
                        <img class="empImg" src="images/new.svg" /> 
                    </SfButton> 
                </div> 
            </Template> 
        </ToolbarItem> 
        <ToolbarItem Text="Delete" TooltipText="Delete Record"> 
            <Template> 
                <div> 
                    <SfButton IsToggle="false"> 
                        <span>Delete</span> 
                        <img class="empImg" src="images/Delete.svg" /> 
                    </SfButton> 
                </div> 
            </Template> 
        </ToolbarItem> 
    </ToolbarItems> 
</SfToolbar> 
  
  
  
Kindly try the above sample and get back to us if you need further assistance. 

Regards, 
Satheesh Kumar B 


Loader.
Up arrow icon