- Tooltip template
- Tooltip customization
Contact Support
Tooltip in Angular Rating Component
27 Apr 20247 minutes to read
The rating component supports tooltip to show additional information in rating items by setting the showTooltip
property. If enabled, the tooltip appears when the user hovers over a rating item.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { FormsModule } from '@angular/forms'
import { RatingModule } from '@syncfusion/ej2-angular-inputs'
import { enableRipple } from '@syncfusion/ej2-base'
import { Component } from '@angular/core';
@Component({
imports: [
FormsModule, RatingModule
],
standalone: true,
selector: 'app-root',
template: `<!-- To Render Rating component. -->
<div class="wrap">
<input ejs-rating id="rating" showTooltip="true" value="3" />
</div>`
})
export class AppComponent { }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Tooltip template
You can use the tooltipTemplate
tag directive to specify a custom template for the tooltip
of the rating. The current value of the rating will be passed as the value
property in the template context when building the content of the tooltip. This allows you to include dynamic information about the rating in the template.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { FormsModule } from '@angular/forms'
import { RatingModule } from '@syncfusion/ej2-angular-inputs'
import { enableRipple } from '@syncfusion/ej2-base'
import { Component } from '@angular/core';
@Component({
imports: [
FormsModule, RatingModule
],
standalone: true,
selector: 'app-root',
template: `<!-- To Render Rating component. -->
<div class="wrap">
<input ejs-rating id="rating" value="3" showTooltip="true" [tooltipTemplate]="tooltipTemplate" />
<ng-template #tooltipTemplate let-data="">
<div [ngSwitch]="data.value">
<span *ngSwitchCase="1" >Angry</span>
<span *ngSwitchCase="2" >Sad</span>
<span *ngSwitchCase="3" >Neutral</span>
<span *ngSwitchCase="4" >Good</span>
<span *ngSwitchDefault >Happy</span>
</div>
</ng-template>
</div>`
})
export class AppComponent { }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Tooltip customization
You can customize the appearance of the tooltips using the cssClass
property of the rating component and by defining the custom styles for tooltip elements like the below example.
You can find more information about customizing the appearance of the tooltip in the Tooltip Customization documentation.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { FormsModule } from '@angular/forms'
import { RatingModule } from '@syncfusion/ej2-angular-inputs'
import { enableRipple } from '@syncfusion/ej2-base'
import { Component } from '@angular/core';
@Component({
imports: [
FormsModule, RatingModule
],
standalone: true,
selector: 'app-root',
template: `<!-- To Render Rating component. -->
<div class="wrap">
<input ejs-rating id="rating" value="3" showTooltip="true" cssClass='customtooltip' />
</div>`
})
export class AppComponent { }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
/* Represents the styles for loader */
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
.wrap {
margin: 50px auto;
text-align: center;
}
/* To change the radius of the tooltip corners. */
.customtooltip.e-tooltip-wrap {
border-radius: 3px;
}
/* To change the size of the tooltip content. */
.customtooltip.e-tooltip-wrap .e-tip-content {
font-size:14px;
}
/* To change the border color and width for tooltip. */
.customtooltip.e-tooltip-wrap.e-popup {
border: 2px solid #000000;
}
/* To change the color for arrow of the tooltip. */
.customtooltip.e-tooltip-wrap .e-arrow-tip-inner.e-tip-bottom {
border: 12px #9693
}
/* To change the top border color for arrow of the tooltip. */
.customtooltip.e-tooltip-wrap .e-arrow-tip-outer.e-tip-bottom {
border-top: 9.5px solid #000000;
}