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 Home / End regression #526

Merged
merged 7 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading