Skip to content

Commit

Permalink
Merge pull request appsmithorg#13275 from appsmithorg/fix/disable-can…
Browse files Browse the repository at this point in the history
…cel-button-on-a-disabled-select-widget

fix: disable cancel button on a disabled select widget
  • Loading branch information
Tooluloope committed May 11, 2022
2 parents 49a4e47 + 2f8c178 commit 10aca02
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
12 changes: 8 additions & 4 deletions app/client/src/components/ads/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ export const IconWrapper = styled.span<IconProps>`
display: flex;
align-items: center;
cursor: ${(props) =>
props.disabled ? "not-allowed" : props.clickable ? "pointer" : "default"};
svg {
width: ${(props) => sizeHandler(props.size)}px;
height: ${(props) => sizeHandler(props.size)}px;
Expand All @@ -217,7 +218,6 @@ export const IconWrapper = styled.span<IconProps>`
${(props) => (props.invisible ? `visibility: hidden;` : null)};
&:hover {
cursor: ${(props) => (props.clickable ? "pointer" : "default")};
${(props) =>
!props.keepColors
? `
Expand Down Expand Up @@ -400,10 +400,14 @@ export type IconProps = {
keepColors?: boolean;
loaderWithIconWrapper?: boolean;
clickable?: boolean;
disabled?: boolean;
};

const Icon = forwardRef(
(props: IconProps & CommonComponentProps, ref: Ref<HTMLSpanElement>) => {
(
{ onClick, ...props }: IconProps & CommonComponentProps,
ref: Ref<HTMLSpanElement>,
) => {
const iconName = props.name;
const returnIcon =
ICON_LOOKUP[iconName as keyof typeof ICON_LOOKUP] || null;
Expand All @@ -424,9 +428,9 @@ const Icon = forwardRef(
className={`${Classes.ICON} ${props.className}`}
clickable={clickable}
data-cy={props.cypressSelector}
onClick={props.disabled ? noop : onClick}
ref={ref}
{...props}
onClick={props.onClick || noop}
>
{returnIcon}
</IconWrapper>
Expand Down
1 change: 0 additions & 1 deletion app/client/src/pages/Editor/BottomBar/ManualUpgrades.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ function ManualUpgrades() {
>
<Icon
className="t--upgrade"
disabled={applicationVersion < latestVersion}
fillColor={Colors.SCORPION}
name="upgrade"
onClick={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,27 @@ const renderComponent = (props: SelectButtonProps = defaultProps) => {
};

describe("SelectButton", () => {
it("should not clear value when disabled", () => {
const { getByTestId, getByText } = renderComponent({
...defaultProps,
disabled: true,
});
fireEvent.click(getByTestId("selectbutton.btn.cancel"));
expect(defaultProps.handleCancelClick).not.toBeCalled();
expect(getByText("0")).toBeTruthy();
});

it("should render correctly", () => {
const { getByText } = renderComponent();
expect(getByText("0")).toBeTruthy();
});

it("should trigger handleCancelClick method on cancel click", () => {
const { getByTestId } = renderComponent();
fireEvent.click(getByTestId("selectbutton.btn.cancel"));
expect(defaultProps.handleCancelClick).toBeCalled();
});

it("should toggle popover visibility method on button click", () => {
const { getByTestId } = renderComponent();
fireEvent.click(getByTestId("selectbutton.btn.main"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function SelectButton(props: SelectButtonProps) {
<Icon
className="dropdown-icon cancel-icon"
data-testid="selectbutton.btn.cancel"
disabled={disabled}
fillColor={disabled ? Colors.GREY_7 : Colors.GREY_10}
name="cross"
onClick={handleCancelClick}
Expand All @@ -46,6 +47,7 @@ function SelectButton(props: SelectButtonProps) {
) : null}
<Icon
className="dropdown-icon"
disabled={disabled}
fillColor={disabled ? Colors.GREY_7 : Colors.GREY_10}
name="dropdown"
/>
Expand Down

0 comments on commit 10aca02

Please sign in to comment.