Skip to content

Commit

Permalink
test(Modal): fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asudoh committed Feb 4, 2020
1 parent 1bbe349 commit b09d3d8
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 135 deletions.
4 changes: 2 additions & 2 deletions packages/react/src/components/ComposedModal/ComposedModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export default class ComposedModal extends Component {
ref={this.startSentinel}
tabIndex="0"
role="link"
class={`${prefix}--visually-hidden`}>
className={`${prefix}--visually-hidden`}>
Focus sentinel
</span>
<div ref={this.innerModal} className={containerClass} tabIndex={-1}>
Expand All @@ -248,7 +248,7 @@ export default class ComposedModal extends Component {
ref={this.endSentinel}
tabIndex="0"
role="link"
class={`${prefix}--visually-hidden`}>
className={`${prefix}--visually-hidden`}>
Focus sentinel
</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,25 @@ exports[`<ComposedModal /> renders 1`] = `
onTransitionEnd={[Function]}
open={true}
role="presentation"
tabIndex={-1}
>
<span
className="bx--visually-hidden"
role="link"
tabIndex="0"
>
Focus sentinel
</span>
<div
className="bx--modal-container"
tabIndex={-1}
/>
<span
className="bx--visually-hidden"
role="link"
tabIndex="0"
>
Focus sentinel
</span>
</div>
</ComposedModal>
`;
2 changes: 1 addition & 1 deletion packages/react/src/components/Modal/Modal-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { settings } from 'carbon-components';
const { prefix } = settings;

// The modal is the 0th child inside the wrapper on account of focus-trap-react
const getModal = wrapper => wrapper.childAt(0);
const getModal = wrapper => wrapper.find('.bx--modal');

describe('Modal', () => {
describe('Renders as expected', () => {
Expand Down
13 changes: 9 additions & 4 deletions packages/react/src/components/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import toggleClass from '../../tools/toggleClass';
import Button from '../Button';
import deprecate from '../../prop-types/deprecate';
import requiredIfGivenPropExists from '../../prop-types/requiredIfGivenPropExists';
import wrapFocus from '../../internal/wrapFocus';
import wrapFocus, {
elementOrParentIsFloatingMenu,
} from '../../internal/wrapFocus';
import setupGetInstanceId from '../../tools/setupGetInstanceId';

const { prefix } = settings;
Expand Down Expand Up @@ -198,7 +200,10 @@ export default class Modal extends Component {
if (
this.innerModal.current &&
!this.innerModal.current.contains(evt.target) &&
!this.elementOrParentIsFloatingMenu(evt.target)
!elementOrParentIsFloatingMenu(
evt.target,
this.props.selectorsFloatingMenus
)
) {
this.props.onRequestClose(evt);
}
Expand Down Expand Up @@ -426,7 +431,7 @@ export default class Modal extends Component {
ref={this.startSentinel}
tabIndex="0"
role="link"
class={`${prefix}--visually-hidden`}>
className={`${prefix}--visually-hidden`}>
Focus sentinel
</span>
{modalBody}
Expand All @@ -435,7 +440,7 @@ export default class Modal extends Component {
ref={this.endSentinel}
tabIndex="0"
role="link"
class={`${prefix}--visually-hidden`}>
className={`${prefix}--visually-hidden`}>
Focus sentinel
</span>
</div>
Expand Down
Loading

0 comments on commit b09d3d8

Please sign in to comment.