Skip to content

Commit

Permalink
improvement: scrollable modal
Browse files Browse the repository at this point in the history
We currently only allow a sticky footer, but the Bootstrap modal also
has the ability to make the content scrollable.

Added scrollable to modal
  • Loading branch information
Gido Manders committed Sep 22, 2023
1 parent fc745cd commit a228663
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports[`Component: ConfirmModal ui custom texts 1`] = `
tabindex="-1"
>
<div
class="sticky-modal"
class=""
>
<div
aria-modal="true"
Expand All @@ -16,7 +16,7 @@ exports[`Component: ConfirmModal ui custom texts 1`] = `
tabindex="-1"
>
<div
class="modal-dialog"
class="modal-dialog modal-dialog-scrollable"
role="document"
>
<div
Expand Down Expand Up @@ -105,7 +105,7 @@ exports[`Component: ConfirmModal ui default texts 1`] = `
tabindex="-1"
>
<div
class="sticky-modal"
class=""
>
<div
aria-modal="true"
Expand All @@ -115,7 +115,7 @@ exports[`Component: ConfirmModal ui default texts 1`] = `
tabindex="-1"
>
<div
class="modal-dialog"
class="modal-dialog modal-dialog-scrollable"
role="document"
>
<div
Expand Down
18 changes: 0 additions & 18 deletions src/core/Modal/Modal.scss

This file was deleted.

22 changes: 15 additions & 7 deletions src/core/Modal/Modal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Component: Modal', () => {
function setup({
hasHeader = true,
hasFooter = true,
stickyFooter = undefined
stickyFooter
}: {
hasHeader?: boolean;
hasFooter?: boolean;
Expand All @@ -28,15 +28,13 @@ describe('Component: Modal', () => {
const children = (
<RadioGroup<string>
onChange={jest.fn()}
options={[ 'local', 'development', 'test', 'acceptation', 'production' ]}
options={['local', 'development', 'test', 'acceptation', 'production']}
labelForOption={(v) => v}
label="Environment"
/>
);

const { container } = render(
<Modal {...props}>{children}</Modal>
);
const { container } = render(<Modal {...props}>{children}</Modal>);

return { container, onCloseSpy };
}
Expand All @@ -62,10 +60,20 @@ describe('Component: Modal', () => {
expect(document.body.lastChild).toMatchSnapshot();
});

test('sans sticky footer', () => {
test('sticky footer', () => {
setup({ stickyFooter: true });

expect(
document.body.lastChild?.firstChild?.firstChild?.firstChild
).toHaveClass('modal-dialog-scrollable');
});

test('scrollable', () => {
setup({ stickyFooter: false });

expect(document.body.lastChild?.firstChild).not.toHaveClass('sticky-modal');
expect(
document.body.lastChild?.firstChild?.firstChild?.firstChild
).not.toHaveClass('modal-dialog-scrollable');
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/core/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ export function Modal(props: Props) {

return (
<ReactstrapModal
wrapClassName={stickyFooter ? 'sticky-modal' : undefined}
isOpen={true}
toggle={onClose}
size={size}
className={className}
scrollable={stickyFooter}
>
{header ? (
<ModalHeader toggle={onClose} className={modalHeaderClassName}>
Expand Down
12 changes: 6 additions & 6 deletions src/core/Modal/__snapshots__/Modal.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports[`Component: Modal ui with header and footer 1`] = `
tabindex="-1"
>
<div
class="sticky-modal"
class=""
>
<div
aria-modal="true"
Expand All @@ -16,7 +16,7 @@ exports[`Component: Modal ui with header and footer 1`] = `
tabindex="-1"
>
<div
class="modal-dialog"
class="modal-dialog modal-dialog-scrollable"
role="document"
>
<div
Expand Down Expand Up @@ -143,7 +143,7 @@ exports[`Component: Modal ui without footer 1`] = `
tabindex="-1"
>
<div
class="sticky-modal"
class=""
>
<div
aria-modal="true"
Expand All @@ -153,7 +153,7 @@ exports[`Component: Modal ui without footer 1`] = `
tabindex="-1"
>
<div
class="modal-dialog"
class="modal-dialog modal-dialog-scrollable"
role="document"
>
<div
Expand Down Expand Up @@ -275,7 +275,7 @@ exports[`Component: Modal ui without header 1`] = `
tabindex="-1"
>
<div
class="sticky-modal"
class=""
>
<div
aria-modal="true"
Expand All @@ -285,7 +285,7 @@ exports[`Component: Modal ui without header 1`] = `
tabindex="-1"
>
<div
class="modal-dialog"
class="modal-dialog modal-dialog-scrollable"
role="document"
>
<div
Expand Down
13 changes: 10 additions & 3 deletions src/core/OpenCloseModal/OpenCloseModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,18 @@ describe('Component: OpenCloseModal', () => {
expect(document.body.lastChild).toMatchSnapshot();
});

test('sticky footer', () => {
setup({ isOpen: true, stickyFooter: true });
expect(
document.body.lastChild?.firstChild?.firstChild?.firstChild
).toHaveClass('modal-dialog-scrollable');
});

test('sans sticky footer', () => {
setup({ isOpen: true, stickyFooter: false });
expect(document.body.lastChild?.firstChild).not.toHaveClass(
'sticky-modal'
);
expect(
document.body.lastChild?.firstChild?.firstChild?.firstChild
).not.toHaveClass('modal-dialog-scrollable');
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/core/OpenCloseModal/OpenCloseModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export function OpenCloseModal(props: Props) {
className={className}
isOpen={true}
size={size}
wrapClassName={stickyFooter ? 'sticky-modal' : undefined}
scrollable={stickyFooter}
>
{onSave ? (
<form onSubmit={onSave}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports[`Component: OpenCloseModal ui in progress 1`] = `
tabindex="-1"
>
<div
class="sticky-modal"
class=""
>
<div
aria-modal="true"
Expand All @@ -16,7 +16,7 @@ exports[`Component: OpenCloseModal ui in progress 1`] = `
tabindex="-1"
>
<div
class="modal-dialog"
class="modal-dialog modal-dialog-scrollable"
role="document"
>
<div
Expand Down Expand Up @@ -195,7 +195,7 @@ exports[`Component: OpenCloseModal ui open 1`] = `
tabindex="-1"
>
<div
class="sticky-modal"
class=""
>
<div
aria-modal="true"
Expand All @@ -205,7 +205,7 @@ exports[`Component: OpenCloseModal ui open 1`] = `
tabindex="-1"
>
<div
class="modal-dialog"
class="modal-dialog modal-dialog-scrollable"
role="document"
>
<div
Expand Down
1 change: 0 additions & 1 deletion src/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
@import './core/Spinner/Spinner';
@import './core/Tag/Tag';
@import './core/Popover/Popover';
@import './core/Modal/Modal';
@import './core/Toggle/Toggle';
@import './core/OpenClose/OpenClose';
@import './core/SearchInput/SearchInput';
Expand Down

0 comments on commit a228663

Please sign in to comment.