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

fix(slider): prevent keyboard events when disabled #583

Merged
merged 1 commit into from Jun 12, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/slider/__tests__/slider.test.tsx
Expand Up @@ -110,6 +110,25 @@ describe("<Slider />", () => {
fireEvent.keyDown(handle, { key: "PageDown", code: 34 });
expect(getCurrentValue(handle)).toEqual(min + tenSteps);
});

it("does not move when disabled", () => {
const { getByRole } = render(
<SliderInput aria-label="mover" disabled>
<SliderTrack>
<SliderTrackHighlight />
<SliderHandle />
</SliderTrack>
</SliderInput>
);
const handle = getByRole("slider");

fireEvent.click(handle);

fireEvent.keyDown(handle, { key: "ArrowRight", code: 39 });
fireEvent.keyDown(handle, { key: "ArrowRight", code: 39 });

expect(getCurrentValue(handle)).toEqual(0);
});
});
});

Expand Down
4 changes: 4 additions & 0 deletions packages/slider/src/index.tsx
Expand Up @@ -392,6 +392,10 @@ const SliderInput = forwardRefWithAs<

// https://www.w3.org/TR/wai-aria-practices-1.2/#slider_kbd_interaction
let handleKeyDown = useEventCallback((event: React.KeyboardEvent) => {
if (disabled) {
return;
}

let newValue: number;
let tenSteps = (max - min) / 10;
let keyStep = step || (max - min) / 100;
Expand Down