Skip to content

Commit

Permalink
[Slider] Fixed incorrect marks displayed due to duplicate keys in ran…
Browse files Browse the repository at this point in the history
…ge (mui#33526)
  • Loading branch information
kskd1804 authored and Daniel Rabe committed Nov 29, 2022
1 parent a14f5e8 commit c924dfc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/mui-base/src/SliderUnstyled/SliderUnstyled.js
Expand Up @@ -210,7 +210,7 @@ const SliderUnstyled = React.forwardRef(function SliderUnstyled(props, ref) {
}

return (
<React.Fragment key={mark.value}>
<React.Fragment key={index}>
<Mark
data-index={index}
{...markProps}
Expand Down
12 changes: 12 additions & 0 deletions packages/mui-material/src/Slider/Slider.test.js
Expand Up @@ -987,6 +987,18 @@ describe('<Slider />', () => {
expect(container.querySelectorAll(`.${classes.mark}[data-index="2"]`).length).to.equal(1);
});

it('should correctly display mark labels when ranges slider have the same start and end', () => {
const getMarks = (value) => value.map((val) => ({ value: val, label: val }));

const { container, setProps } = render(
<Slider value={[100, 100]} marks={getMarks([100, 100])} />,
);
expect(container.querySelectorAll(`.${classes.markLabel}`).length).to.equal(2);

setProps({ value: [40, 60], marks: getMarks([40, 60]) });
expect(container.querySelectorAll(`.${classes.markLabel}`).length).to.equal(2);
});

it('should pass "name" and "value" as part of the event.target for onChange', () => {
const handleChange = stub().callsFake((event) => event.target);
const { getByRole } = render(
Expand Down

0 comments on commit c924dfc

Please sign in to comment.