Skip to content

Commit ff7a2c7

Browse files
author
Sasha Kondrashov
committed
rating
1 parent 7cd9b7c commit ff7a2c7

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/modules/Rating/Rating.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ export interface StrictRatingProps {
3636
* Called after user selects a new rating.
3737
*
3838
* @param {SyntheticEvent} event - React's original SyntheticEvent.
39-
* @param {object} data - All props and proposed rating.
39+
* @param {object} props - All props.
40+
* @param {number} props - New rating.
4041
*/
41-
onRate?: (event: React.MouseEvent<HTMLDivElement>, data: RatingProps) => void
42+
onRate?: (event: React.MouseEvent<HTMLDivElement>, props: RatingProps, rating: number) => void
4243

4344
/** The current number of active icons. */
4445
rating?: number | string

src/modules/Rating/Rating.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const Rating = React.forwardRef(function (props, ref) {
5858
setRating(newRating)
5959
setIsSelecting(false)
6060

61-
_.invoke(props, 'onRate', e, { ...props, rating: newRating })
61+
_.invoke(props, 'onRate', e, props, newRating)
6262
}
6363

6464
const handleIconMouseEnter = (e, { index }) => {

test/specs/modules/Rating/Rating-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,16 +241,16 @@ describe('Rating', () => {
241241

242242
describe('onRate', () => {
243243
it('is called with (event, { rating, maxRating } on icon click', () => {
244-
const spy = sandbox.spy()
244+
const onRate = sandbox.spy()
245245
const event = { fake: 'event data' }
246246

247-
mount(<Rating maxRating={3} onRate={spy} />)
247+
mount(<Rating maxRating={3} onRate={onRate} />)
248248
.find('RatingIcon')
249249
.last()
250250
.simulate('click', event)
251251

252-
spy.should.have.been.calledOnce()
253-
spy.should.have.been.calledWithMatch(event, { rating: 3, maxRating: 3 })
252+
onRate.should.have.been.calledOnce()
253+
onRate.should.have.been.calledWithMatch(event, { maxRating: 3 }, 3)
254254
})
255255
})
256256

0 commit comments

Comments
 (0)