Skip to content

Commit

Permalink
[material-ui][Rating] modify with default value
Browse files Browse the repository at this point in the history
  • Loading branch information
declan.zou committed Jul 4, 2024
1 parent 1c140f9 commit 9ff905c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 2 additions & 4 deletions packages/mui-material/src/Rating/Rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,7 @@ const defaultIcon = <Star fontSize="inherit" />;
const defaultEmptyIcon = <StarBorder fontSize="inherit" />;

function defaultLabelText(value) {
const _value = value || 0;
return `${_value} Star${_value > 1 ? 's' : ''}`;
return `${value || '0'} Star${value !== 1 ? 's' : ''}`;
}

const Rating = React.forwardRef(function Rating(inProps, ref) {
Expand Down Expand Up @@ -684,8 +683,7 @@ Rating.propTypes /* remove-proptypes */ = {
* @param {number} value The rating label's value to format.
* @returns {string}
* @default function defaultLabelText(value) {
* const _value = value || 0;
* return `${_value} Star${_value > 1 ? 's' : ''}`;
* return `${value || "0"} Star${value !== 1 ? 's' : ''}`;
* }
*/
getLabelText: PropTypes.func,
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/Rating/Rating.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ describe('<Rating />', () => {
it('can be labelled with getLabelText when non set value', () => {
render(<Rating readOnly />);

expect(screen.getByRole('img')).toHaveAccessibleName('0 Heart');
expect(screen.getByRole('img')).toHaveAccessibleName('0 Hearts');
});

it('should have readOnly class applied', () => {
Expand Down

0 comments on commit 9ff905c

Please sign in to comment.