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] abstractButton: remove reliance on getDerivedStateFromProps #4310

Merged
merged 1 commit into from
Sep 3, 2020
Merged
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
18 changes: 2 additions & 16 deletions packages/core/src/components/button/abstractButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,30 +101,16 @@ export abstract class AbstractButton<H extends React.HTMLAttributes<HTMLElement>

private currentKeyDown: number = null;

// A disabled element cannot be active, but there are cases where
// this situation can happen (NumericInput buttons), hence the need
// to check if disabled prop has been passed and change isActive
// accordingly
public static getDerivedStateFromProps(props: IButtonProps, state: IButtonState) {
if (state.isActive && props.disabled) {
return {
isActive: false,
};
}

return null;
}

public abstract render(): JSX.Element;

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

const className = classNames(
Classes.BUTTON,
{
[Classes.ACTIVE]: this.state.isActive || this.props.active,
[Classes.ACTIVE]: !disabled && (active || this.state.isActive),
[Classes.DISABLED]: disabled,
[Classes.FILL]: fill,
[Classes.LARGE]: large,
Expand Down