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

fix(TextInput): misaligned label and helper text at different sizes #695

Conversation

aversini
Copy link
Collaborator

@aversini aversini commented Sep 26, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new story for the TextInput component showcasing various sizes: "xs", "sm", "md", "lg", and "xl".
  • Improvements

    • Enhanced label positioning for the TextInput component when focused or not empty.
    • Improved responsiveness of label and helper text based on input size.
  • Bug Fixes

    • Adjusted padding for "xs" and "sm" sizes in the TextInput component tests to ensure consistency.

Copy link

coderabbitai bot commented Sep 26, 2024

Walkthrough

The changes introduce a new story for the TextInput component that showcases various sizes, enhances label and helper text responsiveness based on size, and modifies CSS properties for better alignment. Additionally, adjustments are made to the test suite for padding classes and the utility function for height management, ensuring consistent styling across different input sizes.

Changes

File Change Summary
packages/documentation/src/Form/TextInput.stories.tsx Added a new story AllSizes demonstrating the TextInput component in sizes "xs", "sm", "md", "lg", and "xl" with corresponding defaultValue, helperText, and label.
packages/ui-styles/src/plugins/tailwindcss/components/textInput.ts Modified the CSS transformation for the label on focus or when not empty, changing the vertical translation from -37px to -33px.
packages/ui-textinput/src/components/TextInput/TextInput.tsx Introduced useRef hooks for label and helper text, and added useLayoutEffect to adjust CSS properties based on the size prop for better responsiveness.
packages/ui-textinput/src/components/TextInput/tests/TextInput.test.tsx Updated padding classes for "xs" and "sm" sizes, changing from "px-2" to "px-4" and "px-3" to "px-4" respectively.
packages/ui-textinput/src/components/TextInput/utilities.ts Renamed sizeClass to heightClass in getTextInputClasses, removing padding from height class assignments and applying it directly in the return statement.

Possibly related PRs

  • feat(TextInput): adding size prop #693: The main PR introduces a new story for the TextInput component that demonstrates various sizes, while the related PR adds a size property to the TextInput component, establishing a direct connection in functionality and purpose.

Suggested labels

Enhancement


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 022e062 and da86135.

📒 Files selected for processing (2)
  • packages/ui-styles/src/plugins/tailwindcss/components/textInput.ts (1 hunks)
  • packages/ui-textinput/src/components/TextInput/TextInput.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/ui-styles/src/plugins/tailwindcss/components/textInput.ts
  • packages/ui-textinput/src/components/TextInput/TextInput.tsx

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

@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: 3

🧹 Outside diff range and nitpick comments (3)
packages/ui-styles/src/plugins/tailwindcss/components/textInput.ts (1)

11-11: Approved: Label position adjustment improves alignment

The change from -37px to -33px for the label's vertical translation when focused or not empty is a good adjustment to improve the visual alignment of the text input component. This aligns well with the PR objective of fixing misaligned labels.

Consider adding a comment explaining the purpose of this adjustment, e.g.:

 [`.av-text-input:focus + label[aria-hidden="true"],
   .av-text-input:not(:placeholder-shown) + label[aria-hidden="true"]`]: {
+  /* Adjust label position for better alignment when input is focused or not empty */
   transform: "translate(12px, var(--av-text-input-label, -33px)) scale(0.75)",
 },

This will help future developers understand the reasoning behind this specific value.

packages/documentation/src/Form/TextInput.stories.tsx (1)

69-93: Great addition of the AllSizes story!

This new story effectively demonstrates the TextInput component in various sizes, which aligns well with the PR objective of addressing misaligned label and helper text at different sizes. The consistent use of helperText and label across all sizes provides a good basis for comparison.

Consider improving responsiveness

While the current implementation works, the use of fixed-height divs (h-28) for each input might limit responsiveness. Consider using a more flexible layout approach that adapts to the content size.

You could replace the fixed height with a flexible padding or margin:

-			<div className="h-28">
+			<div className="py-4">

This change would allow the container to adapt to the content size while still providing visual separation between inputs.

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

74-129: Consider handling size-based styles with CSS classes

Directly manipulating styles in JavaScript can affect maintainability and performance. Consider moving size-dependent styles to CSS classes or styled-components to leverage CSS capabilities.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 397d22f and 306791c.

📒 Files selected for processing (5)
  • packages/documentation/src/Form/TextInput.stories.tsx (1 hunks)
  • packages/ui-styles/src/plugins/tailwindcss/components/textInput.ts (1 hunks)
  • packages/ui-textinput/src/components/TextInput/TextInput.tsx (5 hunks)
  • packages/ui-textinput/src/components/TextInput/tests/TextInput.test.tsx (1 hunks)
  • packages/ui-textinput/src/components/TextInput/utilities.ts (2 hunks)
🔇 Additional comments (5)
packages/ui-textinput/src/components/TextInput/utilities.ts (1)

Line range hint 167-193: Improved separation of concerns for height and padding

The renaming of sizeClass to heightClass and the separation of height and padding concerns are good improvements. This change enhances code readability and allows for more flexible styling options.

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

3-3: Added necessary React hooks

The imports of useLayoutEffect and useRef are correctly added to support the new functionality.


43-45: Initialize refs for label and helper text elements

Creating labelRef and helperTextRef using useRef is appropriate for accessing DOM elements.


155-158: Attach labelRef to the visible label element

Adding ref={labelRef} to the label element is necessary for the useLayoutEffect to adjust its styles.


166-169: Attach helperTextRef to the helper text element

Adding ref={helperTextRef} to the helper text div allows for dynamic adjustment of its styles based on size.

Copy link

Bundle Size (components)

Status File Size (Gzip) Limits
style.css 7.34 KB 8 KB
index.js 10.88 KB (-13 B -0.12%) 12 KB
vendor.js 66.06 KB 67 KB

Overall bundle size: 84.28 KB (-13 B -0.02%)
Overall status: ✅

Bundle Size (fingerprint)

Status File Size (Gzip) Limits
index.js 3.94 KB (-1 B -0.02%) 4 KB
vendor.js 44.34 KB 45 KB

Overall bundle size: 48.28 KB (-1 B 0.00%)
Overall status: ✅

Bundle Size (form components)

Status File Size (Gzip) Limits
index.js 5.65 KB (+216 B +3.88%) 20 KB
vendor.js 44.46 KB 67 KB

Overall bundle size: 50.11 KB (+216 B +0.42%)
Overall status: ✅

Bundle Size (system)

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

Overall bundle size: 50.35 KB
Overall status: ✅

@aversini aversini merged commit 9ff6fa1 into main Sep 26, 2024
6 checks passed
@aversini aversini deleted the fix(TextInput)-misaligned-label-and-helper-text-at-different-sizes branch September 26, 2024 21:18
@aversini aversini mentioned this pull request Sep 26, 2024
aversini added a commit that referenced this pull request Sep 27, 2024
🚀 Automated Release
---


<details><summary>ui-anchor: 1.1.5</summary>

##
[1.1.5](ui-anchor-v1.1.4...ui-anchor-v1.1.5)
(2024-09-26)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @versini/ui-button bumped to 1.1.5
  * devDependencies
    * @versini/ui-styles bumped to 1.10.2
</details>

<details><summary>ui-bubble: 1.0.5</summary>

##
[1.0.5](ui-bubble-v1.0.4...ui-bubble-v1.0.5)
(2024-09-26)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @versini/ui-button bumped to 1.1.5
    * @versini/ui-icons bumped to 1.12.6
    * @versini/ui-private bumped to 1.4.14
  * devDependencies
    * @versini/ui-styles bumped to 1.10.2
</details>

<details><summary>ui-button: 1.1.5</summary>

##
[1.1.5](ui-button-v1.1.4...ui-button-v1.1.5)
(2024-09-26)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @versini/ui-private bumped to 1.4.14
  * devDependencies
    * @versini/ui-icons bumped to 1.12.6
    * @versini/ui-styles bumped to 1.10.2
</details>

<details><summary>ui-card: 1.0.5</summary>

##
[1.0.5](ui-card-v1.0.4...ui-card-v1.0.5)
(2024-09-26)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @versini/ui-private bumped to 1.4.14
  * devDependencies
    * @versini/ui-styles bumped to 1.10.2
</details>

<details><summary>ui-components: 5.31.6</summary>

##
[5.31.6](ui-components-v5.31.5...ui-components-v5.31.6)
(2024-09-26)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @versini/ui-anchor bumped to 1.1.5
    * @versini/ui-button bumped to 1.1.5
    * @versini/ui-bubble bumped to 1.0.5
    * @versini/ui-card bumped to 1.0.5
    * @versini/ui-footer bumped to 1.0.5
    * @versini/ui-header bumped to 1.0.5
    * @versini/ui-icons bumped to 1.12.6
    * @versini/ui-main bumped to 1.0.5
    * @versini/ui-menu bumped to 1.0.5
    * @versini/ui-panel bumped to 1.0.5
    * @versini/ui-pill bumped to 1.0.5
    * @versini/ui-private bumped to 1.4.14
    * @versini/ui-spinner bumped to 1.0.5
    * @versini/ui-table bumped to 1.0.5
  * devDependencies
    * @versini/ui-styles bumped to 1.10.2
</details>

<details><summary>ui-footer: 1.0.5</summary>

##
[1.0.5](ui-footer-v1.0.4...ui-footer-v1.0.5)
(2024-09-26)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @versini/ui-private bumped to 1.4.14
  * devDependencies
    * @versini/ui-styles bumped to 1.10.2
</details>

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

##
[1.6.5](ui-form-v1.6.4...ui-form-v1.6.5)
(2024-09-26)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @versini/ui-textarea bumped to 1.0.4
    * @versini/ui-textinput bumped to 1.1.0
    * @versini/ui-toggle bumped to 1.0.4
    * @versini/ui-private bumped to 1.4.14
  * devDependencies
    * @versini/ui-button bumped to 1.1.5
    * @versini/ui-icons bumped to 1.12.6
    * @versini/ui-styles bumped to 1.10.2
</details>

<details><summary>ui-header: 1.0.5</summary>

##
[1.0.5](ui-header-v1.0.4...ui-header-v1.0.5)
(2024-09-26)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @versini/ui-private bumped to 1.4.14
  * devDependencies
    * @versini/ui-styles bumped to 1.10.2
</details>

<details><summary>ui-icons: 1.12.6</summary>

##
[1.12.6](ui-icons-v1.12.5...ui-icons-v1.12.6)
(2024-09-26)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @versini/ui-private bumped to 1.4.14
  * devDependencies
    * @versini/ui-private bumped to 1.4.14
</details>

<details><summary>ui-main: 1.0.5</summary>

##
[1.0.5](ui-main-v1.0.4...ui-main-v1.0.5)
(2024-09-26)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @versini/ui-private bumped to 1.4.14
  * devDependencies
    * @versini/ui-styles bumped to 1.10.2
</details>

<details><summary>ui-menu: 1.0.5</summary>

##
[1.0.5](ui-menu-v1.0.4...ui-menu-v1.0.5)
(2024-09-26)


### Dependencies

* The following workspace dependencies were updated
  * devDependencies
    * @versini/ui-button bumped to 1.1.5
    * @versini/ui-icons bumped to 1.12.6
    * @versini/ui-styles bumped to 1.10.2
</details>

<details><summary>ui-panel: 1.0.5</summary>

##
[1.0.5](ui-panel-v1.0.4...ui-panel-v1.0.5)
(2024-09-26)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @versini/ui-button bumped to 1.1.5
    * @versini/ui-icons bumped to 1.12.6
    * @versini/ui-private bumped to 1.4.14
  * devDependencies
    * @versini/ui-styles bumped to 1.10.2
</details>

<details><summary>ui-pill: 1.0.5</summary>

##
[1.0.5](ui-pill-v1.0.4...ui-pill-v1.0.5)
(2024-09-26)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @versini/ui-private bumped to 1.4.14
  * devDependencies
    * @versini/ui-styles bumped to 1.10.2
</details>

<details><summary>ui-private: 1.4.14</summary>

##
[1.4.14](ui-private-v1.4.13...ui-private-v1.4.14)
(2024-09-26)


### Dependencies

* The following workspace dependencies were updated
  * devDependencies
    * @versini/ui-styles bumped to 1.10.2
</details>

<details><summary>ui-spinner: 1.0.5</summary>

##
[1.0.5](ui-spinner-v1.0.4...ui-spinner-v1.0.5)
(2024-09-26)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @versini/ui-private bumped to 1.4.14
  * devDependencies
    * @versini/ui-styles bumped to 1.10.2
</details>

<details><summary>ui-styles: 1.10.2</summary>

##
[1.10.2](ui-styles-v1.10.1...ui-styles-v1.10.2)
(2024-09-26)


### Bug Fixes

* **TextInput:** misaligned label and helper text at different sizes
([#695](#695))
([9ff6fa1](9ff6fa1))
</details>

<details><summary>ui-system: 1.4.15</summary>

##
[1.4.15](ui-system-v1.4.14...ui-system-v1.4.15)
(2024-09-26)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @versini/ui-private bumped to 1.4.14
  * devDependencies
    * @versini/ui-button bumped to 1.1.5
    * @versini/ui-styles bumped to 1.10.2
</details>

<details><summary>ui-table: 1.0.5</summary>

##
[1.0.5](ui-table-v1.0.4...ui-table-v1.0.5)
(2024-09-26)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @versini/ui-button bumped to 1.1.5
    * @versini/ui-icons bumped to 1.12.6
    * @versini/ui-private bumped to 1.4.14
  * devDependencies
    * @versini/ui-styles bumped to 1.10.2
</details>

<details><summary>ui-textarea: 1.0.4</summary>

##
[1.0.4](ui-textarea-v1.0.3...ui-textarea-v1.0.4)
(2024-09-26)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @versini/ui-private bumped to 1.4.14
  * devDependencies
    * @versini/ui-styles bumped to 1.10.2
</details>

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

##
[1.1.0](ui-textinput-v1.0.3...ui-textinput-v1.1.0)
(2024-09-26)


### Features

* **TextInput:** adding size prop
([#693](#693))
([397d22f](397d22f))


### Bug Fixes

* **TextInput:** misaligned label and helper text at different sizes
([#695](#695))
([9ff6fa1](9ff6fa1))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @versini/ui-private bumped to 1.4.14
  * devDependencies
    * @versini/ui-button bumped to 1.1.5
    * @versini/ui-icons bumped to 1.12.6
    * @versini/ui-styles bumped to 1.10.2
</details>

<details><summary>ui-toggle: 1.0.4</summary>

##
[1.0.4](ui-toggle-v1.0.3...ui-toggle-v1.0.4)
(2024-09-26)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @versini/ui-private bumped to 1.4.14
  * devDependencies
    * @versini/ui-styles bumped to 1.10.2
</details>

<details><summary>ui-truncate: 1.0.2</summary>

##
[1.0.2](ui-truncate-v1.0.1...ui-truncate-v1.0.2)
(2024-09-26)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @versini/ui-button bumped to 1.1.5
  * devDependencies
    * @versini/ui-styles bumped to 1.10.2
</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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant