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: tabbar support mouse wheel vertical #5129

Merged
merged 3 commits into from
Dec 13, 2024

Conversation

mynetfan
Copy link
Collaborator

@mynetfan mynetfan commented Dec 13, 2024

Description

默认情况下,标签栏是横向滚动的,只能支持系统的横向滚动事件,因此只能按下Shift键才能滚动标签栏。

现在添加了一个开关,可以响应系统的纵向滚动事件。开启后,无需按下Shift键直接可以使用滚轮滚动标签栏。

close #4474

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Checklist

ℹ️ Check all checkboxes - this will indicate that you have done everything in accordance with the rules in CONTRIBUTING.

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs:dev command.
  • Run the tests with pnpm test.
  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • New Features

    • Introduced a wheelable property for the tab bar, enabling mouse wheel interactions for navigation.
    • Added a switch in preferences to control the wheelable feature.
    • Enhanced tooltips for better user guidance on the new functionality.
  • Documentation

    • Updated language files to include descriptions for the wheelable feature in English and Chinese.
  • Bug Fixes

    • Improved scrolling behavior for the tab interface, ensuring smoother user interactions.

Copy link

changeset-bot bot commented Dec 13, 2024

⚠️ No Changeset found

Latest commit: 58aa2dc

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
Contributor

coderabbitai bot commented Dec 13, 2024

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • packages/@core/preferences/__tests__/__snapshots__/config.test.ts.snap is excluded by !**/*.snap

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request introduces a new wheelable property to various components and configurations related to tab navigation, allowing the tab bar to respond to mouse wheel events. This includes updates to the defaultPreferences, TabbarPreferences interface, and several Vue components. The changes enhance user interaction by enabling scrolling through tabs using the mouse wheel, along with necessary localization updates for user preferences.

Changes

File Change Summary
packages/@core/preferences/src/config.ts Added wheelable: true to tabbar in defaultPreferences.
packages/@core/preferences/src/types.ts Added wheelable: boolean; to TabbarPreferences interface.
packages/@core/ui-kit/tabs-ui/src/tabs-view.vue Added wheelable prop and onWheel method; integrated with VbenScrollbar for wheel event handling.
packages/@core/ui-kit/tabs-ui/src/types.ts Added styleType?: TabsStyleType; and wheelable?: boolean; to TabsProps interface.
packages/@core/ui-kit/tabs-ui/src/use-tabs-view-scroll.ts Added handleWheel method for smooth scrolling based on wheel events; made it accessible from the return object.
packages/effects/layouts/src/basic/tabbar/tabbar.vue Introduced :wheelable property bound to preferences.tabbar.wheelable.
packages/effects/layouts/src/widgets/preferences/blocks/layout/tabbar.vue Added tabbarWheelable model with a UI switch for enabling/disabling wheel support.
packages/effects/layouts/src/widgets/preferences/blocks/switch-item.vue Updated switch-item.vue to include a new optional tip property for tooltips.
packages/effects/layouts/src/widgets/preferences/preferences-drawer.vue Added tabbarWheelable model and bound it to the Tabbar component.
packages/locales/src/langs/en-US/preferences.json Added localization entries for wheelable and wheelableTip.
packages/locales/src/langs/zh-CN/preferences.json Added localization entries for wheelable and wheelableTip.

Possibly related PRs

Suggested reviewers

  • anncwb
  • vince292007

Poem

🐰 In the land of tabs, we hop and scroll,
With wheelable magic, we take control!
A flick of the wrist, and tabs glide with glee,
Navigating with ease, just you wait and see!
So let’s celebrate this change, oh so bright,
For wheelable wonders bring joy to our night! 🌙


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. (Experiment)
  • @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.

@mynetfan mynetfan changed the title Feat/tabbar wheel feat: tabbar support mouse wheel vertical Dec 13, 2024
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

🧹 Outside diff range and nitpick comments (8)
packages/@core/ui-kit/tabs-ui/src/types.ts (2)

46-54: Consider adding English documentation

The styleType property documentation only includes Chinese comments. Consider adding English documentation to maintain consistency with international developers.

/**
+ * @en_US Tab style type
 * @zh_CN 标签页风格
 */
styleType?: TabsStyleType;

56-59: Consider adding English documentation

The wheelable property documentation only includes Chinese comments. Consider adding English documentation to improve accessibility for international developers.

/**
+ * @en_US Whether to respond to mouse wheel events
 * @zh_CN 是否响应滚轮事件
 */
wheelable?: boolean;
packages/effects/layouts/src/widgets/preferences/blocks/switch-item.vue (1)

36-46: Consider enhancing type safety for tooltip content

The tooltip implementation handles multi-line content well, but could benefit from additional type safety.

Consider creating a computed property to handle the tip splitting:

<script setup lang="ts">
+ const tooltipLines = computed(() => tip.split('\n'));
</script>

<template>
  ...
  <slot name="tip">
    <template v-if="tip">
-     <p v-for="(line, index) in tip.split('\n')" :key="index">
+     <p v-for="(line, index) in tooltipLines" :key="index">
        {{ line }}
      </p>
    </template>
  </slot>
  ...
</template>
packages/effects/layouts/src/widgets/preferences/blocks/layout/tabbar.vue (1)

21-21: LGTM! Consider grouping related preferences together.

The implementation of the wheelable preference is well-structured and follows the established patterns. The switch item is properly integrated with localization and conditional disabling.

Consider grouping this preference with other scrolling/navigation-related preferences for better organization.

Consider moving this switch item next to the tabbarDraggable switch since both relate to tab navigation/interaction.

Also applies to: 57-63

packages/@core/ui-kit/tabs-ui/src/tabs-view.vue (1)

39-45: Consider improving wheel event handling.

A few suggestions to enhance the wheel event handler:

  1. Consider debouncing the handler for smoother scrolling
  2. Add browser compatibility checks
  3. Consider adding ARIA attributes to indicate scrollable region

Here's a suggested implementation:

+import { debounce } from 'lodash-es';
+
+const debouncedHandleWheel = debounce((e: WheelEvent) => {
+  handleWheel(e);
+}, 16); // ~60fps
+
 function onWheel(e: WheelEvent) {
   if (props.wheelable) {
-    handleWheel(e);
+    debouncedHandleWheel(e);
     e.stopPropagation();
     e.preventDefault();
   }
 }

Also, add ARIA attributes to the scrollable region:

 <VbenScrollbar
   ref="scrollbarRef"
   :shadow-bottom="false"
   :shadow-top="false"
   class="h-full"
   horizontal
   scroll-bar-class="z-10 hidden "
   shadow
   shadow-left
   shadow-right
+  role="region"
+  aria-label="Scrollable tabs"
   @scroll-at="handleScrollAt"
   @wheel="onWheel"
 >
packages/@core/ui-kit/tabs-ui/src/use-tabs-view-scroll.ts (1)

145-150: Consider enhancing the wheel scroll implementation.

While the basic implementation works, there are several improvements that could make it more robust:

  1. The scroll multiplier (3) should be configurable to allow customization of scroll sensitivity
  2. Consider handling horizontal scroll events (deltaX) for trackpad users
  3. Add boundary checks to prevent unnecessary scroll attempts
  4. Consider preventing default scroll behavior to avoid conflicts

Here's a suggested enhancement:

-  function handleWheel({ deltaY }: WheelEvent) {
+  function handleWheel(event: WheelEvent) {
+    const { deltaY, deltaX } = event;
+    const scrollMultiplier = 3; // Consider making this configurable
+    
+    if (!scrollViewportEl.value) return;
+    
+    // Prevent default only if scroll would be effective
+    const newScrollLeft = scrollViewportEl.value.scrollLeft + (deltaY + deltaX) * scrollMultiplier;
+    if (newScrollLeft >= 0 && 
+        newScrollLeft <= scrollViewportEl.value.scrollWidth - scrollViewportEl.value.clientWidth) {
+      event.preventDefault();
+      
+      scrollViewportEl.value.scrollBy({
+        behavior: 'smooth',
+        left: (deltaY + deltaX) * scrollMultiplier,
+      });
+    }
   }
packages/locales/src/langs/en-US/preferences.json (1)

58-59: Enhance English translations for consistency with Chinese version.

The English translations could be more detailed to match the information provided in the Chinese version:

-    "wheelable": "Support Mouse Wheel",
-    "wheelableTip": "When enabled, the Tabbar area responds to vertical scrolling events of the scroll wheel.",
+    "wheelable": "Enable Vertical Wheel Scrolling",
+    "wheelableTip": "When enabled, the tabbar area responds to vertical scroll wheel events. When disabled, only system horizontal scroll events (requiring Shift + wheel) are supported."
packages/@core/preferences/src/types.ts (1)

176-177: Maintain documentation consistency by translating the comment to English.

The JSDoc comment should be in English to maintain consistency with other comments in the file.

-  /** 是否开启鼠标滚轮响应 */
+  /** Whether to enable mouse wheel scrolling */
   wheelable: boolean;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between be208fe and 80c8528.

📒 Files selected for processing (11)
  • packages/@core/preferences/src/config.ts (1 hunks)
  • packages/@core/preferences/src/types.ts (1 hunks)
  • packages/@core/ui-kit/tabs-ui/src/tabs-view.vue (3 hunks)
  • packages/@core/ui-kit/tabs-ui/src/types.ts (1 hunks)
  • packages/@core/ui-kit/tabs-ui/src/use-tabs-view-scroll.ts (2 hunks)
  • packages/effects/layouts/src/basic/tabbar/tabbar.vue (1 hunks)
  • packages/effects/layouts/src/widgets/preferences/blocks/layout/tabbar.vue (2 hunks)
  • packages/effects/layouts/src/widgets/preferences/blocks/switch-item.vue (2 hunks)
  • packages/effects/layouts/src/widgets/preferences/preferences-drawer.vue (2 hunks)
  • packages/locales/src/langs/en-US/preferences.json (1 hunks)
  • packages/locales/src/langs/zh-CN/preferences.json (1 hunks)
🔇 Additional comments (9)
packages/@core/ui-kit/tabs-ui/src/types.ts (1)

46-59: LGTM! Type definitions are well-structured

The new properties are properly typed and follow the existing interface pattern.

packages/effects/layouts/src/widgets/preferences/blocks/switch-item.vue (1)

11-13: LGTM! Props are well-defined

The new tip prop is properly typed with a sensible default value.

packages/effects/layouts/src/basic/tabbar/tabbar.vue (1)

58-58: LGTM! Clean implementation of the wheelable property

The wheelable property is properly bound to the preferences system and follows the component's existing pattern.

packages/@core/preferences/src/config.ts (1)

86-86: LGTM! Default configuration looks good.

The wheelable property is correctly placed in the tabbar section with a sensible default value of true.

packages/@core/ui-kit/tabs-ui/src/tabs-view.vue (2)

22-22: LGTM! Default prop value aligns with preferences.

The default value of true for the wheelable prop matches the default preferences configuration.


82-82: Verify wheel event behavior across browsers.

The wheel event behavior can vary across different browsers. We should verify that the scrolling works consistently.

✅ Verification successful

Let me analyze the wheel event implementation further by checking for any browser-specific handling or test cases.


Let me check the wheel event implementation more thoroughly with a corrected command.


Wheel event implementation is safe and well-implemented

The wheel event implementation is properly handled with several safety measures in place:

  • Uses standard WheelEvent interface which is well-supported across modern browsers
  • Implements smooth scrolling behavior using native scrollBy API
  • Has proper cleanup with ResizeObserver and MutationObserver
  • The scrolling is controlled by a configurable wheelable prop
  • Includes event prevention to avoid conflicting scroll behaviors
  • Uses a reasonable scroll multiplier (3x) for smooth horizontal scrolling
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for browser compatibility checks or normalizations
rg -g '!{dist,node_modules}/*' -A 5 'WheelEvent|wheel.*event'

Length of output: 1519


Script:

#!/bin/bash
# Search for any browser-specific handling in the tabs implementation
rg -g '!{dist,node_modules}/*' -A 5 'browser|navigator|userAgent' packages/@core/ui-kit/tabs-ui/

# Look for test files related to wheel events
fd -g '*test*' -g '*spec*' packages/@core/ui-kit/tabs-ui/ --exec rg -l 'wheel|WheelEvent'

Length of output: 243


Script:

#!/bin/bash
# Look at the complete implementation of use-tabs-view-scroll.ts
cat packages/@core/ui-kit/tabs-ui/src/use-tabs-view-scroll.ts

# Search for test files with corrected syntax
fd -e spec.ts -e test.ts . packages/@core/ui-kit/tabs-ui/ --exec rg -l 'wheel|WheelEvent' {}

Length of output: 4873

packages/locales/src/langs/zh-CN/preferences.json (1)

58-59: LGTM! Clear and informative localization entries.

The Chinese translations for the new wheelable feature are clear, accurate, and provide good context about the functionality.

packages/@core/ui-kit/tabs-ui/src/use-tabs-view-scroll.ts (1)

194-194: Verify the handleWheel export.

The handleWheel method is now exposed through the hook's return object. Ensure that components using this hook properly handle wheel events and respect the wheelable preference.

✅ Verification successful

The handleWheel implementation is properly used and controlled by wheelable prop

The verification shows that:

  • handleWheel is correctly implemented in use-tabs-view-scroll.ts and exposed through the hook's return object
  • It's properly consumed in tabs-view.vue where it's only called when the wheelable prop is true
  • The wheel event is properly handled with stopPropagation and preventDefault
  • The implementation includes smooth scrolling behavior with appropriate deltaY multiplication

The code demonstrates proper handling of wheel events and respect for the wheelable preference as originally intended.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for components using handleWheel
ast-grep --pattern 'handleWheel($$$)'

Length of output: 39


Script:

#!/bin/bash
# Search for usages of handleWheel with ripgrep for better context
rg "handleWheel" -A 3

# Also search for any imports or destructuring of handleWheel
rg "handleWheel.*}" -A 3

# Search for use-tabs-view-scroll hook usage
rg "useTabsViewScroll" -A 3

Length of output: 2654

packages/effects/layouts/src/widgets/preferences/preferences-drawer.vue (1)

108-108: LGTM! Well-integrated changes.

The new tabbarWheelable model is correctly defined and integrated, maintaining consistency with the existing codebase patterns for both the model declaration and its binding in the template.

Also applies to: 349-349

@mynetfan mynetfan merged commit 7fbf7b1 into vbenjs:main Dec 13, 2024
13 checks passed
@mynetfan mynetfan deleted the feat/tabbar-wheel branch December 13, 2024 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FEATURE: 标签页能否支持鼠标滚动
1 participant