Skip to content
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: 2 additions & 0 deletions src/components/Modal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import { BBBModal } from 'bbb-ui-components-react';
| `noFooter` | `boolean` | `false` | Hides the modal footer. |
| `footerContent` | `React.ReactNode` | `null` | Custom content for the footer. |
| `stickyFooter` | `boolean` | `true` | Makes the footer sticky. |
| `testId` | `string` | — | Test identifier applied to the modal element (native `ReactModal` prop). |
| `closeButtonDataTest` | `string` | — | Test identifier applied to the close button. Omitted if empty. |
| `children` | `React.ReactNode` | — | Modal content. |
| `...props` | `ReactModal.Props` | — | Any other props are passed down to the underlying `react-modal` instance. |

Expand Down
8 changes: 8 additions & 0 deletions src/components/Modal/component.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ const meta = {
control: 'boolean',
description: 'When true, the footer is sticky to the bottom.',
},
testId: {
control: 'text',
description: 'Test identifier applied to the modal element (native ReactModal prop).',
},
closeButtonDataTest: {
control: 'text',
description: 'Test identifier applied to the close button. Omitted if empty.',
},
children: {
control: false,
description: 'Modal body content.',
Expand Down
9 changes: 9 additions & 0 deletions src/components/Modal/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@ const Modal: React.FC<ModalProps> = ({
noFooter = false,
footerContent = null,
stickyFooter = true,
testId,
closeButtonDataTest,
children,
...rest
}) => {
let _closeButtonDataTest = closeButtonDataTest;

if (testId && !closeButtonDataTest) {
_closeButtonDataTest = `${testId}-close-button`;
}

const renderFooter = useCallback((isSticky: boolean) => (
<>
Expand All @@ -50,6 +57,7 @@ const Modal: React.FC<ModalProps> = ({
shouldCloseOnOverlayClick={shouldCloseOnOverlayClick}
shouldCloseOnEsc={shouldCloseOnEsc}
appElement={appElement}
testId={testId}
>
<Styled.ModalHeader>
<BBBTypography
Expand All @@ -63,6 +71,7 @@ const Modal: React.FC<ModalProps> = ({
onClick={onRequestClose}
variant="subtle"
ariaLabel="close"
{...(_closeButtonDataTest ? { dataTest: _closeButtonDataTest } : {})}
/>
</Styled.ModalHeader>

Expand Down
2 changes: 2 additions & 0 deletions src/components/Modal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ export interface ModalProps extends Omit<ReactModal.Props, 'style'> {
noFooter?: boolean;
stickyFooter?: boolean;
footerContent?: React.ReactNode;
testId?: string;
closeButtonDataTest?: string;
children: React.ReactNode;
}
Loading