Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] feat(MultistepDialog): tooltips on navigation buttons #5534

Merged
merged 10 commits into from
Sep 14, 2022
Merged
Changes from 5 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
3 changes: 3 additions & 0 deletions packages/core/src/components/button/abstractButton.tsx
Original file line number Diff line number Diff line change
@@ -85,6 +85,9 @@ export interface IButtonProps<E extends HTMLButtonElement | HTMLAnchorElement =
/** Whether this button should use small styles. */
small?: boolean;

/** Tooltip content to display when the button is disabled */
tooltipContent?: string;

/**
* HTML `type` attribute of button. Accepted values are `"button"`, `"submit"`, and `"reset"`.
* Note that this prop has no effect on `AnchorButton`; it only affects `Button`.
2 changes: 1 addition & 1 deletion packages/core/src/components/dialog/dialogStep.tsx
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ import { DISPLAYNAME_PREFIX, HTMLDivProps, Props } from "../../common/props";
import { ButtonProps } from "../button/buttons";

export type DialogStepId = string | number;
export type DialogStepButtonProps = Partial<Pick<ButtonProps, "disabled" | "text">>;
export type DialogStepButtonProps = Partial<Pick<ButtonProps, "disabled" | "text" | "tooltipContent">>;

// eslint-disable-next-line deprecation/deprecation
export type DialogStepProps = IDialogStepProps;
60 changes: 47 additions & 13 deletions packages/core/src/components/dialog/multistepDialog.tsx
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
import classNames from "classnames";
import * as React from "react";

import { Tooltip2 } from "../../../../popover2/src/tooltip2";
import { AbstractPureComponent2, Classes, Position, Utils } from "../../common";
import { DISPLAYNAME_PREFIX } from "../../common/props";
import { Button, ButtonProps } from "../button/buttons";
@@ -233,30 +234,63 @@ export class MultistepDialog extends AbstractPureComponent2<MultistepDialogProps
if (this.state.selectedIndex > 0) {
const backButtonProps = steps[selectedIndex].props.backButtonProps ?? this.props.backButtonProps;

buttons.push(
if (backButtonProps?.tooltipContent) {
buttons.push(
<Tooltip2 content={backButtonProps?.tooltipContent} hoverOpenDelay={100}>
<Button
key="back"
onClick={this.getDialogStepChangeHandler(selectedIndex - 1)}
text="Back"
{...backButtonProps}
/>
</Tooltip2>,
);
} else {
<Button
key="back"
onClick={this.getDialogStepChangeHandler(selectedIndex - 1)}
text="Back"
{...backButtonProps}
/>,
);
/>;
}
}

if (selectedIndex === this.getDialogStepChildren().length - 1) {
buttons.push(<Button intent="primary" key="final" text="Submit" {...this.props.finalButtonProps} />);
if (this.props.finalButtonProps?.tooltipContent) {
buttons.push(
<Tooltip2 content={this.props.finalButtonProps?.tooltipContent} hoverOpenDelay={100}>
<Button intent="primary" key="final" text="Submit" {...this.props.finalButtonProps} />
</Tooltip2>,
);
} else {
buttons.push(<Button intent="primary" key="final" text="Submit" {...this.props.finalButtonProps} />);
}
} else {
const nextButtonProps = steps[selectedIndex].props.nextButtonProps ?? this.props.nextButtonProps;

buttons.push(
<Button
intent="primary"
key="next"
onClick={this.getDialogStepChangeHandler(selectedIndex + 1)}
text="Next"
{...nextButtonProps}
/>,
);
if (nextButtonProps?.tooltipContent) {
buttons.push(
<Tooltip2 content={nextButtonProps?.tooltipContent} hoverOpenDelay={100}>
<Button
intent="primary"
key="next"
onClick={this.getDialogStepChangeHandler(selectedIndex + 1)}
text="Next"
{...nextButtonProps}
/>
</Tooltip2>,
);
} else {
buttons.push(
<Button
intent="primary"
key="next"
onClick={this.getDialogStepChangeHandler(selectedIndex + 1)}
text="Next"
{...nextButtonProps}
/>,
);
}
}

return buttons;
Original file line number Diff line number Diff line change
@@ -115,7 +115,10 @@ export class MultistepDialogExample extends React.PureComponent<
icon="info-sign"
navigationPosition={position}
onClose={this.handleClose}
nextButtonProps={{ disabled: this.state.value === undefined }}
nextButtonProps={{
disabled: this.state.value === undefined,
tooltipContent: this.state.value === undefined ? "Needs an input." : null,
}}
finalButtonProps={finalButtonProps}
title={hasTitle ? "Multistep dialog" : undefined}
{...state}