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

Accessibility: Backport modal autofocus in latest insomnia version #166

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
31 changes: 17 additions & 14 deletions packages/insomnia/src/ui/components/base/modal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import classnames from 'classnames';
import React, { forwardRef, ReactNode, useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react';
import { FocusScope } from 'react-aria';

import { createKeybindingsHandler } from '../keydown-binder';
// Keep global z-index reference so that every modal will
Expand Down Expand Up @@ -93,22 +94,24 @@ export const Modal = forwardRef<ModalHandle, ModalProps>(({
}, [handleKeydown]);

return (open ?
<div
ref={containerRef}
onKeyDown={handleKeydown}
tabIndex={-1}
className={classes}
style={{ zIndex }}
aria-hidden={false}
role="dialog"
>
<div className="modal__backdrop overlay theme--transparent-overlay" data-close-modal />
<div className={classnames('modal__content__wrapper', { 'modal--centered': centered })}>
<div className="modal__content">
{children}
<FocusScope autoFocus>
<div
ref={containerRef}
onKeyDown={handleKeydown}
tabIndex={-1}
className={classes}
style={{ zIndex }}
aria-hidden={false}
role="dialog"
>
<div className="modal__backdrop overlay theme--transparent-overlay" data-close-modal />
<div className={classnames('modal__content__wrapper', { 'modal--centered': centered })}>
<div className="modal__content">
{children}
</div>
</div>
</div>
</div>
</FocusScope>
: null
);
});
Expand Down