Skip to content

[added] Apply custom data- and aria- props to content div #230

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

Closed
wants to merge 1 commit into from
Closed
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
17 changes: 15 additions & 2 deletions lib/components/ModalPortal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var React = require('react');
var HTMLDOMPropertyConfig = require('react/lib/HTMLDOMPropertyConfig');
var div = React.DOM.div;
var focusManager = require('../helpers/focusManager');
var scopeTab = require('../helpers/scopeTab');
Expand All @@ -18,6 +19,18 @@ var CLASS_NAMES = {
}
};

function getCustomProps(props) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe move this function to a helper?

var customProps = {};

Object.keys(props).forEach(function (key) {
if (HTMLDOMPropertyConfig.isCustomAttribute(key)) {
customProps[key] = props[key];
}
});

return customProps;
}

var ModalPortal = module.exports = React.createClass({

displayName: 'ModalPortal',
Expand Down Expand Up @@ -194,7 +207,7 @@ var ModalPortal = module.exports = React.createClass({
onMouseDown: this.handleOverlayMouseDown,
onMouseUp: this.handleOverlayMouseUp
},
div({
div(Assign(getCustomProps(this.props), {
ref: "content",
style: Assign({}, contentStyles, this.props.style.content || {}),
className: this.buildClassName('content', this.props.className),
Expand All @@ -203,7 +216,7 @@ var ModalPortal = module.exports = React.createClass({
onMouseDown: this.handleContentMouseDown,
onMouseUp: this.handleContentMouseUp,
role: "dialog"
},
}),
this.props.children
)
)
Expand Down
12 changes: 12 additions & 0 deletions specs/Modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,18 @@ describe('Modal', function () {
unmountModal();
});

it('supports custom aria-attributes', function () {
var modal = renderModal({isOpen: true, 'aria-foo': 'bar'});
equal(modal.portal.refs.content.getAttribute('aria-foo'), 'bar');
unmountModal();
});

it('supports custom data-attributes', function () {
var modal = renderModal({isOpen: true, 'data-foo': 'bar'});
equal(modal.portal.refs.content.getAttribute('data-foo'), 'bar');
unmountModal();
});

it('overrides the default styles when a custom classname is used', function () {
var modal = renderModal({isOpen: true, className: 'myClass'});
equal(modal.portal.refs.content.style.top, '');
Expand Down