Skip to content

Commit

Permalink
[Slider] Fix Home / End regression (#526)
Browse files Browse the repository at this point in the history
Co-authored-by: Michał Dudak <[email protected]>
  • Loading branch information
sai6855 and michaldudak authored Aug 21, 2024
1 parent 8883827 commit 919d9ca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
22 changes: 11 additions & 11 deletions packages/mui-base/src/Slider/Root/SliderRoot.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,7 @@ describe('<Slider.Root />', () => {
expect(handleValueChange.args[1][0]).to.deep.equal(9);
});

describe('key: Home', () => {
describe('key: End', () => {
it('sets value to max in a single value slider', async () => {
const handleValueChange = spy();
const { container } = await render(
Expand All @@ -1383,7 +1383,7 @@ describe('<Slider.Root />', () => {
(input as HTMLInputElement).focus();
});

fireEvent.keyDown(input!, { key: 'Home' });
fireEvent.keyDown(input!, { key: 'End' });
expect(handleValueChange.callCount).to.equal(1);
expect(handleValueChange.args[0][0]).to.deep.equal(77);
});
Expand All @@ -1401,24 +1401,24 @@ describe('<Slider.Root />', () => {
thumbOne.focus();
});

fireEvent.keyDown(thumbOne, { key: 'Home' });
fireEvent.keyDown(thumbOne, { key: 'End' });
expect(handleValueChange.callCount).to.equal(1);
expect(handleValueChange.args[0][0]).to.deep.equal([50, 50]);
fireEvent.keyDown(thumbOne, { key: 'Home' });
fireEvent.keyDown(thumbOne, { key: 'End' });
expect(handleValueChange.callCount).to.equal(1);

await act(() => {
thumbTwo.focus();
});

fireEvent.keyDown(thumbTwo, { key: 'Home' });
fireEvent.keyDown(thumbTwo, { key: 'End' });
expect(handleValueChange.callCount).to.equal(2);
expect(handleValueChange.args[1][0]).to.deep.equal([50, 77]);
});
});

describe('key: End', () => {
it('sets value to min on End', async () => {
describe('key: Home', () => {
it('sets value to min on Home', async () => {
const handleValueChange = spy();
const { container } = await render(
<TestSlider defaultValue={55} onValueChange={handleValueChange} min={17} />,
Expand All @@ -1432,7 +1432,7 @@ describe('<Slider.Root />', () => {
(input as HTMLInputElement).focus();
});

fireEvent.keyDown(input!, { key: 'End' });
fireEvent.keyDown(input!, { key: 'Home' });
expect(handleValueChange.callCount).to.equal(1);
expect(handleValueChange.args[0][0]).to.deep.equal(17);
});
Expand All @@ -1450,17 +1450,17 @@ describe('<Slider.Root />', () => {
thumbTwo.focus();
});

fireEvent.keyDown(thumbTwo, { key: 'End' });
fireEvent.keyDown(thumbTwo, { key: 'Home' });
expect(handleValueChange.callCount).to.equal(1);
expect(handleValueChange.args[0][0]).to.deep.equal([20, 20]);
fireEvent.keyDown(thumbTwo, { key: 'End' });
fireEvent.keyDown(thumbTwo, { key: 'Home' });
expect(handleValueChange.callCount).to.equal(1);

await act(() => {
thumbOne.focus();
});

fireEvent.keyDown(thumbOne, { key: 'End' });
fireEvent.keyDown(thumbOne, { key: 'Home' });
expect(handleValueChange.callCount).to.equal(2);
expect(handleValueChange.args[1][0]).to.deep.equal([7, 20]);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/mui-base/src/Slider/Thumb/useSliderThumb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export function useSliderThumb(parameters: UseSliderThumbParameters) {
case 'PageDown':
newValue = getNewValue(thumbValue, largeStep, -1, min, max);
break;
case 'Home':
case 'End':
newValue = max;

if (isRange) {
Expand All @@ -192,7 +192,7 @@ export function useSliderThumb(parameters: UseSliderThumbParameters) {
: max;
}
break;
case 'End':
case 'Home':
newValue = min;

if (isRange) {
Expand Down

0 comments on commit 919d9ca

Please sign in to comment.