Skip to content

Commit

Permalink
Updated to use a more flexible prop
Browse files Browse the repository at this point in the history
  • Loading branch information
Titani committed Jan 5, 2022
1 parent cef68a1 commit c4382cd
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/react-core/src/components/Modal/Modal.tsx
Expand Up @@ -39,8 +39,8 @@ export interface ModalProps extends React.HTMLProps<HTMLDivElement>, OUIAProps {
actions?: any;
/** A callback for when the close button is clicked */
onClose?: () => void;
/** Close button id */
closeButtonId?: string;
/** Additional props added to the close button */
closeButtonProps?: any;
/** Default width of the Modal. */
width?: number | string;
/** The parent container to append the modal to. Defaults to document.body */
Expand Down
Expand Up @@ -7,17 +7,14 @@ export interface ModalBoxCloseButtonProps {
className?: string;
/** A callback for when the close button is clicked */
onClose?: () => void;
/** Close button id */
id?: string;
}

export const ModalBoxCloseButton: React.FunctionComponent<ModalBoxCloseButtonProps> = ({
className = '',
onClose = () => undefined as any,
id,
...props
}: ModalBoxCloseButtonProps) => (
<Button className={className} variant="plain" onClick={onClose} aria-label="Close" id={id} {...props}>
<Button className={className} variant="plain" onClick={onClose} aria-label="Close" {...props}>
<TimesIcon />
</Button>
);
Expand Down
8 changes: 4 additions & 4 deletions packages/react-core/src/components/Modal/ModalContent.tsx
Expand Up @@ -57,8 +57,8 @@ export interface ModalContentProps extends OUIAProps {
actions?: any;
/** A callback for when the close button is clicked */
onClose?: () => void;
/** Close button id */
closeButtonId?: string;
/** Additional props added to the close button */
closeButtonProps?: any;
/** Id of the ModalBox container */
boxId: string;
/** Id of the ModalBox title */
Expand Down Expand Up @@ -88,7 +88,7 @@ export const ModalContent: React.FunctionComponent<ModalContentProps> = ({
footer = null,
actions = [],
onClose = () => undefined as any,
closeButtonId,
closeButtonProps,
variant = 'default',
position,
positionOffset,
Expand Down Expand Up @@ -165,7 +165,7 @@ export const ModalContent: React.FunctionComponent<ModalContentProps> = ({
aria-describedby={ariaDescribedby || (hasNoBodyWrapper ? null : descriptorId)}
{...getOUIAProps(ModalContent.displayName, ouiaId, ouiaSafe)}
>
{showClose && <ModalBoxCloseButton onClose={onClose} id={closeButtonId} />}
{showClose && <ModalBoxCloseButton onClose={onClose} {...closeButtonProps} />}
{modalBoxHeader}
{modalBody}
{modalBoxFooter}
Expand Down
Expand Up @@ -4,7 +4,7 @@ import { ModalBoxCloseButton } from '../ModalBoxCloseButton';

test('ModalBoxCloseButton Test', () => {
const mockfn = jest.fn();
const view = shallow(<ModalBoxCloseButton className="test-box-close-button-class" onClose={mockfn} id="close-button-id"/>);
const view = shallow(<ModalBoxCloseButton className="test-box-close-button-class" onClose={mockfn} closeButtonProps={{ id: 'basic-close-button', 'data-example': 'example-data-attribute' }}/>);
expect(view).toMatchSnapshot();
view
.find('.test-box-close-button-class')
Expand Down
Expand Up @@ -4,7 +4,12 @@ exports[`ModalBoxCloseButton Test 1`] = `
<Button
aria-label="Close"
className="test-box-close-button-class"
id="close-button-id"
closeButtonProps={
Object {
"data-example": "example-data-attribute",
"id": "basic-close-button",
}
}
onClick={[MockFunction]}
variant="plain"
>
Expand Down
2 changes: 1 addition & 1 deletion packages/react-core/src/components/Modal/examples/Modal.md
Expand Up @@ -44,7 +44,7 @@ class SimpleModal extends React.Component {
title="Simple modal header"
isOpen={isModalOpen}
onClose={this.handleModalToggle}
closeButtonId="basic-close-button"
closeButtonProps={{ id: 'basic-close-button', 'data-example': 'example-data-attribute' }}
actions={[
<Button key="confirm" variant="primary" onClick={this.handleModalToggle}>
Confirm
Expand Down

0 comments on commit c4382cd

Please sign in to comment.