Skip to content

Commit

Permalink
Merge pull request #3357 from picklesrus/join-modal-x-button
Browse files Browse the repository at this point in the history
One approach to hiding the close button in the modal.
  • Loading branch information
picklesrus committed Sep 24, 2019
2 parents c609d99 + 1a58095 commit 036937b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 14 deletions.
29 changes: 18 additions & 11 deletions src/components/modal/base/modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,20 @@ class Modal extends React.Component {
}}
{...omit(this.props, ['className', 'overlayClassName'])}
>
<div
className="modal-content-close"
onClick={this.handleRequestClose}
>
<img
alt="close-icon"
className="modal-content-close-img"
draggable="false"
src="/svgs/modal/close-x.svg"
/>
</div>

{this.props.showCloseButton && (
<div
className="modal-content-close"
onClick={this.handleRequestClose}
>
<img
alt="close-icon"
className="modal-content-close-img"
draggable="false"
src="/svgs/modal/close-x.svg"
/>
</div>
)}
{this.props.children}
</ReactModal>
);
Expand All @@ -70,7 +73,11 @@ Modal.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
overlayClassName: PropTypes.string,
showCloseButton: PropTypes.bool,
useStandardSizes: PropTypes.bool
};

Modal.defaultProps = {
showCloseButton: true
};
module.exports = Modal;
4 changes: 3 additions & 1 deletion src/components/modal/join/modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const JoinModal = ({
}) => (
<Modal
isOpen
showCloseButton
useStandardSizes
className="mod-join"
shouldCloseOnOverlayClick={false}
Expand All @@ -26,7 +27,8 @@ const JoinModal = ({

JoinModal.propTypes = {
onCompleteRegistration: PropTypes.func,
onRequestClose: PropTypes.func
onRequestClose: PropTypes.func,
showCloseButton: PropTypes.bool
};

module.exports = JoinModal;
4 changes: 2 additions & 2 deletions src/views/join/join.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ const ErrorBoundary = require('../../components/errorboundary/errorboundary.jsx'
// Require this even though we don't use it because, without it, webpack runs out of memory...
const Page = require('../../components/page/www/page.jsx'); // eslint-disable-line no-unused-vars

const openModal = true;
const Register = () => (
<ErrorBoundary>
<JoinModal
isOpen={openModal}
isOpen
key="scratch3registration"
showCloseButton={false}
/>
</ErrorBoundary>
);
Expand Down
34 changes: 34 additions & 0 deletions test/unit/components/modal.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const React = require('react');
const {shallowWithIntl} = require('../../helpers/intl-helpers.jsx');
const Modal = require('../../../src/components/modal/base/modal.jsx');

describe('Modal', () => {
test('Close button not shown when showCloseButton false', () => {
const showClose = true;
const component = shallowWithIntl(
<Modal
showCloseButton={showClose}
/>
);
expect(component.find('div.modal-content-close').exists()).toBe(true);
expect(component.find('img.modal-content-close-img').exists()).toBe(true);
});
test('Close button shown by default', () => {
const component = shallowWithIntl(
<Modal />
);
expect(component.find('div.modal-content-close').exists()).toBe(true);
expect(component.find('img.modal-content-close-img').exists()).toBe(true);
});

test('Close button shown when showCloseButton true', () => {
const showClose = false;
const component = shallowWithIntl(
<Modal
showCloseButton={showClose}
/>
);
expect(component.find('div.modal-content-close').exists()).toBe(false);
expect(component.find('img.modal-content-close-img').exists()).toBe(false);
});
});

0 comments on commit 036937b

Please sign in to comment.