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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Modal, Frame(Nav), Sheet] Trapped virtual cursor inside dialogs #3931

Merged
merged 4 commits into from
Jan 29, 2021
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 UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f

### Bug fixes

- Fixed virtual cursor leaving dialog in `Modal`, `Navigation` and `Sheet` ([#3931](https://github.com/Shopify/polaris-react/pull/3931))

### Documentation

### Development workflow
Expand Down
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
},
"Frame": {
"skipToContent": "Skip to content",
"navigationLabel": "Navigation",
"Navigation": {
"closeMobileNavigationLabel": "Close navigation"
}
Expand Down
9 changes: 9 additions & 0 deletions src/components/Frame/Frame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ class FrameInner extends PureComponent<CombinedProps, State> {
const mobileNavShowing = isNavigationCollapsed && showMobileNavigation;
const tabIndex = mobileNavShowing ? 0 : -1;

const mobileNavAttributes = {
...(mobileNavShowing && {
'aria-modal': true,
role: 'dialog',
}),
};

const navigationMarkup = navigation ? (
<TrapFocus trapping={mobileNavShowing}>
<CSSTransition
Expand All @@ -135,6 +142,8 @@ class FrameInner extends PureComponent<CombinedProps, State> {
classNames={navTransitionClasses}
>
<div
{...mobileNavAttributes}
aria-label={i18n.translate('Polaris.Frame.navigationLabel')}
ref={this.navigationNode}
className={navClassName}
onKeyDown={this.handleNavKeydown}
Expand Down
2 changes: 2 additions & 0 deletions src/components/Frame/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ function FrameExample() {
},
Frame: {
skipToContent: 'Skip to content',
navigationLabel: 'Navigation',
Navigation: {
closeMobileNavigationLabel: 'Close navigation',
},
Expand Down Expand Up @@ -680,6 +681,7 @@ function FrameExample() {
},
Frame: {
skipToContent: 'Skip to content',
navigationLabel: 'Navigation',
Navigation: {
closeMobileNavigationLabel: 'Close navigation',
},
Expand Down
26 changes: 26 additions & 0 deletions src/components/Frame/tests/Frame.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,32 @@ describe('<Frame />', () => {

expect(spy).toHaveBeenCalledTimes(1);
});

it('renders mobile accessibility attributes on small screens', () => {
const navigation = <div />;
const frame = mountWithApp(
<Frame showMobileNavigation navigation={navigation} />,
{mediaQuery: {isNavigationCollapsed: true}},
);

expect(frame).toContainReactComponent('div', {
'aria-modal': true,
role: 'dialog',
});
});

it('does not render mobile accessibility attributes on large screens', () => {
const navigation = <div />;
const frame = mountWithApp(
<Frame showMobileNavigation navigation={navigation} />,
{mediaQuery: {isNavigationCollapsed: false}},
);

expect(frame).not.toContainReactComponent('div', {
'aria-modal': true,
role: 'dialog',
});
});
});

describe('globalRibbon', () => {
Expand Down
1 change: 1 addition & 0 deletions src/components/Modal/components/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export function Dialog({
<TrapFocus>
<div
role="dialog"
aria-modal
aria-labelledby={labelledBy}
tabIndex={-1}
className={styles.Dialog}
Expand Down
1 change: 1 addition & 0 deletions src/components/Sheet/Sheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export function Sheet({
<TrapFocus trapping={open}>
<div
role="dialog"
aria-modal
tabIndex={-1}
className={styles.Sheet}
aria-label={accessibilityLabel}
Expand Down