Skip to content

Commit 46b08a3

Browse files
authored
fix(Table): stuck search form-control when press keyup/keydown when IsExcel mode (dotnetcore#5826)
* refactor: 增加调用函数保护 * refactor: 增加控件搜索范围 * refactor: 更正行搜索逻辑 * chore: bump version 9.5.6
1 parent 698666c commit 46b08a3

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.5.6-beta05</Version>
4+
<Version>9.5.6</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/Table/Table.razor.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -389,15 +389,19 @@ const setExcelKeyboardListener = table => {
389389
const setFocus = target => {
390390
const handler = setTimeout(function () {
391391
clearTimeout(handler);
392-
target.focus();
393-
target.select();
392+
if (target.focus) {
393+
target.focus();
394+
}
395+
if (target.select) {
396+
target.select();
397+
}
394398
}, 10);
395399
}
396400

397401
const activeCell = (cells, index) => {
398402
let ret = false;
399403
const td = cells[index];
400-
const target = td.querySelector('input.form-control:not([readonly])');
404+
const target = td.querySelector('.form-control:not([readonly])');
401405
if (target) {
402406
setFocus(target);
403407
ret = true;
@@ -425,22 +429,30 @@ const setExcelKeyboardListener = table => {
425429
}
426430
}
427431
else if (keyCode === KeyCodes.UP_ARROW) {
428-
cells = tr.previousElementSibling && tr.previousElementSibling.children;
429-
if (cells) {
430-
while (index < cells.length) {
432+
let nextRow = tr.previousElementSibling;
433+
while (nextRow) {
434+
cells = nextRow.children;
435+
if (cells) {
431436
if (activeCell(cells, index)) {
432437
break;
433438
}
439+
else {
440+
nextRow = nextRow.previousElementSibling;
441+
}
434442
}
435443
}
436444
}
437445
else if (keyCode === KeyCodes.DOWN_ARROW) {
438-
cells = tr.nextElementSibling && tr.nextElementSibling.children;
439-
if (cells) {
440-
while (index < cells.length) {
446+
let nextRow = tr.nextElementSibling;
447+
while (nextRow) {
448+
cells = nextRow.children;
449+
if (cells) {
441450
if (activeCell(cells, index)) {
442451
break;
443452
}
453+
else {
454+
nextRow = nextRow.nextElementSibling;
455+
}
444456
}
445457
}
446458
}

0 commit comments

Comments
 (0)