Skip to content

Rate

Rules

Basic Example

js
const rule = {
    type:"rate",
    field:"rate",
    title:"Recommendation Level",
    value:3.5,
    props:{
        count: 10,
    }
}

Props Configuration Examples

Allow Half-Star Rating

js
const rule = {
    type:"rate",
    field:"rating",
    title:"Product Rating",
    value:0,
    props:{
        allowHalf: true,
        count: 5,
    }
}

Allow Clear

js
const rule = {
    type:"rate",
    field:"rating",
    title:"Service Rating",
    value:0,
    props:{
        count: 5,
        allowClear: true,
    }
}

Readonly Rating

js
const rule = {
    type:"rate",
    field:"rating",
    title:"Average Rating",
    value:4.5,
    props:{
        readonly: true,
        allowHalf: true,
    }
}

Smiley Grading

js
const rule = {
    type:"rate",
    field:"rating",
    title:"Satisfaction",
    value:0,
    props:{
        grading: true,
        count: 5,
    }
}

Events Examples

Handle Rating Changes

js
const rule = {
    type:"rate",
    field:"rating",
    title:"Product Rating",
    value:0,
    props:{
        allowHalf: true,
        count: 5,
    },
    on: {
        change: (value) => {
            console.log('Rating changed:', value);
        },
    },
}

Show Feedback After Rating

js
const rule = [
    {
        type:"rate",
        field:"rating",
        title:"Product Rating",
        value:0,
        props:{
            allowHalf: true,
            count: 5,
        },
        inject: true,
        on: {
            change: ($inject, value) => {
                // Display feedback based on rating
                const feedbackMap = {
                    1: "Very Poor",
                    2: "Poor",
                    3: "Average",
                    4: "Good",
                    5: "Excellent",
                };
                const level = Math.ceil(value);
                $inject.api.setValue('feedback', feedbackMap[level] || '');
            },
        },
    },
    {
        type:"input",
        field:"feedback",
        title:"Feedback",
        props: {
            disabled: true,
        },
    },
]

Complete configuration items: arco-design_Rate

value: Number

Props

ParameterDescriptionTypeDefault
countTotal number of ratingsnumber5
allow-halfWhether to allow half selectionbooleanfalse
allow-clearWhether to allow clearbooleanfalse
gradingWhether to enable smiley gradingbooleanfalse
readonlyWhether in readonly statebooleanfalse
disabledWhether disabledbooleanfalse

Events

Event NameDescriptionParameters
changeTriggered when value changesvalue: number
hover-changeTriggered when mouse moves over valuevalue: number

FormCreate is an open-source project released under the MIT License. Free for personal and commercial use.