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

Add AutoGoToTop parameter to BitAppShell (#9788) #9789

Merged

Conversation

msynk
Copy link
Member

@msynk msynk commented Feb 4, 2025

closes #9788

Summary by CodeRabbit

  • New Features
    • Enhanced navigation with customizable scrolling options—choose between smooth, instant, or CSS-driven behavior for improved page transitions.
    • Introduced an auto-scroll-to-top option that automatically positions the view at the top during navigation.
    • Updated the component demos to showcase these additional configuration options for a more intuitive and flexible user experience.

Copy link

coderabbitai bot commented Feb 4, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

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

Walkthrough

The changes enhance navigation handling and component lifecycle management. The BitAppShell class now implements IDisposable and subscribes to navigation events to auto-scroll to the top when enabled. A new AutoGoToTop parameter and additional scroll behavior options are introduced via the BitScrollBehavior enum. The JS interop and TypeScript functions have been updated to support this behavior. Demo components and related pages are modified to showcase and integrate these new features, while some outdated event handlers have been removed to streamline navigation functionality.

Changes

File(s) Change Summary
src/BlazorUI/Bit.BlazorUI.Extras/Components/AppShell/BitAppShell.razor.cs Implements IDisposable; adds private _disposed field; injects NavigationManager; introduces AutoGoToTop parameter; updates GoToTop to accept an optional BitScrollBehavior; subscribes to LocationChanged event; implements disposal logic.
src/BlazorUI/Bit.BlazorUI.Extras/Extensions/JsInterop/BitScrollBehavior.cs
src/BlazorUI/Bit.BlazorUI.Extras/Extensions/JsInterop/ExtrasJsRuntimeExtensions.cs
Adds new BitScrollBehavior enum with values Smooth, Instant, and Auto; updates BitExtrasGoToTop method signature to include an optional behavior parameter, passing it to the JS function call.
src/BlazorUI/Bit.BlazorUI.Extras/Scripts/Extras.ts Modifies goToTop method to accept an additional behavior parameter and pass it to scrollTo with both top and behavior properties.
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/AppShell/BitAppShellDemo.razor
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/AppShell/BitAppShellDemo.razor.cs
Adds new demo parameters: ComponentPublicMembers, ComponentSubEnums, and AutoGoToTop; introduces a component parameter for GoToTop and a new enum for scroll behaviors in the demo configuration.
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Shared/AppFooter.razor.cs Updates method call to AppShell.GoToTop by passing BitScrollBehavior.Instant explicitly.
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Shared/MainLayout.razor
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Shared/MainLayout.razor.cs
Adds AutoGoToTop attribute to <BitAppShell>; removes obsolete OnItemClick handler; introduces new auto-injected fields and subscriptions (e.g., for navigation and page title updates); removes HandleOnNavItemClick method.

Sequence Diagram(s)

sequenceDiagram
    participant NM as NavigationManager
    participant Shell as BitAppShell
    participant JS as JS Runtime / Extras
    Note over NM: Navigation event occurs
    NM->>Shell: Trigger LocationChanged event
    Shell->>Shell: Check AutoGoToTop setting
    Shell->>Shell: Invoke GoToTop(BitScrollBehavior.Instant)
    Shell->>JS: Call BitExtrasGoToTop(element, behavior)
    JS->>Browser: Execute scrollTo(top, behavior)
Loading

Assessment against linked issues

Objective Addressed Explanation
Automatically scroll to top on navigation (#9788)

Poem

I'm a rabbit with a joyful hop,
Scrolling to the top nonstop.
Code now leaps with auto-scroll beat,
Navigating swiftly, oh so neat.
With every change, I cheer and bound,
In joyful bytes, happiness is found!
🐰✨


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.

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)
src/BlazorUI/Bit.BlazorUI.Extras/Scripts/Extras.ts (1)

8-14: LGTM! Consider adding JSDoc comments.

The implementation correctly handles the scroll behavior parameter and uses modern TypeScript features.

Consider adding JSDoc comments to document the parameters and their purpose:

+       /**
+        * Scrolls the specified element to the top.
+        * @param element - The HTML element to scroll.
+        * @param behavior - Optional scroll behavior ('auto', 'smooth', or 'instant').
+        */
        public static goToTop(element: HTMLElement, behavior: ScrollBehavior | undefined) {
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/AppShell/BitAppShellDemo.razor.cs (1)

50-61: LGTM! Comprehensive scroll behavior implementation.

The changes introduce:

  • A flexible GoToTop method that accepts BitScrollBehavior
  • A well-documented BitScrollBehavior enum with appropriate scroll options

Consider adding examples in the documentation to demonstrate the usage of different scroll behaviors.

Also applies to: 154-183

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a226dab and 3ae2956.

📒 Files selected for processing (9)
  • src/BlazorUI/Bit.BlazorUI.Extras/Components/AppShell/BitAppShell.razor.cs (3 hunks)
  • src/BlazorUI/Bit.BlazorUI.Extras/Extensions/JsInterop/BitScrollBehavior.cs (1 hunks)
  • src/BlazorUI/Bit.BlazorUI.Extras/Extensions/JsInterop/ExtrasJsRuntimeExtensions.cs (1 hunks)
  • src/BlazorUI/Bit.BlazorUI.Extras/Scripts/Extras.ts (1 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/AppShell/BitAppShellDemo.razor (1 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/AppShell/BitAppShellDemo.razor.cs (3 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Shared/AppFooter.razor.cs (1 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Shared/MainLayout.razor (2 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Shared/MainLayout.razor.cs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build and test
🔇 Additional comments (17)
src/BlazorUI/Bit.BlazorUI.Extras/Components/AppShell/BitAppShell.razor.cs (9)

1-2: Using directive added.
This import is necessary for handling navigation events via LocationChangedEventArgs.


8-8: Implements IDisposable for proper resource management.
Adding IDisposable to the class is a good practice to ensure subscriptions are cleaned up.


10-10: Private disposal field.
Using _disposed is a standard approach to prevent multiple disposals.


14-16: Injected services.
These injection points look correct, and the usage of default! is acceptable for Blazor components.


19-22: New AutoGoToTop parameter.
The property name and documentation are consistent, providing a clear indication of its purpose.


46-51: GoToTop method.
This method cleanly delegates to _js.BitExtrasGoToTop, with an optional parameter for scroll behavior. No issues noticed.


67-76: Subscribing to LocationChanged conditionally.
This logic correctly wires up the event subscription based on the AutoGoToTop property. Good job remembering to unsubscribe later.


80-86: LocationChanged event handler.
Invoking GoToTop(BitScrollBehavior.Instant) upon navigation is a straightforward and effective approach.


90-106: Dispose pattern.
Properly unsubscribing from _navManager.LocationChanged and suppressing finalization is clean and avoids event leaks.

src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Shared/AppFooter.razor.cs (1)

12-12: Explicit scroll behavior.
Calling AppShell.GoToTop(BitScrollBehavior.Instant) aligns with the updated method signature and provides clear scroll behavior.

src/BlazorUI/Bit.BlazorUI.Extras/Extensions/JsInterop/BitScrollBehavior.cs (1)

1-22: New enum for scroll behavior.
The enum values and documentation are straightforward, offering clear scrolling options.

src/BlazorUI/Bit.BlazorUI.Extras/Extensions/JsInterop/ExtrasJsRuntimeExtensions.cs (1)

10-13: LGTM! Clean and consistent implementation.

The method signature and implementation correctly handle the optional scroll behavior parameter, with proper null handling and case conversion for JS interop.

src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Shared/MainLayout.razor (1)

3-3: LGTM! Verify navigation behavior.

The AutoGoToTop attribute has been correctly added to BitAppShell, and the removal of the OnItemClick handler suggests that navigation is now managed internally.

Please verify that:

  1. Navigation still works correctly without the OnItemClick handler
  2. The page automatically scrolls to top on navigation
  3. The scroll behavior is smooth and user-friendly
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/AppShell/BitAppShellDemo.razor (1)

11-13: LGTM! Documentation parameters added.

The addition of ComponentPublicMembers and ComponentSubEnums parameters enhances the demo's documentation by exposing the new scroll behavior functionality.

src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Shared/MainLayout.razor.cs (2)

14-17: LGTM! Dependencies are properly injected.

The new dependencies are correctly injected using [AutoInject] and initialized with default values.


25-45: LGTM! Robust error handling and event subscriptions.

The OnInitialized method now includes:

  • Proper error handling with try-catch
  • Navigation event subscription
  • Page title change subscription with async state updates
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/AppShell/BitAppShellDemo.razor.cs (1)

7-13: LGTM! AutoGoToTop parameter is well-documented.

The new parameter is properly defined with clear type, default value, and description, aligning with the PR objectives.

@msynk msynk merged commit 20b96a3 into bitfoundation:develop Feb 4, 2025
3 checks passed
@msynk msynk deleted the 9788-blazorui-appshell-autoscroll-to-top branch February 4, 2025 16:38
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.

The BitAppShell needs a new feature to automatically scroll to top on navigation
1 participant