Skip to content

fix: fix form item not align when set display-only #2950

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

Merged
merged 2 commits into from
Feb 24, 2025
Merged

Conversation

gimmyhehe
Copy link
Member

@gimmyhehe gimmyhehe commented Feb 24, 2025

PR

修复多端模板,表单仅展示表单项对齐问题

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • Style
    • Improved spacing and alignment for form elements in display-only mode.
    • Enhanced numeric displays with refined line heights and background accents.
    • Adjusted radio button visuals with better alignment and cursor behavior.
    • Updated switch component styling to consistently indicate disabled states.

Copy link

coderabbitai bot commented Feb 24, 2025

Walkthrough

This pull request makes a series of styling updates in several Vue components. Modifications include adjustments to class bindings in mobile-first components for form items, numeric inputs, and switches—primarily controlling spacing, leading, heights, and disabled states based on component state properties. Additionally, token files for numeric and radio components have been updated to modify background, alignment, and cursor styling. No public API declarations were altered.

Changes

File(s) Change Summary
packages/vue/src/form-item/src/mobile-first.vue, packages/vue/src/numeric/src/mobile-first.vue, packages/vue/src/switch/src/mobile-first.vue Adjusted conditional class bindings based on state.isDisplayOnly and state.disabled. In form-item, updated label, span, and inline item classes; in numeric, changed line height; in switch, replaced use of disabled with state.disabled for consistency.
packages/vue/src/numeric/src/token.ts, packages/vue/src/radio/src/token.ts Updated CSS token definitions: numeric token now includes a bg-color-bg-1 class; radio token removed align-middle from the default entry, added cursor-default in readonly states, and adjusted alignment for the non-readonly case.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant SwitchComponent
  participant State
  User->>SwitchComponent: Toggle switch
  SwitchComponent->>State: Check state.disabled and types
  alt State is disabled or loading
    SwitchComponent->>SwitchComponent: Render with "-disabled" classes for overall switch, handle, and icons
  else
    SwitchComponent->>SwitchComponent: Render with "-not-disabled" (or default) classes
  end
Loading

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • zzcr

Poem

I hop through lines of Vue with style,
Adjusting classes with a twitch and a smile.
Display-only and disabled states now align true,
My little paws dance on code so new.
With a hop, skip, and joyful cheer, I celebrate changes here!
🐰✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/vue/src/form-item/src/mobile-first.vue

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

packages/vue/src/numeric/src/token.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

packages/vue/src/numeric/src/mobile-first.vue

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

  • 2 others
✨ 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@github-actions github-actions bot added the bug Something isn't working label Feb 24, 2025
Copy link

Walkthrough

此PR修复了在多端模板中,当表单项设置为仅展示时的对齐问题。通过调整CSS类和条件渲染,确保在不同的显示状态下,表单项能够正确对齐。

Changes

文件 概要
packages/vue/src/form-item/src/mobile-first.vue 修改了CSS类以修复表单项在仅展示状态下的对齐问题。
packages/vue/src/numeric/src/mobile-first.vue 更新了CSS类以调整显示文本的行高。
packages/vue/src/numeric/src/token.ts 增加了背景颜色类以改善输入框的视觉效果。
packages/vue/src/radio/src/token.ts 修改了CSS类以改善只读状态下的光标样式。
packages/vue/src/switch/src/mobile-first.vue 修正了开关组件在禁用状态下的样式判断逻辑。

Copy link

[e2e-test-warn]
The component to be tested is missing.

The title of the Pull request should look like "fix(vue-renderless): [action-menu, alert] fix xxx bug".

Please make sure you've read our contributing guide

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

🧹 Nitpick comments (2)
packages/vue/src/form-item/src/mobile-first.vue (2)

76-76: Consider extracting magic numbers into CSS variables.

The height values (h-[22px] and h-7) should be extracted into CSS variables for better maintainability and consistency across the component.

Consider this refactor:

-          state.isDisplayOnly ? '[&_[data-tag=tiny-rate]]:h-[22px]' : '[&_[data-tag=tiny-rate]]:h-7',
+          state.isDisplayOnly ? `[&_[data-tag=tiny-rate]]:h-[var(--tiny-rate-display-only-height,22px)]` : '[&_[data-tag=tiny-rate]]:h-[var(--tiny-rate-height,theme(spacing.7))]',

Also applies to: 80-80


112-113: Consider extracting component-specific styles.

The component-specific styles should be extracted into separate classes or CSS variables for better maintainability and reusability.

Consider this refactor:

-            ? 'sm:leading-5.5 [&_>*:not([data-tag^=tiny-],[class^=tiny-])]:leading-8 [&_>*:not([data-tag^=tiny-],[class^=tiny-])]:sm:leading-normal'
-            : '[&_[data-tag=tiny-checkbox]]:h-7 [&_[data-tag=tiny-radio]]:h-7'
+            ? `
+                sm:leading-[var(--tiny-form-item-display-only-leading,1.375rem)]
+                [&_>*:not([data-tag^=tiny-],[class^=tiny-])]:leading-[var(--tiny-form-item-leading,2rem)]
+                [&_>*:not([data-tag^=tiny-],[class^=tiny-])]:sm:leading-normal
+              `
+            : `
+                [&_[data-tag=tiny-checkbox]]:h-[var(--tiny-checkbox-height,theme(spacing.7))]
+                [&_[data-tag=tiny-radio]]:h-[var(--tiny-radio-height,theme(spacing.7))]
+              `
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 47050d0 and e255d26.

📒 Files selected for processing (5)
  • packages/vue/src/form-item/src/mobile-first.vue (4 hunks)
  • packages/vue/src/numeric/src/mobile-first.vue (1 hunks)
  • packages/vue/src/numeric/src/token.ts (1 hunks)
  • packages/vue/src/radio/src/token.ts (2 hunks)
  • packages/vue/src/switch/src/mobile-first.vue (4 hunks)
🔇 Additional comments (7)
packages/vue/src/numeric/src/token.ts (1)

28-28: LGTM! Background color addition improves visual consistency.

The addition of bg-color-bg-1 class ensures consistent background color for numeric inputs, which helps with the form item alignment in display-only mode.

packages/vue/src/radio/src/token.ts (2)

2-2: LGTM! Improved radio button layout.

The updated class definition improves the radio button layout with better alignment and spacing.


40-42: LGTM! Enhanced readonly state styling.

The changes improve user experience by:

  • Setting appropriate cursor style for readonly states
  • Maintaining consistent alignment with other form elements
packages/vue/src/switch/src/mobile-first.vue (1)

9-9: LGTM! Improved state management consistency.

The changes consistently use state.disabled instead of the direct prop, which improves code maintainability and follows Vue's best practices for state management.

Also applies to: 28-29, 65-65, 78-78

packages/vue/src/numeric/src/mobile-first.vue (1)

106-106: LGTM! Fixed line height for better alignment.

The change from sm:leading-normal to sm:leading-5.5 provides precise line height control, which helps fix the form item alignment in display-only mode.

packages/vue/src/form-item/src/mobile-first.vue (2)

29-29: LGTM! Label styling improvements for display-only mode.

The changes appropriately simplify label styling in display-only mode by inheriting alignment and adjusting padding, which helps fix the alignment issues.

Also applies to: 37-37


52-52:

❓ Verification inconclusive

LGTM! Enhanced content visibility and line height consistency.

The increased max-height and adjusted line heights improve content visibility and maintain consistent spacing. Please verify that these changes don't cause any content clipping issues with longer labels.

Run this script to check for potential content clipping issues:

Also applies to: 56-56


🏁 Script executed:

#!/bin/bash
# Description: Search for long label text in the codebase that might be affected by the max-height change.

# Search for label prop assignments with long text
rg -U "label=[\"\'].*[\"\']" --type vue -A 1 -B 1

# Search for label slot usage with potentially long content
rg -U "<template\s+#label>.*</template>" --type vue -A 1 -B 1

Length of output: 240


LGTM! Enhanced content visibility and improved spacing.

The updated max-height and line-height adjustments look good overall. However, the previous script intended to check for potential clipping issues with longer label text returned errors. To further verify that no clipping occurs for longer labels, please run the revised script below:

#!/bin/bash
# Description: Search for long label text in all Vue files to verify that the max-height change does not lead to content clipping.

# Search for label prop assignments with long text in Vue files
rg "label=['\"].*['\"]" --glob '*.vue' -A 2 -B 2

# Search for label slot usage with potentially long content in Vue files
rg "<template\s+#label>.*</template>" --glob '*.vue' -A 2 -B 2

Please confirm that these queries do not expose any clipping issues with long label content.

@zzcr zzcr merged commit a6b0bfb into dev Feb 24, 2025
11 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Apr 1, 2025
13 tasks
@kagol kagol deleted the cgm/sync-form-2 branch April 14, 2025 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants