Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Slider] Fix incorrect marks displayed due to duplicate keys in range #33526

Merged
merged 3 commits into from Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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}>
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
<Mark
data-index={index}
{...markProps}
Expand Down
12 changes: 12 additions & 0 deletions packages/mui-material/src/Slider/Slider.test.js
Expand Up @@ -952,6 +952,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