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

feat(TextInput): adding new prop: rightElementClassName #710

Merged

Conversation

aversini
Copy link
Collaborator

@aversini aversini commented Sep 30, 2024

Summary by CodeRabbit

  • New Features
    • Introduced a new prop, rightElementClassName, for enhanced styling of the right element in the TextInput component.
  • Bug Fixes
    • Adjusted padding logic to accommodate the width of the right element, ensuring proper layout.
  • Tests
    • Added new test cases for rendering with custom classes and updated existing tests for clarity and coverage.

@aversini aversini added the Enhancement New feature or request label Sep 30, 2024
Copy link

coderabbitai bot commented Sep 30, 2024

Walkthrough

The TextInput component has been updated to include a new optional property, rightElementClassName, which allows for additional styling of the right element. This change involves modifications to the TextInputProps interface, the getTextInputClasses function, and the test cases for the component. The input field's padding logic has also been adjusted to account for the width of the right element, ensuring proper layout and styling.

Changes

Files Change Summary
packages/ui-textinput/src/components/TextInput/TextInput.tsx
packages/ui-textinput/src/components/TextInput/TextInputTypes.d.ts
packages/ui-textinput/src/components/TextInput/utilities.ts
Introduced the rightElementClassName prop in TextInputProps, updated getTextInputClasses to include this prop, and modified input padding logic.
packages/ui-textinput/src/components/TextInput/__tests__/TextInput.test.tsx Added new test cases and modified existing ones to verify the rendering and behavior of the TextInput component with the new rightElementClassName prop.

Possibly related PRs


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Bundle Size (components)

Status File Size (Gzip) Limits
style.css 7.34 KB 8 KB
index.js 10.91 KB (+1 B +0.01%) 12 KB
vendor.js 66.14 KB 67 KB

Overall bundle size: 84.39 KB (+1 B 0.00%)
Overall status: ✅

Bundle Size (fingerprint)

Status File Size (Gzip) Limits
index.js 3.94 KB 4 KB
vendor.js 44.34 KB 45 KB

Overall bundle size: 48.28 KB
Overall status: ✅

Bundle Size (form components)

Status File Size (Gzip) Limits
index.js 5.68 KB (+14 B +0.24%) 20 KB
vendor.js 44.46 KB 67 KB

Overall bundle size: 50.14 KB (+14 B +0.03%)
Overall status: ✅

Bundle Size (system)

Status File Size (Gzip) Limits
style.css 2.71 KB 8 KB
index.js 1.93 KB 3 KB
vendor.js 44.46 KB 46 KB

Overall bundle size: 49.11 KB
Overall status: ✅

@aversini aversini merged commit 0374ebe into main Sep 30, 2024
6 checks passed
@aversini aversini deleted the feat(TextInput)-adding-new-prop-rightElementClassName branch September 30, 2024 13:18
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (4)
packages/ui-textinput/src/components/TextInput/TextInputTypes.d.ts (1)

68-71: LGTM with a minor suggestion for the JSDoc comment.

The addition of the rightElementClassName property is well-implemented and provides useful functionality for styling the right element container. The property is correctly typed as an optional string, maintaining backward compatibility.

Consider slightly modifying the JSDoc comment to be more specific:

 /**
- * Extra classes to add to the right element container.
+ * Additional CSS classes to apply to the right element container.
  */

This change makes it clearer that these are CSS classes specifically for the container of the right element.

packages/ui-textinput/src/components/TextInput/TextInput.tsx (1)

Line range hint 1-158: Summary of TextInput component changes

The changes to the TextInput component successfully introduce the new rightElementClassName prop. However, there are a couple of points that require verification:

  1. The implementation of getTextInputClasses should be checked to ensure it correctly handles the new rightElementClassName prop.
  2. The application of rightElementClassName to the right element should be verified, as there are no visible changes in the component's JSX for this.

Overall, the changes align with the PR objectives, but these verifications will ensure the complete and correct implementation of the new feature.

packages/ui-textinput/src/components/TextInput/utilities.ts (1)

220-222: LGTM with a suggestion for improvement

The implementation of rightElementClassName is correct and consistent with the PR objective. However, consider making the positioning more flexible:

Consider separating the positioning class from the rightElement definition to allow more flexibility in positioning the right element. You could add a new prop like rightElementPosition with a default value:

const rightElementPosition = "absolute right-3";
const rightElement = raw
  ? undefined
  : clsx(rightElementPosition, rightElementClassName);

This way, users can override the default positioning if needed.

packages/ui-textinput/src/components/TextInput/__tests__/TextInput.test.tsx (1)

263-275: LGTM: New test case for rightElementClassName

The new test case effectively verifies the functionality of the new rightElementClassName prop, which aligns with the PR objective. It correctly checks for both the custom class and the 'absolute' class on the right element.

A minor suggestion for improvement:

Consider adding an assertion to verify that the input element's padding has been adjusted to account for the right element's width. This would ensure that the layout changes are also being tested. For example:

const input = screen.getByLabelText('toto');
expect(input).toHaveStyle('padding-right: /* expected value */');

Replace /* expected value */ with the actual expected padding value based on your implementation.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d65d57b and 3ecae1f.

📒 Files selected for processing (4)
  • packages/ui-textinput/src/components/TextInput/TextInput.tsx (2 hunks)
  • packages/ui-textinput/src/components/TextInput/TextInputTypes.d.ts (1 hunks)
  • packages/ui-textinput/src/components/TextInput/tests/TextInput.test.tsx (2 hunks)
  • packages/ui-textinput/src/components/TextInput/utilities.ts (3 hunks)
🔇 Additional comments (9)
packages/ui-textinput/src/components/TextInput/TextInputTypes.d.ts (1)

Line range hint 1-71: Verify changes against PR objectives and assess overall impact.

The changes in this file align perfectly with the PR objective of adding a new prop rightElementClassName to the TextInput component. The implementation:

  1. Adds the new optional property to the TextInputProps type.
  2. Provides appropriate JSDoc documentation for the new property.
  3. Maintains backward compatibility by making the property optional.

The addition enhances the component's flexibility for styling the right element container without affecting existing functionality.

To ensure consistency across the codebase, let's verify the usage of this new prop:

This script will help us verify that the new prop is properly implemented in the component, covered in tests, and documented if necessary.

packages/ui-textinput/src/components/TextInput/TextInput.tsx (3)

32-32: LGTM: New prop rightElementClassName added

The addition of the rightElementClassName prop is in line with the PR objective and is correctly placed in the component's prop list.


Line range hint 141-146: Verify application of rightElementClassName

The rightElementClassName prop has been added, but there are no visible changes to the rendering of the right element. Please ensure that the new class is being correctly applied to the right element.

To verify the correct application of rightElementClassName, please check the implementation of getTextInputClasses and confirm that it's correctly incorporating this new prop into the rightElement class. You can use the following script to inspect the relevant code:

#!/bin/bash
# Description: Verify the handling of rightElementClassName in getTextInputClasses

# Test: Search for rightElement class generation in getTextInputClasses
rg --type typescript -A 5 'rightElement.*Class' packages/ui-textinput/src/components/TextInput/utilities.ts

If the rightElementClassName is not being applied, consider updating the component to use it directly:

 {rightElement && (
   <div
     ref={rightElementRef}
-    className={textInputClassName.rightElement}
+    className={`${textInputClassName.rightElement} ${rightElementClassName || ''}`}
   >
     {rightElement}
   </div>
 )}

66-66: LGTM: rightElementClassName added to getTextInputClasses

The rightElementClassName prop is correctly passed to the getTextInputClasses function, which is necessary for incorporating the new styling capability.

To ensure the getTextInputClasses function is correctly implemented to handle this new prop, please run the following script:

packages/ui-textinput/src/components/TextInput/utilities.ts (3)

22-22: LGTM: New property added correctly

The addition of rightElementClassName as an optional string property is consistent with the PR objective and follows the existing pattern for className properties.


158-158: LGTM: Function parameter added correctly

The rightElementClassName parameter has been correctly added to the getTextInputClasses function, maintaining consistency with the type definition and PR objective.


Line range hint 1-233: Summary: Implementation successfully adds new rightElementClassName prop

The changes in this file successfully implement the new rightElementClassName prop for the TextInput component. The implementation is consistent, well-typed, and integrates smoothly with the existing code structure. A minor suggestion was made to improve flexibility in positioning, but overall, the changes meet the PR objective and maintain good code quality.

packages/ui-textinput/src/components/TextInput/__tests__/TextInput.test.tsx (2)

Line range hint 237-262: LGTM: Improved test case naming

The change in the test case name from "should render a text input with an input class" to "should render a text input with a custom input class" improves clarity. It better describes the specific scenario being tested, which is the application of a custom class to the input element.


Line range hint 1-375: Summary: Improved test coverage for TextInput component

The changes in this file effectively address the PR objective of adding support for the new rightElementClassName prop. The additions and modifications to the test cases enhance the overall test coverage of the TextInput component. Specifically:

  1. The renaming of an existing test case improves clarity.
  2. The new test case for rightElementClassName ensures that the new functionality is properly tested.

These changes contribute to maintaining the reliability and robustness of the TextInput component. Good job on keeping the test suite up-to-date with the component's evolving functionality.

@aversini aversini mentioned this pull request Sep 30, 2024
aversini added a commit that referenced this pull request Sep 30, 2024
🚀 Automated Release
---


<details><summary>ui-form: 1.6.12</summary>

##
[1.6.12](ui-form-v1.6.11...ui-form-v1.6.12)
(2024-09-30)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @versini/ui-textinput bumped to 1.2.0
</details>

<details><summary>ui-textinput: 1.2.0</summary>

##
[1.2.0](ui-textinput-v1.1.6...ui-textinput-v1.2.0)
(2024-09-30)


### Features

* **TextInput:** adding new prop: rightElementClassName
([#710](#710))
([0374ebe](0374ebe))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: aversini <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant