Skip to content

Commit

Permalink
fix: prevent focus changed by pressing tab (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
SevenOutman committed Oct 10, 2021
1 parent 0dcf09a commit 742d1bb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/InteractionModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ function InteractionModal({
handleOk();
}
}

// Prevent focus change
if (e.key === 'Tab') {
e.preventDefault();
}
}

if (shouldShowModal) {
Expand All @@ -66,9 +71,8 @@ function InteractionModal({

/**
* using open/show judge by rsuite version
* @example @3 propTypes undefined
* @example @4 no 'open' in propTypes
* @example @4 'open' in propTypes
* @example @5 'open' in propTypes
*/
const modalProps = {
[Modal.propTypes && 'open' in Modal.propTypes
Expand Down
15 changes: 15 additions & 0 deletions src/__tests__/prompt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ it('shows dialog with given message and an text input and two buttons', async ()
).toBeInTheDocument();
});

it('Should lock focus on the text input', () => {
prompt('Message');

const dialog = screen.getByRole('alertdialog');
const textbox = within(dialog).getByRole('textbox');

// Textbox has focus initially
expect(textbox).toHaveFocus();

userEvent.tab();

// Still has focus after user presses Tab
expect(textbox).toHaveFocus();
});

it('renders default value', async () => {
const defaultValue = 'Default value';
prompt('Message', defaultValue);
Expand Down

0 comments on commit 742d1bb

Please sign in to comment.