File tree Expand file tree Collapse file tree 3 files changed +23
-2
lines changed
Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44The format is based on [ Keep a Changelog] ( http://keepachangelog.com/ )
55and this project adheres to [ Semantic Versioning] ( http://semver.org/ ) .
66
7+ ## Unreleased
8+ ### Fixed
9+ - #### Rating
10+ - Inaccurate value rounding calculation when step is not 1 [ #1560 ] ( https://github.com/IgniteUI/igniteui-webcomponents/issues/1560 )
11+
712## [ 5.2.1] - 2025-01-23
813### Added
914- #### Dialog
Original file line number Diff line number Diff line change @@ -306,6 +306,19 @@ describe('Rating component', () => {
306306 expect ( el . value ) . to . equal ( 2.5 ) ;
307307 } ) ;
308308
309+ it ( 'rounds correctly to the next step, when the step is different than 1' , async ( ) => {
310+ const eventSpy = spy ( el , 'emitEvent' ) ;
311+ el . step = 0.4 ;
312+ await elementUpdated ( el ) ;
313+
314+ const symbol = getRatingSymbols ( el ) . item ( 0 ) ;
315+ const { x, width } = getBoundingRect ( symbol ) ;
316+ simulateClick ( symbol , { clientX : x + width * 0.55 } ) ; // Click 55% across the width of the symbol
317+
318+ expect ( eventSpy ) . calledOnceWithExactly ( 'igcChange' , { detail : 0.8 } ) ;
319+ expect ( el . value ) . to . equal ( 0.8 ) ;
320+ } ) ;
321+
309322 it ( 'issue-1548 - Inaccurate value calculation when precision == 1' , async ( ) => {
310323 const eventSpy = spy ( el , 'emitEvent' ) ;
311324
Original file line number Diff line number Diff line change @@ -325,13 +325,16 @@ export default class IgcRatingComponent extends FormAssociatedMixin(
325325 protected calcNewValue ( x : number ) {
326326 const { width, left, right } = this . container . getBoundingClientRect ( ) ;
327327 const percent = isLTR ( this ) ? ( x - left ) / width : ( right - x ) / width ;
328- const value = this . round ( this . max * percent + this . step / 2 ) ;
328+ const value = this . round ( this . max * percent ) ;
329329
330330 return clamp ( value , this . step , this . max ) ;
331331 }
332332
333333 protected round ( value : number ) {
334- return roundPrecise ( value , numberOfDecimals ( this . step ) ) ;
334+ return roundPrecise (
335+ Math . ceil ( value / this . step ) * this . step ,
336+ numberOfDecimals ( this . step )
337+ ) ;
335338 }
336339
337340 protected clipSymbol ( index : number , isLTR = true ) {
You can’t perform that action at this time.
0 commit comments