Skip to content
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
23 changes: 23 additions & 0 deletions packages/mui-material/src/Slider/Slider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,29 @@ describe.skipIf(!supportsTouch())('<Slider />', () => {
});

describe('when `step` is `null` and values are restricted by `marks`', () => {
it.each([
['Home', 60, 20],
['End', 40, 80],
])('key: %s selects its boundary mark', async (key, defaultValue, expectedValue) => {
const { user } = render(
<ThemeProvider theme={createTheme({ direction })}>
<Slider
orientation={orientation}
min={10}
max={90}
step={null}
marks={[{ value: 20 }, { value: 40 }, { value: 60 }, { value: 80 }]}
defaultValue={defaultValue}
/>
</ThemeProvider>,
);

const slider = screen.getByRole('slider');
await user.tab();
await user.keyboard(`{${key}}`);
expect(slider).to.have.attribute('aria-valuenow', String(expectedValue));
});

decrementKeys.forEach((key) => {
it(`key: ${key} decrements the value`, () => {
render(
Expand Down
4 changes: 2 additions & 2 deletions packages/mui-material/src/Slider/useSlider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,13 @@ export function useSlider(parameters: UseSliderParameters): UseSliderReturnValue
const incrementKeys = [isRtl ? 'ArrowLeft' : 'ArrowRight', 'ArrowUp', 'PageUp', 'End'];

if (decrementKeys.includes(event.key)) {
if (currentMarkIndex === 0) {
if (event.key === 'Home' || currentMarkIndex === 0) {
newValue = marksValues[0];
} else {
newValue = marksValues[currentMarkIndex - 1];
}
} else if (incrementKeys.includes(event.key)) {
if (currentMarkIndex === marksValues.length - 1) {
if (event.key === 'End' || currentMarkIndex === marksValues.length - 1) {
newValue = maxMarksValue;
} else {
newValue = marksValues[currentMarkIndex + 1];
Expand Down
Loading