Skip to content

Commit

Permalink
fix:icon align when datatype is of image (#35992)
Browse files Browse the repository at this point in the history
### Description


### [Bug Link](#35549)

I have raised this PR In-order to fix `alignment` of the `icon` in
`input component` when `datatype` is selected as `number` and position
is selected as `right`

### screenshot
### Before issue is resolved , icon dissapears

![image](https://github.com/user-attachments/assets/7d7f2865-5c88-458b-bf8f-cc4097f493ac)

### After the issue is resolved

![image](https://github.com/user-attachments/assets/9c4f1a65-e2c2-4725-bb94-723c512df70d)

### Cypress Testing 

![image](https://github.com/user-attachments/assets/597cd565-4269-463f-bbf2-ba0c078add3c)

### unit Testcases

![image](https://github.com/user-attachments/assets/71c75575-0c1d-40a4-a2f3-7b2f129a1097)

### Cypress Testing video

https://github.com/user-attachments/assets/3898144e-e84e-48b8-9ff1-9f449007cf41




<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced a customizable `rightElement` prop in the
`BaseInputComponent`, allowing users to display an icon on the right
side of the input field based on specified properties.
  
- **Tests**
- Added a new test suite for the `BaseInputComponent` to validate the
rendering and behavior of the component, including checks for icon
visibility and alignment.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
saiprabhu-dandanayak authored Sep 26, 2024
1 parent 347dba5 commit c2fcd51
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
53 changes: 53 additions & 0 deletions app/client/src/widgets/BaseInputWidget/component/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from "react";
import { render } from "@testing-library/react";
import "@testing-library/jest-dom/extend-expect";
import BaseInputComponent, { type BaseInputComponentProps } from "./index";
import { ThemeProvider } from "styled-components";
import { lightTheme } from "selectors/themeSelectors";

const renderBaseInputComponent = (
props: Partial<BaseInputComponentProps> = {},
) => {
const defaultProps: BaseInputComponentProps = {
value: "",
inputType: "TEXT",
inputHTMLType: "TEXT",
disabled: false,
isLoading: false,
compactMode: false,
isInvalid: false,
label: "Salary",
showError: false,
onValueChange: jest.fn(),
onFocusChange: jest.fn(),
widgetId: "test-widget",
rtl: true,
};

return render(
<ThemeProvider theme={lightTheme}>
<BaseInputComponent {...defaultProps} {...props} />
</ThemeProvider>,
);
};

describe("BaseInputComponent TestCases", () => {
test("1. Icon should be visible and aligned to the right when the input type is a number", () => {
const { container } = renderBaseInputComponent({
inputType: "NUMBER",
inputHTMLType: "NUMBER",
value: "123",
onStep: jest.fn(),
rtl: false,
shouldUseLocale: true,
iconName: "add",
iconAlign: "right",
});

const numericInputIcon = container.getElementsByClassName(
"bp3-icon bp3-icon-add",
)[0];

expect(numericInputIcon).toBeInTheDocument();
});
});
1 change: 1 addition & 0 deletions app/client/src/widgets/BaseInputWidget/component/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ class BaseInputComponent extends React.Component<
onKeyUp={this.onKeyUp}
onValueChange={this.onNumberChange}
placeholder={this.props.placeholder}
rightElement={this.getRightIcon()}
stepSize={this.props.stepSize}
value={this.props.value}
{...conditionalProps}
Expand Down

0 comments on commit c2fcd51

Please sign in to comment.