Skip to content

Commit cde6595

Browse files
committed
feat(Modal): add description example to integration and cypress
1 parent fb7c01c commit cde6595

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

packages/patternfly-4/react-integration/cypress/integration/modal.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,25 @@ describe('Modal Test', () => {
2424
});
2525
});
2626

27+
it('Verify Description Modal', () => {
28+
cy.get('#showDescriptionModalButton').then((modalButton: JQuery<HTMLButtonElement>) => {
29+
cy.wrap(modalButton).click();
30+
cy.get('.pf-c-modal-box')
31+
.then(() => {
32+
cy.get('.pf-c-modal-box .pf-c-button[aria-label="Close"]').then(closeButton => {
33+
cy.wrap(closeButton).click();
34+
cy.get('.pf-c-modal-box').should('not.exist');
35+
});
36+
})
37+
.then(() => {
38+
cy.wrap(modalButton).click();
39+
cy.get('.pf-c-modal-box').should('exist');
40+
cy.get('body').trigger('keydown', { keyCode: 27, which: 27 });
41+
cy.get('.pf-c-modal-box').should('not.exist');
42+
});
43+
});
44+
});
45+
2746
it('Verify Small Modal', () => {
2847
cy.get('#showSmallModalButton').then((modalButton: JQuery<HTMLButtonElement>) => {
2948
cy.wrap(modalButton).click();

packages/patternfly-4/react-integration/demo-app-ts/src/components/demos/ModalDemo/ModalDemo.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import WarningTriangleIcon from '@patternfly/react-icons/dist/js/icons/warning-t
44

55
interface ModalDemoState {
66
isModalOpen: boolean;
7+
isModalDescriptionOpen: boolean;
78
isSmallModalOpen: boolean;
89
isLargeModalOpen: boolean;
910
isHalfWidthModalOpen: boolean;
@@ -14,6 +15,7 @@ interface ModalDemoState {
1415
export class ModalDemo extends React.Component<React.HTMLProps<HTMLDivElement>, ModalDemoState> {
1516
state = {
1617
isModalOpen: false,
18+
isModalDescriptionOpen: false,
1719
isSmallModalOpen: false,
1820
isLargeModalOpen: false,
1921
isHalfWidthModalOpen: false,
@@ -27,6 +29,12 @@ export class ModalDemo extends React.Component<React.HTMLProps<HTMLDivElement>,
2729
}));
2830
};
2931

32+
handleModalDescriptionToggle = () => {
33+
this.setState(({ isModalDescriptionOpen }) => ({
34+
isModalDescriptionOpen: !isModalDescriptionOpen
35+
}));
36+
};
37+
3038
handleSmallModalToggle = () => {
3139
this.setState(({ isSmallModalOpen }) => ({
3240
isSmallModalOpen: !isSmallModalOpen
@@ -88,6 +96,35 @@ export class ModalDemo extends React.Component<React.HTMLProps<HTMLDivElement>,
8896
);
8997
}
9098

99+
renderModalWithDescription() {
100+
const { isModalDescriptionOpen } = this.state;
101+
102+
return (
103+
<Modal
104+
title="Modal Header"
105+
isOpen={isModalDescriptionOpen}
106+
onClose={this.handleModalDescriptionToggle}
107+
description="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
108+
magna aliqua."
109+
actions={[
110+
<Button key="cancel" variant="secondary" onClick={this.handleModalDescriptionToggle}>
111+
Cancel
112+
</Button>,
113+
<Button key="confirm" variant="primary" onClick={this.handleModalDescriptionToggle}>
114+
Confirm
115+
</Button>
116+
]}
117+
isFooterLeftAligned
118+
>
119+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
120+
magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
121+
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
122+
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
123+
laborum.
124+
</Modal>
125+
);
126+
}
127+
91128
renderSmallModal() {
92129
const { isSmallModalOpen } = this.state;
93130

@@ -283,13 +320,22 @@ export class ModalDemo extends React.Component<React.HTMLProps<HTMLDivElement>,
283320
>
284321
Show No Header Modal
285322
</Button>
323+
<Button
324+
style={buttonStyle}
325+
variant="primary"
326+
onClick={this.handleModalDescriptionToggle}
327+
id="showDescriptionModalButton"
328+
>
329+
Show Modal with Description
330+
</Button>
286331
</div>
287332
{this.renderModal()}
288333
{this.renderSmallModal()}
289334
{this.renderLargeModal()}
290335
{this.renderHalfWidthModal()}
291336
{this.renderCustomHeaderFooterModal()}
292337
{this.renderNoHeaderModal()}
338+
{this.renderModalWithDescription()}
293339
</React.Fragment>
294340
);
295341
}

0 commit comments

Comments
 (0)