@@ -7,6 +7,7 @@ import './wizard-styles.scss';
77import get from 'lodash/get' ;
88import set from 'lodash/set' ;
99import flattenDeep from 'lodash/flattenDeep' ;
10+ import { selectNext } from './step-buttons' ;
1011
1112const DYNAMIC_WIZARD_TYPES = [ 'function' , 'object' ] ;
1213
@@ -246,6 +247,29 @@ class Wizard extends React.Component {
246247 < div className = { `pf-c-wizard ${ inModal ? '' : 'no-shadow' } ${ isCompactNav ? 'pf-m-compact-nav' : '' } ${ setFullWidth ? 'pf-m-full-width' : '' } ${ setFullHeight ? 'pf-m-full-height' : '' } ` }
247248 role = "dialog"
248249 aria-modal = { inModal ? 'true' : undefined }
250+ onKeyDown = { e => {
251+ if ( e . key === 'Enter' ) {
252+ const isNotButton = e . target . type !== 'button' ;
253+
254+ if ( isNotButton ) {
255+ e . preventDefault ( ) ;
256+
257+ const schemaNextStep = this . findCurrentStep ( this . state . activeStep ) . nextStep ;
258+ const hasCustomButtons = this . findCurrentStep ( this . state . activeStep ) . buttons ;
259+
260+ let nextStep ;
261+ if ( schemaNextStep ) {
262+ nextStep = selectNext ( schemaNextStep , formOptions . getState ) ;
263+ }
264+
265+ if ( formOptions . valid && nextStep && ! hasCustomButtons ) {
266+ this . handleNext ( nextStep , formOptions . getRegisteredFields ) ;
267+ } else if ( formOptions . valid && ! schemaNextStep && ! hasCustomButtons ) {
268+ handleSubmit ( ) ;
269+ }
270+ }
271+ }
272+ } }
249273 >
250274 { title && < WizardHeader
251275 title = { title }
@@ -284,6 +308,7 @@ Wizard.propTypes = {
284308 onSubmit : PropTypes . func . isRequired ,
285309 onCancel : PropTypes . func ,
286310 getRegisteredFields : PropTypes . func . isRequired ,
311+ valid : PropTypes . bool . isRequired ,
287312 } ) ,
288313 fields : PropTypes . arrayOf ( PropTypes . shape ( {
289314 stepKey : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . number ] ) . isRequired ,
0 commit comments