Skip to content
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

feat(Modal): add scrollable prop #1435

Merged
merged 1 commit into from Mar 8, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/lib/Components/ModalsPage.js
Expand Up @@ -69,6 +69,8 @@ const ModalsPage = () => {
PropTypes.bool,
PropTypes.oneOf(['static'])
]),
// if body of modal should be scrollable when content is long
scrollable: PropTypes.bool,
// allows for a node/component to exist next to the modal (outside of it). Useful for external close buttons
// external: PropTypes.node,
// called on componentDidMount
Expand Down
3 changes: 3 additions & 0 deletions src/Modal.js
Expand Up @@ -21,6 +21,7 @@ const propTypes = {
isOpen: PropTypes.bool,
autoFocus: PropTypes.bool,
centered: PropTypes.bool,
scrollable: PropTypes.bool,
size: PropTypes.string,
toggle: PropTypes.func,
keyboard: PropTypes.bool,
Expand Down Expand Up @@ -64,6 +65,7 @@ const defaultProps = {
isOpen: false,
autoFocus: true,
centered: false,
scrollable: false,
role: 'dialog',
backdrop: true,
keyboard: true,
Expand Down Expand Up @@ -318,6 +320,7 @@ class Modal extends React.Component {
className={mapToCssModules(classNames(dialogBaseClass, this.props.className, {
[`modal-${this.props.size}`]: this.props.size,
[`${dialogBaseClass}-centered`]: this.props.centered,
[`${dialogBaseClass}-scrollable`]: this.props.scrollable,
}), this.props.cssModule)}
role="document"
ref={(c) => {
Expand Down
13 changes: 13 additions & 0 deletions src/__tests__/Modal.spec.js
Expand Up @@ -106,6 +106,19 @@ describe('Modal', () => {
wrapper.unmount();
});

it('should render with the class "modal-dialog-scrollable" when scrollable is "true"', () => {
isOpen = true;
const wrapper = mount(
<Modal isOpen={isOpen} toggle={toggle} scrollable={true}>
Yo!
</Modal>
);

jest.runTimersToTime(300);
expect(document.getElementsByClassName('modal-dialog-scrollable').length).toBe(1);
wrapper.unmount();
});

it('should render with class "modal-dialog" and have custom class name if provided', () => {
isOpen = true;
const wrapper = mount(
Expand Down