Skip to content

Commit 52a2a6a

Browse files
committed
fix(pf4): show dropdown when on mobile
1 parent 7ee42c4 commit 52a2a6a

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import './wizard/wizard-styles.scss';
1111

1212
import WizardNavigation from './wizard/wizard-nav';
1313
import reducer from './wizard/reducer';
14+
import WizardToggle from './wizard/wizard-toggle';
1415

1516
const Modal = ({ children, container, inModal }) =>
1617
inModal
@@ -55,7 +56,7 @@ const WizardInternal = ({
5556
maxStepIndex,
5657
isDynamic
5758
} = useContext(WizardContext);
58-
const [state, dispatch] = useReducer(reducer, { loading: true, container });
59+
const [state, dispatch] = useReducer(reducer, { loading: true, container, openNav: false });
5960

6061
useEffect(() => {
6162
if (inModal) {
@@ -102,17 +103,27 @@ const WizardInternal = ({
102103
closeButtonAriaLabel={closeButtonAriaLabel}
103104
/>
104105
)}
106+
<WizardToggle
107+
activeStepIndex={activeStepIndex + 1}
108+
activeStepName={currentStep.title}
109+
activeStepSubName={navSchema.find((step) => step.name === currentStep.name)?.substepOfTitle}
110+
isOpen={state.openNav}
111+
dispatch={dispatch}
112+
/>
105113
<div className="pf-c-wizard__outer-wrap">
106114
<div className="pf-c-wizard__inner-wrap">
107-
<WizardNav aria-label={navAriaLabel}>
115+
<WizardNav aria-label={navAriaLabel} isOpen={state.openNav}>
108116
<FormSpy subscription={{ values: true, valid: true, validating: true }}>
109117
{({ values, valid, validating }) => (
110118
<WizardNavigation
111119
navSchema={navSchema}
112120
activeStepIndex={activeStepIndex}
113121
valid={valid}
114122
maxStepIndex={maxStepIndex}
115-
jumpToStep={jumpToStep}
123+
jumpToStep={(...args) => {
124+
state.openNav && dispatch({ type: 'closeNav' });
125+
return jumpToStep(...args);
126+
}}
116127
crossroads={crossroads}
117128
isDynamic={isDynamic}
118129
values={values}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
const reducer = (state, { type }) => {
22
switch (type) {
3+
case 'openNav':
4+
return {
5+
...state,
6+
openNav: true
7+
};
8+
case 'closeNav':
9+
return {
10+
...state,
11+
openNav: false
12+
};
313
case 'finishLoading':
414
return {
515
...state,
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { AngleRightIcon, CaretDownIcon } from '@patternfly/react-icons';
4+
5+
const WizardToggle = ({ activeStepIndex, activeStepName, activeStepSubName, isOpen, dispatch }) => (
6+
<button
7+
onClick={() => dispatch({ type: isOpen ? 'closeNav' : 'openNav' })}
8+
className={`pf-c-wizard__toggle ${isOpen ? 'pf-m-expanded' : ''}`}
9+
aria-label="Wizard Toggle"
10+
aria-expanded={isOpen}
11+
type="button"
12+
>
13+
<ol className="pf-c-wizard__toggle-list">
14+
<li className="pf-c-wizard__toggle-list-item">
15+
<span className="pf-c-wizard__toggle-num">{activeStepIndex}</span> {activeStepName}
16+
{activeStepSubName && <AngleRightIcon className="pf-c-wizard__toggle-separator" aria-hidden="true" />}
17+
</li>
18+
{activeStepSubName && <li className="pf-c-wizard__toggle-list-item">{activeStepSubName}</li>}
19+
</ol>
20+
<span className="pf-c-wizard__toggle-icon">
21+
<CaretDownIcon aria-hidden="true" />
22+
</span>
23+
</button>
24+
);
25+
26+
WizardToggle.propTypes = {
27+
activeStepIndex: PropTypes.number,
28+
activeStepName: PropTypes.node,
29+
activeStepSubName: PropTypes.node,
30+
isOpen: PropTypes.bool,
31+
dispatch: PropTypes.func
32+
};
33+
34+
export default WizardToggle;

0 commit comments

Comments
 (0)