diff --git a/docs/examples/simple.tsx b/docs/examples/simple.tsx
index f550b66..af455ea 100644
--- a/docs/examples/simple.tsx
+++ b/docs/examples/simple.tsx
@@ -28,6 +28,7 @@ export default () => (
{
diff --git a/src/Rate.tsx b/src/Rate.tsx
index c2492ae..44ef21c 100644
--- a/src/Rate.tsx
+++ b/src/Rate.tsx
@@ -8,7 +8,7 @@ import type { StarProps } from './Star';
function noop() {}
-export interface RateProps extends Pick {
+export interface RateProps extends Pick {
value?: number;
defaultValue?: number;
allowClear?: boolean;
@@ -45,6 +45,7 @@ class Rate extends React.Component {
onHoverChange: noop,
tabIndex: 0,
direction: 'ltr',
+ highlightSelectedOnly: false,
};
stars: Record;
@@ -249,6 +250,7 @@ class Rate extends React.Component {
characterRender,
tabIndex,
direction,
+ highlightSelectedOnly
} = this.props;
const { value, hoverValue, focused } = this.state;
const stars = [];
@@ -269,6 +271,7 @@ class Rate extends React.Component {
character={character}
characterRender={characterRender}
focused={focused}
+ highlightSelectedOnly={highlightSelectedOnly}
/>,
);
}
diff --git a/src/Star.tsx b/src/Star.tsx
index df61d3e..305c0b9 100644
--- a/src/Star.tsx
+++ b/src/Star.tsx
@@ -15,6 +15,7 @@ export interface StarProps {
characterRender?: (origin: React.ReactElement, props: StarProps) => React.ReactNode;
focused?: boolean;
count?: number;
+ highlightSelectedOnly?: boolean;
}
export default class Star extends React.Component {
@@ -36,7 +37,7 @@ export default class Star extends React.Component {
};
getClassName() {
- const { prefixCls, index, value, allowHalf, focused } = this.props;
+ const { prefixCls, index, value, allowHalf, focused, highlightSelectedOnly } = this.props;
const starValue = index + 1;
let className = prefixCls;
if (value === 0 && index === 0 && focused) {
@@ -46,7 +47,7 @@ export default class Star extends React.Component {
if (focused) {
className += ` ${prefixCls}-focused`;
}
- } else {
+ } else if (!highlightSelectedOnly || value === index + 1) {
className += starValue <= value ? ` ${prefixCls}-full` : ` ${prefixCls}-zero`;
if (starValue === value && focused) {
className += ` ${prefixCls}-focused`;