<commit_before>import React from 'react';
import Webiny from 'webiny';
import _ from 'lodash';
import Container from './Container';

class Wizard extends Webiny.Ui.Component {
}

Wizard.defaultProps = {
    contentRenderer: undefined,
    actionsRenderer: undefined,
    loaderRenderer: undefined,
    layoutRenderer: undefined,
    initialStep: 0,
    onTransition: _.noop,
    onFinish: _.noop,
    onStart: _.noop,
    form: {},
    renderer() {
        const {Form} = this.props;
        return (
            <Form {...this.props.form}>
                {({form}) => (
                    <Container form={form} {..._.omit(this.props, ['Form', 'form', 'renderer', 'children'])}>
                        {this.props.children}
                    </Container>
                )}
            </Form>
        );
    }
};

export default Webiny.createComponent(Wizard, {modules: ['Form', 'Loader'], api: ['setStep', 'nextStep', 'previousStep']});<commit_msg>Previously, only by clicking on Next users would be able to go to the next step, and by trying to submit a form with keyboard using eg. Cmd+Enter shortcut, an error would occur. This works correctly now.<commit_after>import React from 'react';
import Webiny from 'webiny';
import _ from 'lodash';
import Container from './Container';

class Wizard extends Webiny.Ui.Component {
    constructor() {
        super();
        this.container = null;
    }
}

Wizard.defaultProps = {
    contentRenderer: undefined,
    actionsRenderer: undefined,
    loaderRenderer: undefined,
    layoutRenderer: undefined,
    initialStep: 0,
    onTransition: _.noop,
    onFinish: _.noop,
    onStart: _.noop,
    form: {},
    renderer() {
        const {Form} = this.props;

        return (
            <Form
                {...this.props.form}
                onSubmit={async params => {
                    // This callback won't be implemented by developers probably, because there are other valid Wizard callbacks.
                    const onSubmit = _.get(this.props.form, 'onSubmit');
                    if (_.isFunction(onSubmit)) {
                        await this.props.form.onSubmit(params);
                    }

                    // We want to handle cases where user submits the form with keyboard, onSubmit gets triggered here.
                    const container = this.container.component;
                    if (container.isLastStep()) {
                        return container.finish();
                    }

                    return container.nextStep();
                }}>
                {({form}) => (
                    <Container
                        ref={container => this.container = container}
                        form={form} {..._.omit(this.props, ['Form', 'form', 'renderer', 'children'])}>
                        {this.props.children}
                    </Container>
                )}
            </Form>
        );
    }
};

export default Webiny.createComponent(Wizard, {modules: ['Form', 'Loader'], api: ['setStep', 'nextStep', 'previousStep']});
{'fraction_non_alphanumeric': 0.12208729898260584, 'fraction_numerical': 0.0006563833278634722, 'mean_word_length': 1.8432835820895523, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2469705', 'n_tokens_mistral': 806, 'n_tokens_neox': 765, 'n_words': 222}