Skip to content

Commit 954db10

Browse files
fix(Table): fix default horizontal scroll behavior (Tencent#4904)
* fix(Table): fix default horizontal * fix(Table): fix default horizontal * fix(Table): fix default horizontal * chore: update common --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 3a90714 commit 954db10

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

src/table/base-table.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ export default defineComponent({
176176
clearHoverRow,
177177
addRowHoverKeyboardListener,
178178
removeRowHoverKeyboardListener,
179+
tableRefTabIndex,
179180
} = useHoverKeyboardEvent(props, tableRef);
180181

181182
watch(tableElmRef, () => {
@@ -394,6 +395,7 @@ export default defineComponent({
394395
horizontalScrollAffixRef,
395396
headerTopAffixRef,
396397
footerBottomAffixRef,
398+
tableRefTabIndex,
397399
};
398400
},
399401

@@ -714,7 +716,7 @@ export default defineComponent({
714716
return (
715717
<div
716718
ref="tableRef"
717-
tabindex="0"
719+
tabindex={this.tableRefTabIndex}
718720
class={this.dynamicBaseTableClasses}
719721
onFocus={this.onTableFocus}
720722
onBlur={this.onTableBlur}

src/table/hooks/useHoverKeyboardEvent.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@ import { toRefs, Ref, ref, computed } from 'vue';
22
import get from 'lodash/get';
33
import { BaseTableProps } from '../interface';
44
import { on, off } from '../../utils/dom';
5-
import { ALL_REG, ARROW_DOWN_REG, ARROW_UP_REG, CLEAR_REG, ESCAPE_REG, SPACE_REG } from '../../_common/js/common';
5+
import {
6+
ALL_REG,
7+
ARROW_DOWN_REG,
8+
ARROW_UP_REG,
9+
CLEAR_REG,
10+
ESCAPE_REG,
11+
SPACE_REG,
12+
ARROW_LEFT_REG,
13+
ARROW_RIGHT_REG,
14+
} from '../../_common/js/common';
615
import { RowEventContext, TableRowData } from '../type';
716

817
/**
@@ -13,6 +22,7 @@ export function useHoverKeyboardEvent(props: BaseTableProps, tableRef: Ref<HTMLD
1322
const { hover, data, activeRowType, keyboardRowHover, disableSpaceInactiveRow } = toRefs(props);
1423
const hoverRow = ref<string | number>();
1524
const currentHoverRowIndex = ref(-1);
25+
const tableRefTabIndex = ref(0);
1626

1727
// 单行高亮场景,不需要键盘悬浮效果
1828
const needKeyboardRowHover = computed(() => {
@@ -67,6 +77,13 @@ export function useHoverKeyboardEvent(props: BaseTableProps, tableRef: Ref<HTMLD
6777
} else if (CLEAR_REG.test(code) && !props.activeRowType) {
6878
props.onActiveRowAction?.({ action: 'clear', activeRowList: [] });
6979
}
80+
81+
// 用于支持键盘默认的左右滚动,左右滚动时重置为undefined,其他情况下为0,支持键盘操作
82+
if (ARROW_LEFT_REG.test(code) || ARROW_RIGHT_REG.test(code)) {
83+
tableRefTabIndex.value = undefined;
84+
} else {
85+
tableRefTabIndex.value = 0;
86+
}
7087
};
7188

7289
const addRowHoverKeyboardListener = () => {
@@ -83,6 +100,7 @@ export function useHoverKeyboardEvent(props: BaseTableProps, tableRef: Ref<HTMLD
83100
clearHoverRow,
84101
addRowHoverKeyboardListener,
85102
removeRowHoverKeyboardListener,
103+
tableRefTabIndex,
86104
};
87105
}
88106

src/table/hooks/useRowHighlight.ts

+1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ export function useRowHighlight(props: BaseTableProps, tableRef: Ref<HTMLDivElem
164164

165165
const keyboardDownListener = (e: KeyboardEvent) => {
166166
const code = e.code || e.key?.trim();
167+
167168
if (ARROW_DOWN_REG.test(code)) {
168169
e.preventDefault();
169170
const index = Math.min(data.value.length - 1, currentOperationRowIndex.value + 1);

0 commit comments

Comments
 (0)