Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion packages/material-ui/src/Slider/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function focusThumb({ sliderRef, activeIndex, setActive }) {
!sliderRef.current.contains(document.activeElement) ||
Number(document.activeElement.getAttribute('data-index')) !== activeIndex
) {
sliderRef.current.querySelector(`[data-index="${activeIndex}"]`).focus();
sliderRef.current.querySelector(`[role="slider"][data-index="${activeIndex}"]`).focus();
}

if (setActive) {
Expand Down
22 changes: 22 additions & 0 deletions packages/material-ui/src/Slider/Slider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,28 @@ describe('<Slider />', () => {
expect(thumb2.getAttribute('aria-valuenow')).to.equal('29');
});

it('should support keyboard with marks variant', () => {
const { getAllByRole } = render(
<Slider defaultValue={30} step={10} marks min={10} max={110} />,
);
const [thumb] = getAllByRole('slider');

thumb.focus();
fireEvent.keyDown(document.activeElement, {
key: 'ArrowRight',
});
expect(thumb.getAttribute('aria-valuenow')).to.equal('40');

thumb.focus();
fireEvent.keyDown(document.activeElement, {
key: 'ArrowLeft',
});
fireEvent.keyDown(document.activeElement, {
key: 'ArrowLeft',
});
expect(thumb.getAttribute('aria-valuenow')).to.equal('20');
});

it('should support mouse events', () => {
const handleChange = spy();
const { container } = render(<Slider defaultValue={[20, 30]} onChange={handleChange} />);
Expand Down