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(InputNumber): make plus/minus buttons un-focusable #2398

Merged
merged 1 commit into from
Mar 18, 2022
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
2 changes: 2 additions & 0 deletions src/InputNumber/InputNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ const InputNumber = React.forwardRef((props: InputNumberProps, ref) => {
{input}
<span className={prefix('btn-group-vertical')}>
<Button
tabIndex={-1}
appearance={buttonAppearance}
className={prefix('touchspin-up')}
onClick={handlePlus}
Expand All @@ -308,6 +309,7 @@ const InputNumber = React.forwardRef((props: InputNumberProps, ref) => {
<AngleUpIcon />
</Button>
<Button
tabIndex={-1}
appearance={buttonAppearance}
className={prefix('touchspin-down')}
onClick={handleMinus}
Expand Down
13 changes: 13 additions & 0 deletions src/InputNumber/test/InputNumberSpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import ReactTestUtils, { act } from 'react-dom/test-utils';
import { getDOMNode } from '@test/testUtils';
import { testStandardProps } from '@test/commonCases';
Expand Down Expand Up @@ -191,6 +192,18 @@ describe('InputNumber', () => {
expect(getByRole('spinbutton')).to.exist;
});

it('Should not have focusable elements other than the input', () => {
const { container } = render(<InputNumber value={0} />);

// Move focus to the input
userEvent.tab();

// Move focus out
userEvent.tab();

expect(container).not.to.contain(document.activeElement);
});

describe('Keyboard interaction', () => {
it('Should increase the value when ArrowUp is pressed', () => {
const onChange = sinon.spy();
Expand Down