Rate

Used for rating operation on something.
Importimport{ Rate }from"antd";

When To Use

  • Show evaluation.
  • A quick rating operation on something.

Examples

The simplest usage.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
normal

Add copywriting in rate components.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
allowClear: true
allowClear: false

Support set allow to clear star when click again.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
  • 1
    1
  • 2
    2
  • 3
    3
  • 4
    4
  • 5
    5

Can customize each character using (RateProps) => ReactNode.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

Support select half star.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

Read only, can't use mouse to interact.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
  • A
    A
  • A
    A
  • A
    A
  • A
    A
  • A
    A

Replace the default star to other character like alphabet, digit, iconfont or even Chinese word.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

API

Common props ref:Common props

PropertyDescriptiontypeDefaultVersion
allowClearWhether to allow clear when click againbooleantrue
allowHalfWhether to allow semi selectionbooleanfalse
autoFocusIf get focus when component mountedbooleanfalse
characterThe custom character of rateReactNode | (RateProps) => ReactNode<StarFilled />function(): 4.4.0
classNameThe custom class name of ratestring-
countStar countnumber5
defaultValueThe default valuenumber0
disabledIf read only, unable to interactbooleanfalse
keyboardSupport keyboard operationbooleantrue5.18.0
styleThe custom style object of rateCSSProperties-
tooltipsCustomize tooltip by each characterstring[]-
valueThe current valuenumber-
onBlurCallback when component lose focusfunction()-
onChangeCallback when select valuefunction(value: number)-
onFocusCallback when component get focusfunction()-
onHoverChangeCallback when hover itemfunction(value: number)-
onKeyDownCallback when keydown on componentfunction(event)-

Methods

NameDescription
blur()Remove focus
focus()Get focus

Design Token

Component TokenHow to use?

Token NameDescriptionTypeDefault Value
starBgStar background colorstringrgba(0,0,0,0.06)
starColorStar colorstring#fadb14
starHoverScaleScale of star when hoverundefined | readonly string[] | Transform | readonly Transform[] | { _multi_value_?: boolean; _skip_check_?: boolean; value: readonly string[] | Transform | (readonly string[] | Transform | undefined)[] | undefined }scale(1.1)
starSizeStar sizenumber20

Global TokenHow to use?