Skip to content

Commit

Permalink
[Modal, Frame(Nav), Sheet] Trapped virtual cursor inside dialogs (#3931)
Browse files Browse the repository at this point in the history
* Trapped virtual cursor inside dialogs

* changelog

* Add nav container label

* Only applt attributes on small screens
  • Loading branch information
AndrewMusgrave authored and sylvhama committed Mar 26, 2021
1 parent c4060aa commit 957b22d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 0 deletions.
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

- Added an example for the `onRemove` prop to `Tag` and clarified that no remove button is rendered when `onClick` is set ([#2987](https://github.com/Shopify/polaris-react/pull/2987))
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

0 comments on commit 957b22d

Please sign in to comment.