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(select): [select] fix the problem of multiple selection of hover … #2566

Merged
merged 3 commits into from
Nov 28, 2024

Conversation

MomoPoppy
Copy link
Collaborator

@MomoPoppy MomoPoppy commented Nov 27, 2024

…Expand not being centered

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

Release Notes

  • New Features

    • Introduced dynamic sizing for the select component with computedCurrentSizeMap.
    • Added new props for enhanced functionality: searchable, showEmptyImage, inputBoxType, tagType, clearNoMatchValue, showLimitText, showProportion, clickExpand, maxVisibleRows, showAllTextTag, and allText.
    • Implemented search functionality within the dropdown for better user experience.
  • Bug Fixes

    • Improved responsiveness of input height based on selected size and available space.
  • Style Updates

    • Refined layout and display properties for hover and click states in the select component, including adjustments to vertical alignment.

These enhancements aim to improve usability, flexibility, and responsiveness of the select component.

Copy link

coderabbitai bot commented Nov 27, 2024

Walkthrough

The changes in this pull request enhance the functionality of the select component across multiple files. A new computed property, computedCurrentSizeMap, is introduced to manage dynamic sizing based on the designConfig state. The mounted lifecycle hook is updated to utilize this property for setting the initial input height. Additional computed properties and new props are added to improve API capabilities and user interaction. Style adjustments refine the layout and display properties, particularly for hover and click states.

Changes

File Path Change Summary
packages/renderless/src/select/index.ts Added computedCurrentSizeMap for dynamic size management; updated mounted lifecycle hook to use this property for initial input height.
packages/renderless/src/select/vue.ts Introduced new computed properties: computedGetIcon, computedGetTagType, and computedCurrentSizeMap; updated API array and state initialization accordingly.
packages/theme/src/select/index.less Added new class .tiny-select__multiple.is-display-only and adjusted styles for .is-hover-expand and .is-click-expand classes.
packages/vue/src/select/src/pc.vue Added multiple new props (searchable, showEmptyImage, etc.) and modified template and script sections to enhance functionality and user interaction.
packages/theme/src/option/index.less Added vertical-align: top; to the .@{option-prefix-cls}-label class for improved alignment in the option component.

Possibly related PRs

Suggested reviewers

  • zzcr

🐰 In the meadow, changes bloom,
New sizes dance, dispelling gloom.
With props galore and styles refined,
Our select component's truly designed!
Hopping high with joy and cheer,
A better choice is finally here! 🌼

Warning

Rate limit exceeded

@MomoPoppy has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 19 minutes and 40 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 12b0da1 and cb0bb7b.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 12b0da1 and cb0bb7b.

📒 Files selected for processing (1)
  • packages/theme/src/option/index.less (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/theme/src/option/index.less

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.

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 Nov 27, 2024
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: 1

🧹 Outside diff range and nitpick comments (2)
packages/renderless/src/select/vue.ts (2)

Line range hint 1-113: API array is missing some of the new computed properties.

The API array should include all the computed properties that are part of the component's public interface. Currently, only isTagClosable is included, but computedGetIcon, computedGetTagType, and computedCurrentSizeMap are missing.

Add the missing computed properties to the API array:

export const api = [
  // ... existing entries ...
  'getLabelSlotValue',
  'loadTreeData',
  'updateModelValue',
  'clearSearchText',
  'onClickCollapseTag',
  'computedShowTagText',
- 'isTagClosable'
+ 'isTagClosable',
+ 'computedGetIcon',
+ 'computedGetTagType',
+ 'computedCurrentSizeMap'
]

Line range hint 1-644: Good architectural approach with renderless pattern.

The implementation follows the renderless component pattern, which promotes good separation of concerns between logic and presentation. The new functionality for icons and tag types is integrated consistently with this pattern.

However, consider the following architectural improvements:

  1. Document the purpose and expected values of the new computed properties
  2. Consider extracting the icon and tag type logic into a separate composable if they might be reused in other components
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1df0f4d and 12b0da1.

📒 Files selected for processing (4)
  • packages/renderless/src/select/index.ts (2 hunks)
  • packages/renderless/src/select/vue.ts (3 hunks)
  • packages/theme/src/select/index.less (1 hunks)
  • packages/vue/src/select/src/pc.vue (1 hunks)
🔇 Additional comments (5)
packages/theme/src/select/index.less (1)

225-230: LGTM! Please verify the fix and add documentation.

The addition of vertical alignment for display-only multiple select in hover/click expand states looks correct. However:

  1. Please verify that this change fully addresses the multiple selection hover issue mentioned in the PR objectives.
  2. Consider adding a comment explaining why this vertical alignment is necessary to help future maintainers.

Let's verify if this style change affects other components or states:

✅ Verification successful

Vertical alignment change is consistent with existing patterns

The vertical-align: top property is already used consistently across related components:

  • It's applied to hover/click expand states in base-select
  • It's used in cascader's hover-expand state
  • The new addition for multiple select display-only follows the same pattern

The change is safe and aligns with the existing codebase conventions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other components that might be affected by vertical alignment changes
# or that use similar expand states

# Look for other components using similar class combinations
rg -l "is-hover-expand|is-click-expand" --type less

# Look for potential vertical alignment dependencies
rg -l "vertical-align.*top.*select" --type less

Length of output: 307


Script:

#!/bin/bash
# Let's examine the related files to understand the impact and consistency

# Check how vertical-align is used in base-select
rg "vertical-align" packages/theme/src/base-select/index.less -B 2 -A 2

# Check the context of hover/click expand in cascader
rg "is-hover-expand|is-click-expand" packages/theme/src/cascader/index.less -B 2 -A 2

# Look for similar multiple selection display-only patterns
rg "multiple.*display-only" packages/theme/src/base-select/index.less packages/theme/src/select/index.less -B 2 -A 2

Length of output: 870

packages/renderless/src/select/vue.ts (2)

247-248: LGTM: State initialization is well-structured.

The new state properties are properly initialized with computed values and the designConfig integration is handled correctly with proper fallbacks.


409-410: Verify the implementation of isTagClosable.

The isTagClosable function is called without parameters during API initialization, but it might need access to component state or props to determine if a tag is closable.

Let's check the implementation of isTagClosable:

✅ Verification successful

The isTagClosable implementation is correct

The implementation of isTagClosable is a higher-order function that returns a function taking an item parameter, which is exactly what's needed. The function is defined in both packages/renderless/src/select/index.ts and packages/renderless/src/base-select/index.ts as:

export const isTagClosable = () => (item) => !item.required

This matches its usage in the Vue templates where it's called with an item parameter:

:closable="isTagClosable(item)"
:closable="isTagClosable(state.selected[0])"
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the implementation of isTagClosable
ast-grep --pattern 'isTagClosable = $_' -l ts,js

Length of output: 161


Script:

#!/bin/bash
# Search for the implementation of isTagClosable with correct language flags
ast-grep --pattern 'isTagClosable = $_'

# Also search for any declaration or definition using ripgrep
rg "isTagClosable" -A 3

Length of output: 4074

packages/renderless/src/select/index.ts (2)

2051-2058: LGTM! Well-structured computed property for size management.

The implementation provides good flexibility with design system configuration while maintaining sensible defaults.


752-752: LGTM! Good use of computed property for dynamic sizing.

The changes properly integrate the computed size map and handle spacing configuration, making the component more maintainable and configurable.

Also applies to: 756-756

@@ -151,7 +151,7 @@
:type="state.getTagType"
key="tags-collapse"
data-tag="tags-collapse"
only-icon
:only-icon="!hoverExpand"
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure hoverExpand prop is defined to prevent runtime errors

The hoverExpand property is used in the template but is not currently defined as a prop or within the component's data or computed properties. This could lead to runtime errors due to accessing an undefined property.

Apply this diff to define hoverExpand as a prop:

  props: [
    ...props,
    // 以下为 tiny 新增
    'searchable',
    'showEmptyImage',
    'inputBoxType',
    'tagType',
    'clearNoMatchValue',
    'showLimitText',
    'showProportion',
    'clickExpand',
    'maxVisibleRows',
    'showAllTextTag',
    'allText',
+   'hoverExpand'
  ],

Committable suggestion skipped: line range outside the PR's diff.

@zzcr zzcr merged commit d3fcc60 into opentiny:dev Nov 28, 2024
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants