Skip to content

Commit

Permalink
[SliderUnstyled] Fix disabledSwap not being respected in `onChangeC…
Browse files Browse the repository at this point in the history
…ommitted` (#32647)
  • Loading branch information
JeanPetrov committed May 19, 2022
1 parent aad056e commit e6024d4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/mui-base/src/SliderUnstyled/useSlider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ export default function useSlider(props: UseSliderProps) {
return;
}

const { newValue } = getFingerNewValue({ finger, values });
const { newValue } = getFingerNewValue({ finger, move: true, values });

setActive(-1);
if (nativeEvent.type === 'touchend') {
Expand Down
26 changes: 26 additions & 0 deletions packages/mui-material/src/Slider/Slider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,32 @@ describe('<Slider />', () => {
expect(handleChange.args[1][1]).to.deep.equal([20, 20]);
expect(document.activeElement).to.have.attribute('data-index', '1');
});

it('should bound the value when moving the first behind the second', () => {
const handleChange = spy();
const { container } = render(
<Slider defaultValue={[20, 30]} disableSwap onChange={handleChange} />,
);

stub(container.firstChild, 'getBoundingClientRect').callsFake(() => ({
width: 100,
height: 10,
bottom: 10,
left: 0,
}));

fireEvent.touchStart(
container.firstChild,
createTouches([{ identifier: 1, clientX: 15, clientY: 0 }]),
);
fireEvent.touchMove(
document.body,
createTouches([{ identifier: 1, clientX: 40, clientY: 0 }]),
);
expect(handleChange.args[0][1]).to.deep.equal([15, 30]);
expect(handleChange.args[1][1]).to.deep.equal([30, 30]);
expect(document.activeElement).to.have.attribute('data-index', '0');
});
});

describe('prop: size', () => {
Expand Down

0 comments on commit e6024d4

Please sign in to comment.