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] fix: restore button loading prop precedence #5445

Merged
merged 3 commits into from
Jul 19, 2022
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
19 changes: 15 additions & 4 deletions packages/core/src/components/button/abstractButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ export interface IButtonProps<E extends HTMLButtonElement | HTMLAnchorElement =
large?: boolean;

/**
* If set to `true`, the button will display a centered loading spinner instead of its contents, and the button will be disabled.
* The width of the button is not affected by the value of this prop.
* If set to `true`, the button will display a centered loading spinner instead of its contents
* and the button will be disabled (_even if_ `disabled={false}`). The width of the button is
* not affected by the value of this prop.
*
* @default false
*/
Expand Down Expand Up @@ -120,8 +121,18 @@ export abstract class AbstractButton<E extends HTMLButtonElement | HTMLAnchorEle
public abstract render(): JSX.Element;

protected getCommonButtonProps() {
const { active, alignText, fill, large, loading = false, outlined, minimal, small, tabIndex } = this.props;
const disabled = this.props.disabled ?? loading;
const {
active = false,
alignText,
fill,
large,
loading = false,
outlined,
minimal,
small,
tabIndex,
} = this.props;
const disabled = this.props.disabled || loading;

const className = classNames(
Classes.BUTTON,
Expand Down
8 changes: 8 additions & 0 deletions packages/core/test/buttons/buttonTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ function buttonTestSuite(component: React.ComponentClass<any>, tagName: string)
assert.isTrue(wrapper.hasClass(Classes.DISABLED));
});

// This tests some subtle (potentialy unexpected) behavior, but it was an API decision we
// made a long time ago which we rely on and should not break.
// See https://github.com/palantir/blueprint/issues/3819#issuecomment-1189478596
it("button is disabled when the loading prop is true, even if disabled={false}", () => {
const wrapper = button({ disabled: false, loading: true });
assert.isTrue(wrapper.hasClass(Classes.DISABLED));
});

it("clicking button triggers onClick prop", () => {
const onClick = spy();
button({ onClick }).simulate("click");
Expand Down