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(theme): support description with a single space using zero-width … #4215

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

Conversation

iqingting
Copy link

@iqingting iqingting commented Dec 3, 2024

πŸ“ Description

Support description=" " to maintain a consistent layout when some form controls have descriptions and others do not.

⛳️ Current behavior (updates)

CleanShot 2024-12-03 at 17 20 55@2x

πŸš€ New behavior

CleanShot 2024-12-03 at 17 19 51@2x

πŸ’£ Is this a breaking change (Yes/No): No

πŸ“ Additional Information

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced new story templates for components like Input, Textarea, and DatePicker, enhancing their presentation with descriptions.
    • Added type safety for the InputOtp component, improving prop validation.
  • Improvements

    • Streamlined the rendering of descriptions in various components to handle empty or whitespace-only cases more gracefully.
    • Enhanced layout and styling for WithDescription exports across multiple components for better visual representation.
  • Bug Fixes

    • Adjusted validation handling in the RadioGroup component to remove unnecessary properties.

Copy link

changeset-bot bot commented Dec 3, 2024

⚠️ No Changeset found

Latest commit: ecfd471

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 Dec 3, 2024

@iqingting is attempting to deploy a commit to the NextUI Inc Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Dec 3, 2024

Walkthrough

This pull request introduces modifications across various story files for components like Autocomplete, Checkbox, Date Input, and others. The primary focus is on the WithDescription export, where the rendering logic has been updated to remove the description prop from args and instead manage it directly within the render function. Additionally, several components have seen changes to how descriptions are displayed, particularly handling cases where the description is a single space character. Overall, the changes streamline the presentation of the stories while maintaining existing functionality.

Changes

File Path Change Summary
packages/components/autocomplete/stories/autocomplete.stories.tsx Removed MirrorTemplate, replaced with an inline function for WithDescription, removed description from args.
packages/components/checkbox/stories/checkbox-group.stories.tsx Updated WithDescription to wrap two Template components in a div, removed description from args.
packages/components/date-input/src/date-input-group.tsx Modified rendering of description to display a non-breaking space for single spaces.
packages/components/date-input/stories/date-input.stories.tsx Updated WithDescription to center DateInput components, removed description from args.
packages/components/date-input/stories/time-input.stories.tsx Updated WithDescription to display two TimeInput components, removed description from args.
packages/components/date-picker/stories/date-picker.stories.tsx Updated WithDescription to wrap Template in a styled div, removed description from args.
packages/components/date-picker/stories/date-range-picker.stories.tsx Updated WithDescription to include a wrapper div, removed description from args.
packages/components/input-otp/stories/input-otp.stories.tsx Introduced InputOtpProps, updated WithDescription to conditionally include description.
packages/components/input/src/input.tsx Modified rendering logic for description to handle single space characters.
packages/components/input/stories/input.stories.tsx Added WithDescriptionTemplate, replacing MirrorTemplate in WithDescription.
packages/components/input/stories/textarea.stories.tsx Introduced new WithDescription story for Textarea component.
packages/components/radio/stories/radio.stories.tsx Updated WithDescription to render two Template components, removed isInvalid from ServerValidationTemplate.
packages/components/select/src/select.tsx Modified rendering logic for description to display non-breaking space for single spaces.
packages/components/select/stories/select.stories.tsx Updated WithDescription to render multiple Template instances with varying props, removed description from args.

Possibly related PRs

Suggested labels

πŸ‘€ Status: In Review, πŸ“‹ Scope : Docs

Suggested reviewers

  • jrgarciadev

πŸ“œ Recent review details

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

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 704ba52 and ecfd471.

πŸ“’ Files selected for processing (1)
  • packages/components/input/src/input.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/components/input/src/input.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 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.

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: 1

🧹 Outside diff range and nitpick comments (6)
packages/components/date-input/src/date-input-group.tsx (1)

67-69: LGTM! Consider documenting this behavior

The implementation elegantly handles single-space descriptions using a zero-width space character, which maintains layout consistency without visible content. This aligns well with the PR objectives.

Consider adding a code comment explaining the purpose of the zero-width space character (​) for future maintainers.

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

74-76: LGTM! Consider extracting to a shared utility

The implementation correctly uses the zero-width space approach, maintaining consistency with the date-input component.

Consider extracting this pattern into a shared utility function since it's used across multiple components:

// shared-utils.ts
export const renderDescription = (description: ReactNode) => 
  description === " " ? <span>&#8203;</span> : description;

This would ensure consistent behavior and make future updates easier.

packages/components/checkbox/stories/checkbox-group.stories.tsx (1)

235-242: LGTM! Consider using a more semantic class name.

The side-by-side comparison effectively demonstrates the layout behavior with and without descriptions. The implementation aligns well with the PR's objective of supporting single-space descriptions for layout consistency.

Consider renaming the class from w-full max-w-3xl to something more semantic like story-container to better convey its purpose. You can define this in your stories' CSS:

-      <div className="w-full max-w-3xl flex justify-center gap-4">
+      <div className="story-container flex justify-center gap-4">
packages/components/radio/stories/radio.stories.tsx (1)

Line range hint 282-285: Remove redundant description prop from args.

The description is now passed directly in the render function, making this prop in args redundant.

  args: {
    ...defaultProps,
-   description: "Please select an option",
  },
packages/components/select/stories/select.stories.tsx (1)

868-890: LGTM! Clean implementation of description variants.

The implementation effectively demonstrates different description scenarios, including the new single-space description support. The layout is well-structured and consistent with other stories.

Consider extracting the common props into a variable to improve readability:

  render: (args: SelectProps) => {
+   const commonProps = {
+     ...args,
+     label: "Favorite Animal",
+     placeholder: "Select an animal",
+   };
    return (
      <div className="w-full max-w-3xl flex justify-center gap-4">
        <Template
-         {...args}
+         {...commonProps}
          description="Select your favorite animal"
-         placeholder="Select an animal"
        />
        <Template
-         {...args}
+         {...commonProps}
          description="Select your favorite animal"
-         label="Favorite Animal"
-         placeholder="Select an animal"
        />
        <Template
-         {...args}
+         {...commonProps}
          description=" "
-         label="Favorite Animal"
-         placeholder="Select an animal"
        />
      </div>
    );
  },
packages/components/autocomplete/stories/autocomplete.stories.tsx (1)

962-969: LGTM! Consider aligning with select.stories.tsx implementation.

The implementation effectively demonstrates the description variants, including the single-space support. However, for consistency across components, consider matching the three variants shown in select.stories.tsx.

Consider aligning with select.stories.tsx by adding a third variant:

  render: (props: AutocompleteProps) => {
+   const commonProps = {
+     ...props,
+     label: "Favorite Animal",
+     placeholder: "Select an animal",
+   };
    return (
      <div className="w-full max-w-3xl flex justify-center gap-4">
-       <Template {...props} description="Select your favorite animal" />
-       <Template {...props} description=" " />
+       <Template {...commonProps} description="Select your favorite animal" />
+       <Template {...commonProps} description="Select your favorite animal" label="Favorite Animal" />
+       <Template {...commonProps} description=" " label="Favorite Animal" />
      </div>
    );
  },
πŸ“œ Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between e8bfdc8 and 704ba52.

πŸ“’ Files selected for processing (14)
  • packages/components/autocomplete/stories/autocomplete.stories.tsx (1 hunks)
  • packages/components/checkbox/stories/checkbox-group.stories.tsx (1 hunks)
  • packages/components/date-input/src/date-input-group.tsx (1 hunks)
  • packages/components/date-input/stories/date-input.stories.tsx (1 hunks)
  • packages/components/date-input/stories/time-input.stories.tsx (1 hunks)
  • packages/components/date-picker/stories/date-picker.stories.tsx (1 hunks)
  • packages/components/date-picker/stories/date-range-picker.stories.tsx (1 hunks)
  • packages/components/input-otp/stories/input-otp.stories.tsx (2 hunks)
  • packages/components/input/src/input.tsx (1 hunks)
  • packages/components/input/stories/input.stories.tsx (2 hunks)
  • packages/components/input/stories/textarea.stories.tsx (1 hunks)
  • packages/components/radio/stories/radio.stories.tsx (1 hunks)
  • packages/components/select/src/select.tsx (1 hunks)
  • packages/components/select/stories/select.stories.tsx (1 hunks)
πŸ”‡ Additional comments (10)
packages/components/input-otp/stories/input-otp.stories.tsx (2)

8-8: LGTM! Good type safety enhancement.

Adding the InputOtpProps type import improves type safety and code maintainability.


216-223: LGTM! Consistent implementation.

The side-by-side comparison follows the same pattern established in other components, maintaining consistency across the codebase.

packages/components/date-input/stories/time-input.stories.tsx (1)

188-195: LGTM! Well-structured implementation.

The changes maintain consistency with other components while properly demonstrating the layout behavior with descriptions. The use of TimeInputProps type ensures type safety.

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

217-230: LGTM! Well-structured story implementation.

The WithDescription story effectively demonstrates both cases:

  1. Component with descriptive text
  2. Component with single space description
packages/components/date-input/stories/date-input.stories.tsx (1)

213-220: LGTM! Clean and consistent implementation.

The story implementation follows the established pattern and maintains type safety with DateInputProps.

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

274-281: LGTM! Clean implementation of the WithDescription story.

The story implementation follows the established pattern and effectively demonstrates both description cases.

packages/components/date-picker/stories/date-picker.stories.tsx (1)

492-499: LGTM! Well-structured implementation for description variants.

The implementation effectively demonstrates both regular and single-space descriptions side by side, with proper layout constraints and spacing.

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

94-101: LGTM! Comprehensive template for description variants.

The template effectively demonstrates all three variants (with description, with placeholder, and with single space), using proper layout constraints.


601-601: LGTM! Proper integration of the new template.

The WithDescription export correctly uses the new template.

packages/components/date-picker/stories/date-range-picker.stories.tsx (1)

573-580: LGTM! Consistent implementation with other components.

The implementation follows the established pattern, effectively demonstrating both regular and single-space descriptions with proper layout constraints.

packages/components/input/src/input.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@Peterl561 Peterl561 left a comment

Choose a reason for hiding this comment

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

Aligning inputs is a styling problem that can be fixed through CSS (e.g. align-items: flex-start; or items-start class in tailwind). No need to make this change to input description's behavior.

@@ -64,7 +64,9 @@ export const DateInputGroup = forwardRef<"div", DateInputGroupProps>((props, ref
{isInvalid && errorMessage ? (
<div {...errorMessageProps}>{errorMessage}</div>
) : description ? (
<div {...descriptionProps}>{description}</div>
<div {...descriptionProps}>
{description === " " ? <span>&#8203;</span> : description}
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. It's not immediately clear for users that " " causes a span to appear where normally you'd expect text
  2. Doesn't seem ideal for accessibility

Copy link
Contributor

@Peterl561 Peterl561 Dec 4, 2024

Choose a reason for hiding this comment

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

Also this won't work if neighboring inputs have multiple lines of description.

@iqingting
Copy link
Author

iqingting commented Dec 5, 2024

Aligning inputs is a styling problem that can be fixed through CSS (e.g. align-items: flex-start; or items-start class in tailwind). No need to make this change to input description's behavior.

It's not just a style issue; the problem is that when no description is provided, the error messages disrupt the layout. For example, if the form is in a modal, the current behavior causes the modal's height to change as the form's validation status updates.

And what I do is set the description to an empty value to reserve space so that the error messages no longer disrupt the layout.

https://stackblitz.com/edit/vitejs-vite-mj4jjg?file=src%2FApp.tsx

CleanShot.2024-12-05.at.11.00.44.mp4

@Peterl561
Copy link
Contributor

Peterl561 commented Dec 5, 2024

It's not just a style issue; the problem is that when no description is provided, the error messages disrupt the layout. For example, if the form is in a modal, the current behavior causes the modal's height to change as the form's validation status updates.

That is definitely not great UI-wise, but I think solving it with some CSS is preferable to the implementation proposed in this PR, for the reasons I mentioned in my previous comments.

@iqingting
Copy link
Author

iqingting commented Dec 6, 2024

It's not just a style issue; the problem is that when no description is provided, the error messages disrupt the layout. For example, if the form is in a modal, the current behavior causes the modal's height to change as the form's validation status updates.

That is definitely not great UI-wise, but I think solving it with some CSS is preferable to the implementation proposed in this PR, for the reasons I mentioned in my previous comments.

I agree it’s not the best solution, but

  1. Why do you think don't disrupt the form layout when validate status change is not great UI-wise.
  2. flex-start doesn't work unless you set a static height for every form control, if you agree that preventing the form layout is a reasonable requirement.

@Peterl561
Copy link
Contributor

  1. Why do you think don't disrupt the form layout when validate status change is not great UI-wise.
  2. flex-start doesn't work unless you set a static height for every form control, if you agree that preventing the form layout is a reasonable requirement.

Sorry for the confusion. I meant that the form height changing is not great. I do think it would be nice if we could come up with a generalized fix, but I don't have any decent ideas.

The actual CSS implementation will of course depend on your requirements. If you are interested in discussing a specific CSS solution for your situation, you could try asking in Discord.

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.

3 participants