Skip to content

Commit 084c766

Browse files
nanabear0Denizhan Erdemsopranopillowlayershifter
authored
fix(react-rating): Pass missing Rating's itemLabel prop to its state so RatingItem consumes it from context (#33361)
Co-authored-by: Denizhan Erdem <derdem@microsoft.com> Co-authored-by: Esteban Munoz Facusse <estebanmu@microsoft.com> Co-authored-by: Oleksandr Fediashov <olfedias@microsoft.com>
1 parent 870fdfd commit 084c766

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "fix: Pass missing Rating's itemLabel prop to its state so RatingItem consumes it from context.",
4+
"packageName": "@fluentui/react-rating",
5+
"email": "derdem@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

packages/react-components/react-rating/library/src/components/Rating/Rating.test.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,12 @@ describe('Rating', () => {
5151
expect(onChange.mock.calls[1][1].value).toBe(3);
5252
expect(onChange.mock.calls[2][1].value).toBe(2);
5353
});
54+
it('creates RadioItems with correct aria-labels', () => {
55+
const onChange = jest.fn();
56+
const { getAllByRole } = render(<Rating onChange={onChange} itemLabel={num => `item #${num}`} />);
57+
const items = getAllByRole('radio');
58+
expect(items[0].getAttribute('aria-label')).toBe('item #1');
59+
expect(items[1].getAttribute('aria-label')).toBe('item #2');
60+
expect(items[2].getAttribute('aria-label')).toBe('item #3');
61+
});
5462
});

packages/react-components/react-rating/library/src/components/Rating/useRating.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const useRating_unstable = (props: RatingProps, ref: React.Ref<HTMLDivEle
3131
onChange,
3232
step = 1,
3333
size = 'extra-large',
34+
itemLabel,
3435
} = props;
3536

3637
const [value, setValue] = useControllableState({
@@ -56,6 +57,7 @@ export const useRating_unstable = (props: RatingProps, ref: React.Ref<HTMLDivEle
5657
name,
5758
step,
5859
size,
60+
itemLabel,
5961
value,
6062
hoveredValue,
6163
components: {

0 commit comments

Comments
 (0)