React Rating Overview

    The Ignite UI for React Rating component allows users to view and provide feedback.

    EXAMPLE
    TSX
    CSS

    Like this sample? Get access to our complete Ignite UI for React toolkit and start building your own apps in minutes. Download it for free.

    First, you need to the install the corresponding Ignite UI for React npm package by running the following command:

    npm install igniteui-react
    cmd

    Before using the IgrRating, you need to register it as follows:

    import { IgrRatingModule, IgrRating } from 'igniteui-react';
    import 'igniteui-webcomponents/themes/light/bootstrap.css';
    IgrRatingModule.register();
    tsx

    The simplest way to start using the IgrRating is as follows:

      <IgrRating></IgrRating>
    tsx

    This will create a five-star rating component that can be used to input and read data from.

    Using Custom Symbols

    The IgrRating component allows you to use custom symbols in place of the default star symbols. If you want to use a different symbol, like SVG, icon or another unicode symbol, you should place IgrRatingSymbol components between the opening and closing brackets of the IgrRating:

      <IgrRating label="Rate Experience" step=".5" size="large" hoverPreview="true">
        <IgrRatingSymbol key="0">
            <IgrIcon ref={this.iconRef} name='heart' collection="material" key="heart0"></IgrIcon>
        </IgrRatingSymbol>
        <IgrRatingSymbol key="1">
            <IgrIcon  name='heart' collection="material" key="heart1"></IgrIcon>                           
        </IgrRatingSymbol>
        <IgrRatingSymbol key="2">
          	<IgrIcon  name='heart' collection="material" key="heart2"></IgrIcon>                           
        </IgrRatingSymbol>
        <IgrRatingSymbol key="3">
           	<IgrIcon  name='heart' collection="material" key="heart3"></IgrIcon>                           
        </IgrRatingSymbol>
        <IgrRatingSymbol key="4">
           	<IgrIcon  name='heart' collection="material" key="heart4"></IgrIcon>                           
        </IgrRatingSymbol>                        
    </IgrRating> 
    tsx

    EXAMPLE
    TSX
    CSS

    The number of rating symbols between the opening and closing brackets of the rating component determines the max value.

    Single Selection

    The Ignite UI for React Rating component has a single selection mode that allows users to provide different icons/elements for the different rating values. In this case, only one of the icons/elements can be selected and reflect the feedback given by the user.

      <IgrRating single="true">
        <IgrRatingSymbol key="0">                           
    	<div key="div0">😣</div>	
    	<div key="empty-div0" slot="empty">😣</div>
        </IgrRatingSymbol>
        <IgrRatingSymbol key="1">                           
     	<div key="div1">😣</div>
            <div key="empty-div1" slot="empty">😣</div>
        </IgrRatingSymbol>
        <IgrRatingSymbol key="2">                           
            <div key="div2">😣</div>
            <div key="empty-div2" slot="empty">😣</div>
        </IgrRatingSymbol>
        <IgrRatingSymbol key="3">                           
            <div key="div3">😣</div>
            <div key="empty-div3" slot="empty">😣</div>
        </IgrRatingSymbol>
        <IgrRatingSymbol key="4">                           
            <div key="div4">😣</div>
            <div key="empty-div4" slot="empty">😣</div>
        </IgrRatingSymbol>                         
    </IgrRating>
    tsx

    EXAMPLE
    TSX
    CSS

    Keep in mind that the step attribute doesn't work with single selection mode.

    Ignite UI for React | CTA Banner

    Empty & Selected

    The Ignite UI for React Rating component allows users to use different icons/elements for the empty and the selected state of a single rating value. It is mandatory to provide 2 icons for each slot (empty and full) when declaring a symbol, even if they are the same. For instance:

    <IgrRatingSymbol key="0">
        <div key="div0"><IgrIcon name='bandage' collection="material" key="default0"></IgrIcon></div>
        <div key="empty-div0" slot='empty'><IgrIcon name='bacteria' collection="material" key="empty0"></IgrIcon></div> 
    </IgrRatingSymbol> 
    tsx

    EXAMPLE
    TSX
    CSS

    Configuration

    Single

    Turns on the single visual mode for the rating. Useful when using symbols that communicate unique values, like feedback emoji faces.

    Value

    The value attribute sets the current value of the component.

    Label

    The label attribute allows setting the label value of the rating component.

    Value Format

    A format string which sets aria-valuetext. All instances of it will be replaced with the current value of the control. Important for screen-readers and useful for localization.

    Max Value

    The max attribute sets the maximum allowed value of the rating component.

    Step

    The step attribute sets the allowed fraction of steps between two symbols. Useful when splitting the rating symbols in halves.

    Hover Preview

    The hoverPreview attribute makes the component show the possible outcome of user selection on hover. It is useful when you want to give instant feedback about what the selected value could be.

    Read-Only

    The readOnly attribute allows the users to set the IgrRating in read-only mode. This attribute is useful when you want to use the component for information purposes only.

    Disabled

    The disabled attribute disables the component, making it impossible to select a value using the mouse or keyboard.

    Methods

    Step Up

    The stepUp method increments the value of the component by n steps. Determined by the step factor.

    Step Down

    The stepDown method decrements the value of the component by n steps. Determined by the step factor.

    Events

    The IgrRating component emits two separate events - hover and change.

    Hover Event

    The hover event is fired when hovering over a symbol. It provides the value of the symbol under the mouse cursor. Useful for creating custom value labels and readouts.

    Change Event

    The change event is fired when the selected value changes.

    Styling

    The IgrRating component provides base, label, value-label, symbols, and symbol that allow you to style the component symbols and its encompassing label.

    EXAMPLE
    TSX
    CSS

    API Reference

    Additional Resources