Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions packages/react-core/src/components/Wizard/WizardFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { css } from '@patternfly/react-styles';
import styles from '@patternfly/react-styles/css/components/Wizard/wizard';

import { Button, ButtonVariant } from '../Button';
import { isCustomWizardFooter, WizardStepType } from './types';
import { isCustomWizardFooter, WizardFooterButtonProps, WizardStepType } from './types';

/**
* Hosts the standard structure of a footer with ties to the active step so that text for buttons can vary from step to step.
Expand Down Expand Up @@ -33,6 +33,12 @@ export interface WizardFooterProps {
isBackHidden?: boolean;
/** Flag to hide the cancel button */
isCancelHidden?: boolean;
/** Additional props for the Next button. */
nextButtonProps?: Omit<WizardFooterButtonProps, 'isDisabled' | 'type'>;
/** Additional props for the Back button. */
backButtonProps?: Omit<WizardFooterButtonProps, 'isDisabled'>;
/** Additional props for the Cancel button. */
cancelButtonProps?: WizardFooterButtonProps;
}

/**
Expand Down Expand Up @@ -62,22 +68,31 @@ const InternalWizardFooter = ({
isCancelHidden,
nextButtonText = 'Next',
backButtonText = 'Back',
cancelButtonText = 'Cancel'
cancelButtonText = 'Cancel',
nextButtonProps,
backButtonProps,
cancelButtonProps
}: Omit<WizardFooterProps, 'activeStep'>) => (
<WizardFooterWrapper>
{!isBackHidden && (
<Button variant={ButtonVariant.secondary} onClick={onBack} isDisabled={isBackDisabled}>
<Button variant={ButtonVariant.secondary} onClick={onBack} isDisabled={isBackDisabled} {...backButtonProps}>
{backButtonText}
</Button>
)}

<Button variant={ButtonVariant.primary} type="submit" onClick={onNext} isDisabled={isNextDisabled}>
<Button
variant={ButtonVariant.primary}
type="submit"
onClick={onNext}
isDisabled={isNextDisabled}
{...nextButtonProps}
>
{nextButtonText}
</Button>

{!isCancelHidden && (
<div className={styles.wizardFooterCancel}>
<Button variant={ButtonVariant.link} onClick={onClose}>
<Button variant={ButtonVariant.link} onClick={onClose} {...cancelButtonProps}>
{cancelButtonText}
</Button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,27 @@ test('renders default footer with custom props', () => {
expect(screen.getByRole('button', { name: 'Leave now!' })).toBeVisible();
});

test('can add props to default footer buttons', () => {
render(
<Wizard
footer={{
nextButtonProps: { id: 'next-button', className: 'custom-class' },
backButtonProps: { id: 'back-button' },
cancelButtonProps: { id: 'cancel-button' }
}}
>
<WizardStep id="test-step" name="Test step" />
</Wizard>
);

const nextButton = screen.getByRole('button', { name: 'Next' });

expect(nextButton).toHaveProperty('id', 'next-button');
expect(nextButton).toHaveClass('custom-class');
expect(screen.getByRole('button', { name: 'Back' })).toHaveProperty('id', 'back-button');
expect(screen.getByRole('button', { name: 'Cancel' })).toHaveProperty('id', 'cancel-button');
});

test('renders custom footer', () => {
render(
<Wizard footer={<>Some footer</>}>
Expand Down
4 changes: 4 additions & 0 deletions packages/react-core/src/components/Wizard/types.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { WizardNavProps, WizardNavItemProps, WizardFooterProps } from '.';
import { ButtonProps } from '../Button';

/** Type used to define 'basic' steps, or in other words, steps that are neither parents or children of parents. */
export interface WizardBasicStep {
Expand Down Expand Up @@ -30,6 +31,9 @@ export enum WizardNavItemStatus {
Error = 'error'
}

/** Type for customizing a button (next, back or cancel) in a Wizard footer. It omits some props which either have a default value or are passed directly via WizardFooterProps. */
export type WizardFooterButtonProps = Omit<ButtonProps, 'children' | 'variant' | 'onClick'>;

/** Type used to define parent steps. */
export interface WizardParentStep extends WizardBasicStep {
/** Nested step IDs */
Expand Down