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(input): adding outside-top prop #4775

Open
wants to merge 3 commits into
base: canary
Choose a base branch
from

Conversation

abhinav700
Copy link
Contributor

@abhinav700 abhinav700 commented Feb 1, 2025

This PR is duplicate of #3660
PR #4761 is closed because the old branch is deleted

📝 Description

⛳️ Current behavior (updates)

In old behaviour, the label was presented inside the input component if placholder === "" even if labelPlacement === "outside"

🚀 New behavior

Adding outside-top prop which dispalys the label outside the input component regardless of whether the placeholder is there or not.

💣 Is this a breaking change (Yes/No):

📝 Additional Information

image

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new outside-top label placement option for Input components.
    • Enhanced flexibility in label positioning for Input components.
  • Documentation

    • Updated Input component documentation to clarify behavior of the new label placement options.
    • Added detailed explanations regarding label positioning configurations.
  • Improvements

    • Expanded label placement options to provide more layout versatility.
    • Refined rendering logic of the Input component for an improved user experience.

Copy link

changeset-bot bot commented Feb 1, 2025

⚠️ No Changeset found

Latest commit: 190341c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Feb 1, 2025

@abhinav700 is attempting to deploy a commit to the HeroUI Inc Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Feb 1, 2025

Walkthrough

The pull request introduces a new label placement option "outside-top" for the Input component across multiple files. This enhancement expands the existing label positioning capabilities, allowing developers to place labels above input fields. The changes are implemented consistently across documentation, component implementation, stories, and theme configuration, ensuring a comprehensive and cohesive update to the Input component's functionality.

Changes

File Change Summary
apps/docs/content/components/input/label-placements.raw.jsx Added "outside-top" to placement options
apps/docs/content/docs/components/input.mdx Updated documentation with new label placement details and behavior clarifications
packages/components/input/src/input.tsx Introduced isOutsideTop property and updated rendering logic for label visibility
packages/components/input/src/use-input.ts Modified label placement logic to support "outside-top" configuration
packages/components/input/stories/input.stories.tsx Added "outside-top" to Storybook configuration and example template
packages/core/theme/src/components/input.ts Created new theme variant for "outside-top" label placement
packages/core/system/src/hooks/use-label-placement.ts Updated method signature to include "outside-top" in labelPlacement options

Sequence Diagram

sequenceDiagram
    participant Developer
    participant Input Component
    participant Theme Configuration
    
    Developer->>Input Component: Set labelPlacement="outside-top"
    Input Component->>Theme Configuration: Request styling
    Theme Configuration-->>Input Component: Return layout configuration
    Input Component->>Developer: Render input with top-placed label
Loading

The sequence diagram illustrates how the new "outside-top" label placement is processed, from developer configuration through theme styling to final rendering.

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@abhinav700
Copy link
Contributor Author

@wingkwong I have created a new branch and added the changes there

Copy link
Contributor

@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

🧹 Nitpick comments (1)
apps/docs/content/docs/components/input.mdx (1)

84-87: Consider rephrasing the notes to improve readability.

The notes provide valuable clarification about label placement behavior, but they could be more concise and avoid repetition.

Consider this revision:

-> **Note**: If the `labelPlacement` is `outside`, `label` is outside only when a placeholder is provided. 
-
-> **Note**: If the `labelPlacement` is `outside-top` or `outside-left`, `label` is outside even if a placeholder is not provided.
+> **Note**: Label placement behavior varies:
+> - With `outside`: Label appears outside only when a placeholder is provided.
+> - With `outside-top` or `outside-left`: Label always appears outside, regardless of placeholder.
🧰 Tools
🪛 LanguageTool

[style] ~86-~86: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...y when a placeholder is provided. > Note: If the labelPlacement is `outside-...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 92281a6 and 6b6ae46.

📒 Files selected for processing (6)
  • apps/docs/content/components/input/label-placements.raw.jsx (1 hunks)
  • apps/docs/content/docs/components/input.mdx (1 hunks)
  • packages/components/input/src/input.tsx (3 hunks)
  • packages/components/input/src/use-input.ts (2 hunks)
  • packages/components/input/stories/input.stories.tsx (3 hunks)
  • packages/core/theme/src/components/input.ts (1 hunks)
🧰 Additional context used
🪛 LanguageTool
apps/docs/content/docs/components/input.mdx

[style] ~86-~86: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...y when a placeholder is provided. > Note: If the labelPlacement is `outside-...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: TypeScript
  • GitHub Check: Build
🔇 Additional comments (6)
apps/docs/content/components/input/label-placements.raw.jsx (1)

4-4: LGTM!

The addition of "outside-top" to the placements array is consistent with the new feature.

packages/components/input/src/input.tsx (1)

20-20: LGTM!

The implementation correctly handles the new "outside-top" label placement by:

  1. Adding the isOutsideTop prop
  2. Updating the label rendering conditions to consider the new placement

Also applies to: 86-86, 119-119

packages/components/input/src/use-input.ts (1)

242-244: LGTM!

The implementation correctly:

  1. Adds variables to track label placement
  2. Updates the logic to handle the new "outside-top" placement
  3. Maintains clear documentation of the behavior

Also applies to: 245-250, 260-261

packages/components/input/stories/input.stories.tsx (1)

53-53: LGTM!

The changes correctly:

  1. Add the new placement option to the Storybook configuration
  2. Include comprehensive examples demonstrating the feature with and without placeholders

Also applies to: 178-182, 187-206

packages/core/theme/src/components/input.ts (1)

181-186: LGTM! Clean implementation of the "outside-top" label placement.

The implementation follows the established pattern and uses appropriate Tailwind classes for layout and spacing.

apps/docs/content/docs/components/input.mdx (1)

78-78: LGTM! Clear documentation of the new option.

The documentation accurately includes the new "outside-top" option in the list of available label placements.

Copy link
Member

@wingkwong wingkwong left a comment

Choose a reason for hiding this comment

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

build & typecheck failed. please check.

@abhinav700
Copy link
Contributor Author

build & typecheck failed. please check.

Searched, but everything seams fine.
labelPlacement is correctly having the type outside || outside-top || outside-left || inside || undefined.

I think this was a common problem in my previous PR also where I would see this error locally but not while making a PR.

Copy link
Member

@wingkwong wingkwong left a comment

Choose a reason for hiding this comment

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

@abhinav700 your local branch is outdated. I just push the latest canary branch to your branch. Just FYI, we did some refactoring on label placement recently. Please also update this file and revise your current change if necessary. Thanks.

https://github.com/heroui-inc/heroui/blob/canary/packages/core/system/src/hooks/use-label-placement.ts

Copy link
Contributor

@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

🧹 Nitpick comments (1)
apps/docs/content/docs/components/input.mdx (1)

86-86: Style Improvement Suggestion for outside-top/outside-left Note
This note states that when labelPlacement is outside-top or outside-left, the label will be displayed outside regardless of a placeholder. However, three successive sentences in this section begin similarly. Consider rephrasing this note to vary the sentence structure and enhance readability.

🧰 Tools
🪛 LanguageTool

[style] ~86-~86: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...y when a placeholder is provided. > Note: If the labelPlacement is `outside-...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b6ae46 and e91d0e3.

📒 Files selected for processing (3)
  • apps/docs/content/docs/components/input.mdx (1 hunks)
  • packages/components/input/src/use-input.ts (2 hunks)
  • packages/core/theme/src/components/input.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/core/theme/src/components/input.ts
  • packages/components/input/src/use-input.ts
🧰 Additional context used
🪛 LanguageTool
apps/docs/content/docs/components/input.mdx

[style] ~86-~86: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...y when a placeholder is provided. > Note: If the labelPlacement is `outside-...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: TypeScript
  • GitHub Check: Build
🔇 Additional comments (2)
apps/docs/content/docs/components/input.mdx (2)

78-78: New outside-top Option Introduced
The updated text now includes the outside-top option along with the existing options. This aligns well with the new feature behavior.


84-84: Clarification on outside Label Behavior
This note clarifies that when labelPlacement is set to outside, the label will only be rendered outside if a placeholder is provided. Ensure that the implementation reflects this conditional logic.

Copy link
Contributor

@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

🧹 Nitpick comments (1)
packages/core/system/src/hooks/use-label-placement.ts (1)

12-20: Consider documenting the label placement behavior.

The logic handles the new "outside-top" option correctly. Consider adding JSDoc comments to document the behavior of each placement option for better maintainability.

Add documentation above the function:

+/**
+ * Hook to manage label placement with support for inside, outside, outside-left, and outside-top positions.
+ * Falls back to "outside" when label is not provided with "inside" placement.
+ * @param props.labelPlacement - Desired label placement
+ * @param props.label - Label content
+ * @returns The resolved label placement
+ */
 export function useLabelPlacement(props: {
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e91d0e3 and 190341c.

📒 Files selected for processing (1)
  • packages/core/system/src/hooks/use-label-placement.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: TypeScript
  • GitHub Check: Build
🔇 Additional comments (1)
packages/core/system/src/hooks/use-label-placement.ts (1)

6-6: LGTM! Verify integration with dependent components.

The addition of "outside-top" to the label placement options is a clean, non-breaking change.

Let's verify the integration with dependent components:

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Search for components using labelPlacement
ast-grep --pattern 'labelPlacement={$_}'

Length of output: 42


🏁 Script executed:

#!/bin/bash
# Let's search for the new "outside-top" option and also check for hook usage throughout the codebase.
echo "Searching for 'outside-top' usage (string literal)..."
rg "\"outside-top\"" .

echo "Searching for 'useLabelPlacement' hook usage..."
rg "useLabelPlacement" .

Length of output: 2470


Integration Verified – "outside-top" Option Properly Propagated

We've confirmed through codebase analysis that the new "outside-top" option is integrated across multiple dependent components (e.g., Input, DateInput, DatePicker, Select) and is properly handled in both hook usage and stories. No issues were found with the hook's implementation or its integration.

@abhinav700
Copy link
Contributor Author

@wingkwong looks like adding outside top to this causes problems in other packages like date-input
should I make changes to the files of these components?

Copy link
Member

@wingkwong wingkwong left a comment

Choose a reason for hiding this comment

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

please add changeset

@@ -3,7 +3,7 @@ import {useMemo} from "react";
import {useProviderContext} from "../provider-context";

export function useLabelPlacement(props: {
labelPlacement?: "inside" | "outside" | "outside-left";
labelPlacement?: "inside" | "outside" | "outside-left" | "outside-top";
Copy link
Member

Choose a reason for hiding this comment

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

seems this will break other components. probably use the old way in use-input with some comments, i.e. not using useLabelPlacement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants