Skip to content

Commit

Permalink
feat(Modal): add scrollable prop (#1435)
Browse files Browse the repository at this point in the history
This PR adds a `scrollable` prop to `Modal` which applies the `modal-dialog-scrollable` class which was added in Bootstrap 4.3.0. [Here](https://getbootstrap.com/docs/4.3/components/modal/#scrolling-long-content) is the relevant section of the Bootstrap documentation for reference.
  • Loading branch information
tcbegley authored and TheSharpieOne committed Mar 8, 2019
1 parent 1e2dc5b commit 9f7dd45
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
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

0 comments on commit 9f7dd45

Please sign in to comment.