Skip to content

Conversation

@momijijin
Copy link
Collaborator

@momijijin momijijin commented Jun 17, 2025

Link issues

fixes #6243

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Add enhanced keyboard navigation for IP address input fields and improve segment handling by defaulting empty segments to zero and stripping spaces.

New Features:

  • Allow Space or ArrowRight at end of a segment to move focus to the next segment
  • Allow ArrowLeft at start of a segment to move focus to the previous segment
  • Extend Backspace behavior to reset empty or single-character segments to zero and shift focus backward

Bug Fixes:

  • Default empty IP segments to "0" when initializing input values
  • Remove all spaces from the concatenated IP string before updating the model

@momijijin momijijin linked an issue Jun 17, 2025 that may be closed by this pull request
1 task
@bb-auto
Copy link

bb-auto bot commented Jun 17, 2025

Thanks for your PR, @momijijin. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jun 17, 2025

Reviewer's Guide

This PR enhances the IpAddress component by expanding keyboard-driven navigation between IP segment inputs (supporting Space, ArrowLeft, ArrowRight, and refined Backspace behavior) and improves input sanitization by defaulting blank segments to "0" and stripping spaces on update.

Class diagram for updated IpAddress component input handling

classDiagram
    class IpAddress {
        string Value1
        string Value2
        string Value3
        string Value4
        void OnParametersSet()
        void UpdateValue()
    }
    IpAddress : OnParametersSet() sets Value1-4 to "0" if blank/whitespace
    IpAddress : UpdateValue() strips all spaces from concatenated IP string
Loading

File-Level Changes

Change Details Files
Enhance keyboard navigation in the IpAddress component
  • Capture current input element for accurate cursor position checks
  • Move focus to next or previous segment on Space, ArrowRight, and ArrowLeft when caret is at input boundaries
  • Refine Backspace handling to default empty or single‐character cells to "0" and shift focus backward
src/BootstrapBlazor/Components/IpAddress/IpAddress.razor.js
Improve IP segment defaulting and sanitization logic
  • Default blank or whitespace-only segments to "0" when initializing values
  • Remove all spaces from the combined IP string on update
src/BootstrapBlazor/Components/IpAddress/IpAddress.razor.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#6243 Implement 'Space' and 'ArrowRight' key functionality to switch the cursor to the next cell when it reaches the end of the current cell content.
#6243 Implement 'ArrowLeft' key functionality to switch the cursor to the previous cell when it reaches the start of the current cell content.
#6243 Implement 'Backspace' key functionality to add '0' and switch to the previous cell if the current cell will be emptied of all contents.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto bot requested a review from ArgoZhang June 17, 2025 03:22
@bb-auto bb-auto bot added the enhancement New feature or request label Jun 17, 2025
@bb-auto bb-auto bot added this to the 9.7.0 milestone Jun 17, 2025
sourcery-ai[bot]
sourcery-ai bot previously approved these changes Jun 17, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @momijijin - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor/Components/IpAddress/IpAddress.razor.js:55` </location>
<code_context>
             }
             else if (e.key === 'Backspace') {
-                if (c.value.length === 0) {
+                if (c.value.length <= 1) {
                     c.value = "0"
-                    selectCell(el, index - 1)
+                    if (index === 0)
+                        e.preventDefault();
+                    const prevCell = selectCell(el, index - 1)
+                    prevCell.selectionStart = prevCell.value.length
+                    prevCell.selectionEnd = prevCell.value.length
                 }
             }
</code_context>

<issue_to_address>
Guard against negative index when selecting previous cell

Add an `if (index > 0)` check before calling `selectCell(el, index - 1)` to prevent out-of-bounds access. Only call `e.preventDefault()` when `index` is 0.
</issue_to_address>

### Comment 2
<location> `src/BootstrapBlazor/Components/IpAddress/IpAddress.razor.js:64` </location>
<code_context>
+                    prevCell.selectionEnd = prevCell.value.length
                 }
             }
+            // 空格或右箭头(光标一定要在内容最后面)向后换一格
+            else if (current.selectionStart === current.value.length && (e.code === 'Space' || e.code === 'ArrowRight')) {
+                e.preventDefault()
</code_context>

<issue_to_address>
Prevent moving past last cell on ArrowRight or Space

Add a condition to ensure `index + 1` does not exceed `totalSegments - 1` to prevent selecting beyond the last cell.
</issue_to_address>

### Comment 3
<location> `src/BootstrapBlazor/Components/IpAddress/IpAddress.razor.js:70` </location>
<code_context>
+                selectCell(el, index + 1)
+            }
+            // 左箭头(光标一定要在内容最前面)向前换一格
+            else if (current.selectionStart === 0 && e.code === 'ArrowLeft') {
+                e.preventDefault()
+                selectCell(el, index - 1)
</code_context>

<issue_to_address>
Prevent moving before first cell on ArrowLeft

Wrap `selectCell(el, index - 1)` with `if (index > 0)` to prevent selecting an invalid cell.
</issue_to_address>

### Comment 4
<location> `src/BootstrapBlazor/Components/IpAddress/IpAddress.razor.js:74` </location>
<code_context>
+                e.preventDefault()
+                selectCell(el, index - 1)
+            }
             else if (e.key === 'Delete' || e.key === 'Tab' || e.key === 'ArrowLeft' || e.key === 'ArrowRight') {

             }
</code_context>

<issue_to_address>
Remove or clarify the redundant empty handler

This branch duplicates existing handlers and does nothing. Please remove it or add a clarifying comment if it's intentional.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Jun 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (863a208) to head (8f36653).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #6244   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          704       704           
  Lines        31130     31130           
  Branches      4402      4402           
=========================================
  Hits         31130     31130           
Flag Coverage Δ
BB 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@momijijin
Copy link
Collaborator Author

@microsoft-github-policy-service agree

… an extra character when switching to the previous cell.
@ArgoZhang ArgoZhang changed the title feat(IpAddress): add keydownEvent.code ['Space','ArrowLeft','ArrowRight','Backspace'] expansion operations feat(IpAddress): support ArrowLeft/Right key Jun 17, 2025
@bb-auto bb-auto bot unassigned momijijin Jun 17, 2025
@ArgoZhang ArgoZhang merged commit e6c8012 into main Jun 17, 2025
6 checks passed
@ArgoZhang ArgoZhang deleted the 6243-featipaddress-add-keydowneventcode-spacearrowleftarrowrightbackspace-expansion-operations branch June 17, 2025 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(IpAddress): support ArrowLeft/Right key

3 participants