Skip to content

Get rid of CommonJS module #299

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

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/components/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ReactDOM from 'react-dom';
import ExecutionEnvironment from 'exenv';
import elementClass from 'element-class';
import ModalPortal from './ModalPortal';
import ariaAppHider from '../helpers/ariaAppHider';
import * as ariaAppHider from '../helpers/ariaAppHider';

const renderSubtreeIntoContainer = ReactDOM.unstable_renderSubtreeIntoContainer;

Expand Down
28 changes: 11 additions & 17 deletions lib/helpers/ariaAppHider.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
let globalElement = typeof document !== 'undefined' ? document.body : null;

function setElement (element) {
function validateElement (appElement) {
if (!appElement && !globalElement) {
throw new Error('react-modal: You must set an element with `Modal.setAppElement(el)` to make this accessible');
}
}

export function setElement (element) {
let newElement = element;
if (typeof newElement === 'string') {
const el = document.querySelectorAll(element);
Expand All @@ -10,34 +16,22 @@ function setElement (element) {
return globalElement;
}

function validateElement (appElement) {
if (!appElement && !globalElement) {
throw new Error('react-modal: You must set an element with `Modal.setAppElement(el)` to make this accessible');
}
}

function hide (appElement) {
export function hide (appElement) {
validateElement(appElement);
(appElement || globalElement).setAttribute('aria-hidden', 'true');
}

function show (appElement) {
export function show (appElement) {
validateElement(appElement);
(appElement || globalElement).removeAttribute('aria-hidden');
}

function toggle (shouldHide, appElement) {
export function toggle (shouldHide, appElement) {
if (shouldHide) {
hide(appElement);
} else { show(appElement); }
}

function resetForTesting () {
export function resetForTesting () {
globalElement = document.body;
}

exports.toggle = toggle;
exports.setElement = setElement;
exports.show = show;
exports.hide = hide;
exports.resetForTesting = resetForTesting;
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
module.exports = require('./components/Modal');
import Modal from './components/Modal';

export default Modal;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better(?) to use export-default-from, but this is stage-1.
What do you think?

export-default-from

export default from './components/Modal';

2 changes: 1 addition & 1 deletion specs/Modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import sinon from 'sinon';
import expect from 'expect';
import ReactDOM from 'react-dom';
import Modal from '../lib/components/Modal';
import ariaAppHider from '../lib/helpers/ariaAppHider';
import * as ariaAppHider from '../lib/helpers/ariaAppHider';
import { renderModal, unmountModal } from './helper';

const Simulate = TestUtils.Simulate;
Expand Down