Skip to content

Conversation

PeikyLiu
Copy link
Contributor

@PeikyLiu PeikyLiu commented Jun 16, 2025

🐛 Bug Fix: Dropdown width not adapting when block prop is true

Problem

When the block prop is set to true on the Suggestion component, the dropdown width was not properly matching the slot element width, causing layout inconsistency and poor visual alignment.

Root Cause

The component was not dynamically monitoring the slot element's width changes, resulting in the dropdown maintaining its default width instead of adapting to the container's actual width.

Solution

  • Added useElementWidth hook: A reusable utility that leverages ResizeObserver to monitor element width changes in real-time
  • Implemented dynamic width synchronization: The dropdown now automatically adjusts its width to match the slot element when block mode is enabled
  • Improved layout consistency: Ensures proper visual alignment between the trigger element and dropdown in block mode

Technical Changes

  1. New hook: useElementWidth for real-time element width monitoring
  2. Computed dropdown style: dropdownStyle that conditionally applies width based on block prop
  3. Reactive width tracking: Uses ResizeObserver for efficient width change detection

Code Changes

// Before
<Cascader
  dropdownMatchSelectWidth={block}
  // ... other props
>

// After  
<Cascader
  dropdownStyle={dropdownStyle.value}
  // ... other props
>

Before/After

Before: Dropdown maintains fixed width regardless of container size
After: Dropdown width dynamically adapts to match container width in block mode


Fixes: Block mode layout inconsistency
Component: Suggestion
Type: Bug Fix

fix #143

Summary by CodeRabbit

  • New Features

    • Dropdown width now dynamically matches the width of the select element when the block option is enabled, providing a more consistent and responsive appearance.
  • Refactor

    • Improved dropdown width control by replacing the previous static setting with a dynamic style based on the actual element width.

Copy link

netlify bot commented Jun 16, 2025

Deploy Preview for antd-design-x-vue ready!

Name Link
🔨 Latest commit 67cf95e
🔍 Latest deploy log https://app.netlify.com/projects/antd-design-x-vue/deploys/685fcffaec7e650008bef9b7
😎 Deploy Preview https://deploy-preview-358--antd-design-x-vue.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

coderabbitai bot commented Jun 16, 2025

"""

Walkthrough

The change updates the dropdown width handling in the Suggestion.vue component. It introduces a reactive reference to measure the slot container's width and applies this width dynamically to the dropdown using a computed style, replacing the previous boolean prop-based width control with a responsive approach.

Changes

File(s) Change Summary
src/suggestion/Suggestion.vue Replaces boolean width prop with dynamic style; adds element ref and width tracking for dropdown.
package.json Moves @vueuse/core from devDependencies to dependencies with updated version.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SuggestionComponent
    participant Cascader
    Note over SuggestionComponent: On render
    SuggestionComponent->>SuggestionComponent: Reference slot container (cascaderSlotRef)
    SuggestionComponent->>SuggestionComponent: Measure container width (useElementSize)
    SuggestionComponent->>SuggestionComponent: Compute dropdownStyle with width if block=true
    SuggestionComponent->>Cascader: Pass dropdownStyle as prop
    User->>SuggestionComponent: Interacts with dropdown
    Cascader->>User: Renders dropdown with computed width
Loading

Assessment against linked issues

Objective Addressed Explanation
修复 suggestion 组件设置为整行宽度不生效 (#143)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Poem

A dropdown once narrow, now stretches with pride,
Measured by code, its width can't hide.
With reactive delight, the slot’s size is known,
The Suggestion component has gracefully grown.
Cascader and style, in harmony play—
Bugs hop away, and features stay!
🐇✨
"""

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.

src/suggestion/Suggestion.vue

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Failed to load parser 'vue-eslint-parser' declared in '.eslintrc.js': Cannot find module 'vue-eslint-parser'
Require stack:

  • /.eslintrc.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1369:15)
    at require.resolve (node:internal/modules/helpers:145:19)
    at Object.resolve (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2346:46)
    at ConfigArrayFactory._loadParser (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3325:39)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3099:43)
    at _normalizeObjectConfigDataBody.next ()
    at ConfigArrayFactory._normalizeObjectConfigData (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3040:20)
    at _normalizeObjectConfigData.next ()
    at ConfigArrayFactory.loadInDirectory (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2886:28)
    at CascadingConfigArrayFactory._loadConfigInAncestors (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3871:46)

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 618284d and 67cf95e.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • package.json (1 hunks)
  • src/suggestion/Suggestion.vue (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • package.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/suggestion/Suggestion.vue

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

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.

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

🧹 Nitpick comments (3)
src/_util/hooks/use-element-width.ts (2)

1-1: Style: add spaces after commas for readability

The import list is hard to read without spaces after the commas.

-import { ref,onMounted,onUnmounted, type Ref } from "vue";
+import { ref, onMounted, onUnmounted, type Ref } from 'vue';

22-23: Return a readonly ref to prevent external mutation

Exposing a mutable ref allows consumers to overwrite the width accidentally.

-import { readonly } from 'vue';-  return width
+  return readonly(width);
src/suggestion/Suggestion.vue (1)

43-44: Initialise ref with null for clearer typing

ref<HTMLElement>() defaults to undefined, but Vue DOM refs conventionally start as null, which plays nicer with strict templates.

-const cascaderSlotRef = ref<HTMLElement>();
+const cascaderSlotRef = ref<HTMLElement | null>(null);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0cc91e2 and 6b009cd.

📒 Files selected for processing (2)
  • src/_util/hooks/use-element-width.ts (1 hunks)
  • src/suggestion/Suggestion.vue (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/_util/hooks/use-element-width.ts (1)
src/vc-util/Dom/isVisible.ts (1)
  • element (1-25)
🔇 Additional comments (1)
src/suggestion/Suggestion.vue (1)

130-131: Ensure loss of dropdownMatchSelectWidth doesn’t regress non-block behaviour

The old implementation relied on dropdownMatchSelectWidth. Removing it may
change width behaviour when block === false.

Please verify all call-sites visually or re-add the prop for the non-block
case:

<Cascader
   …
-  dropdownStyle={dropdownStyle.value}
+  dropdownMatchSelectWidth={!block}
+  dropdownStyle={dropdownStyle.value}
>

@wzc520pyfm wzc520pyfm added bug Something isn't working Suggestion labels Jun 22, 2025
@wzc520pyfm wzc520pyfm force-pushed the suggestion/style/block branch from 618284d to 67cf95e Compare June 28, 2025 11:20
Copy link
Owner

@wzc520pyfm wzc520pyfm left a comment

Choose a reason for hiding this comment

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

Great work!

@wzc520pyfm wzc520pyfm merged commit 18b23af into wzc520pyfm:main Jun 28, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Suggestion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] suggestion组件设置为整行宽度不生效
2 participants