Skip to content

Commit 156fb3d

Browse files
authored
fix(rating): Value rounding calculation when step is 1 (#1551)
Closes #1548
1 parent 9ec2a59 commit 156fb3d

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99
- #### Dialog
1010
- A new `message` slot that renders text content inside the dialog component has been added. The enhancement was introduced to align the design behavior between Ignite UI for WC and Ignite UI for Angular, ensuring a consistent user experience across products. The newly added `message' slot comes with additional styling with a max-width of 40 characters. The default slot is also still available for rendering content inside the dialog without limiting the component's width.
1111

12+
### Fixed
13+
- #### Rating
14+
- Inaccurate value calculation on selection when step is set to 1 [#1548](https://github.com/IgniteUI/igniteui-webcomponents/issues/1548)
15+
1216
## [5.2.0] - 2025-01-09
1317
### Added
1418
- Form-associated elements now have a `defaultValue` property (`defaultChecked` for radio buttons, checkboxes, and switches). When a form is reset, components will use this property’s value as their new value or checked state.

src/components/common/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const clamp = (number: number, min: number, max: number) =>
1616
Math.max(min, Math.min(number, max));
1717

1818
export function numberOfDecimals(number: number): number {
19-
const decimals = last(number.toString().split('.'));
19+
const [_, decimals] = number.toString().split('.');
2020
return decimals ? decimals.length : 0;
2121
}
2222

src/components/rating/rating.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,18 @@ describe('Rating component', () => {
306306
expect(el.value).to.equal(2.5);
307307
});
308308

309+
it('issue-1548 - Inaccurate value calculation when precision == 1', async () => {
310+
const eventSpy = spy(el, 'emitEvent');
311+
312+
const symbol = getRatingSymbols(el).item(2);
313+
const { x, width } = getBoundingRect(symbol);
314+
// Simulate offset click when precision == 1
315+
simulateClick(symbol, { clientX: x + width / 4 });
316+
317+
expect(eventSpy).calledOnceWithExactly('igcChange', { detail: 3 });
318+
expect(el.value).to.equal(3);
319+
});
320+
309321
it('correctly reflects hover state', async () => {
310322
const eventSpy = spy(el, 'emitEvent');
311323
el.value = 2;

0 commit comments

Comments
 (0)