Skip to content

Commit 4cdc45a

Browse files
authored
Merge pull request #962 from rvsia/usePfModalForWizard
fix(pf4): use pf modal for wizard
2 parents 0ce2640 + c2c7972 commit 4cdc45a

File tree

5 files changed

+1195
-847
lines changed

5 files changed

+1195
-847
lines changed

packages/common/src/wizard/enter-handler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import selectNext from './select-next';
22

33
const enterHandler = (e, formOptions, activeStep, findCurrentStep, handleNext, handleSubmit) => {
4-
if (e.key === 'Enter') {
4+
if (e.key === 'Enter' && !e.shiftKey && !e.ctrlKey) {
55
const isNotButton = e.target.type !== 'button';
66

77
if (isNotButton) {

packages/pf4-component-mapper/src/files/wizard.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import React, { useReducer, useEffect, useContext } from 'react';
2-
import { createPortal } from 'react-dom';
32
import PropTypes from 'prop-types';
43
import { FormSpy, WizardContext } from '@data-driven-forms/react-form-renderer';
54
import Wizard from '@data-driven-forms/common/src/wizard/wizard';
65

7-
import { Bullseye, Backdrop, WizardNav, WizardHeader } from '@patternfly/react-core';
6+
import { WizardNav, WizardHeader, Modal as PF4Modal } from '@patternfly/react-core';
87

98
import WizardStep from './wizard/wizard-step';
109
import './wizard/wizard-styles.scss';
@@ -13,17 +12,20 @@ import WizardNavigation from './wizard/wizard-nav';
1312
import reducer from './wizard/reducer';
1413
import WizardToggle from './wizard/wizard-toggle';
1514

16-
const Modal = ({ children, container, inModal }) =>
17-
inModal
18-
? createPortal(
19-
<Backdrop>
20-
<Bullseye>
21-
<div className="pf-c-modal-box pf-m-lg">{children}</div>
22-
</Bullseye>
23-
</Backdrop>,
24-
container
25-
)
26-
: children;
15+
const Modal = ({ children, container, inModal, ...rest }) =>
16+
inModal ? (
17+
<PF4Modal variant="large" isOpen showClose={false} hasNoBodyWrapper appendTo={container} {...rest}>
18+
{children}
19+
</PF4Modal>
20+
) : (
21+
children
22+
);
23+
24+
Modal.propTypes = {
25+
children: PropTypes.node,
26+
container: PropTypes.instanceOf(Element),
27+
inModal: PropTypes.bool
28+
};
2729

2830
const WizardInternal = ({
2931
inModal,
@@ -85,12 +87,18 @@ const WizardInternal = ({
8587
}
8688

8789
return (
88-
<Modal inModal={inModal} container={state.container}>
90+
<Modal inModal={inModal} container={state.container} aria-labelledby={rest.name}>
8991
<div
9092
className={`pf-c-wizard ${inModal ? '' : 'no-shadow'} ddorg__pf4-component-mapper__wizard ${className ? className : ''}`}
9193
role="dialog"
9294
aria-modal={inModal ? 'true' : undefined}
93-
onKeyDown={onKeyDown}
95+
onKeyDown={(e) => {
96+
onKeyDown(e);
97+
98+
if (e.key === 'Escape' && inModal) {
99+
formOptions.onCancel();
100+
}
101+
}}
94102
{...rest}
95103
>
96104
{title && (

0 commit comments

Comments
 (0)