@@ -26,6 +26,9 @@ import { renderTNodeJSX, useElementLazyRender } from '../hooks';
2626import useStyle , { formatCSSUnit } from './hooks/useStyle' ;
2727import useClassName from './hooks/useClassName' ;
2828import { useConfig } from '../config-provider/useConfig' ;
29+ import { useRowHighlight } from './hooks/useRowHighlight' ;
30+ import useHoverKeyboardEvent from './hooks/useHoverKeyboardEvent' ;
31+
2932import { Affix } from '../affix' ;
3033import { ROW_LISTENERS } from './tr' ;
3134import THead from './thead' ;
@@ -157,6 +160,7 @@ export default defineComponent({
157160 [ tableColFixedClasses . leftShadow ] : showColumnShadow . left ,
158161 [ tableColFixedClasses . rightShadow ] : showColumnShadow . right ,
159162 [ tableBaseClass . columnResizableTable ] : props . resizable ,
163+ [ `${ classPrefix } -table__row--active-${ props . activeRowType } ` ] : props . activeRowType ,
160164 } ,
161165 ] ) ;
162166
@@ -177,6 +181,19 @@ export default defineComponent({
177181
178182 const columnResizable = computed ( ( ) => props . allowResizeColumnWidth ?? props . resizable ) ;
179183
184+ // 行高亮
185+ const {
186+ tActiveRow, onHighlightRow, addHighlightKeyboardListener, removeHighlightKeyboardListener,
187+ } = useRowHighlight ( props , tableRef ) ;
188+
189+ const {
190+ hoverRow,
191+ needKeyboardRowHover,
192+ clearHoverRow,
193+ addRowHoverKeyboardListener,
194+ removeRowHoverKeyboardListener,
195+ } = useHoverKeyboardEvent ( props , tableRef ) ;
196+
180197 watch ( tableElmRef , ( ) => {
181198 setUseFixedTableElmRef ( tableElmRef . value ) ;
182199 } ) ;
@@ -276,6 +293,22 @@ export default defineComponent({
276293 addTableResizeObserver ( tableRef . value ) ;
277294 } ) ;
278295
296+ const onTableFocus = ( ) => {
297+ props . activeRowType && addHighlightKeyboardListener ( ) ;
298+ needKeyboardRowHover . value && addRowHoverKeyboardListener ( ) ;
299+ } ;
300+
301+ const onTableBlur = ( ) => {
302+ props . activeRowType && removeHighlightKeyboardListener ( ) ;
303+ needKeyboardRowHover . value && removeRowHoverKeyboardListener ( ) ;
304+ } ;
305+
306+ const onInnerRowClick : BaseTableProps [ 'onRowClick' ] = ( ctx ) => {
307+ props . onRowClick ?.( ctx ) ;
308+ props . activeRowType && onHighlightRow ( ctx ) ;
309+ needKeyboardRowHover . value && clearHoverRow ( ) ;
310+ } ;
311+
279312 const tableData = computed ( ( ) => ( isPaginateData . value ? dataSource . value : props . data ) ) ;
280313
281314 const scrollToElement = ( params : ComponentScrollToElementParams ) => {
@@ -349,6 +382,8 @@ export default defineComponent({
349382 horizontalScrollbarRef,
350383 tableBodyRef,
351384 showAffixPagination,
385+ tActiveRow,
386+ hoverRow,
352387 showElement,
353388 getListener,
354389 renderPagination,
@@ -358,6 +393,9 @@ export default defineComponent({
358393 refreshTable,
359394 onInnerVirtualScroll,
360395 scrollColumnIntoView,
396+ onTableFocus,
397+ onTableBlur,
398+ onInnerRowClick,
361399 paginationAffixRef,
362400 horizontalScrollAffixRef,
363401 headerTopAffixRef,
@@ -576,6 +614,9 @@ export default defineComponent({
576614 // 内部使用分页信息必须取 innerPagination
577615 pagination : this . innerPagination ,
578616 attach : this . attach ,
617+ hoverRow : this . hoverRow ,
618+ activeRow : this . tActiveRow ,
619+ onRowClick : this . onInnerRowClick ,
579620 } ;
580621 // Vue3 do not need getListener
581622 const tBodyListener = this . getListener ( ) ;
@@ -650,7 +691,13 @@ export default defineComponent({
650691 ) ;
651692
652693 return (
653- < div ref = "tableRef" class = { this . dynamicBaseTableClasses } style = "position: relative" >
694+ < div
695+ ref = "tableRef"
696+ tabindex = "0"
697+ class = { this . dynamicBaseTableClasses }
698+ onFocus = { this . onTableFocus }
699+ onBlur = { this . onTableBlur }
700+ >
654701 { ! ! topContent && < div class = { this . tableBaseClass . topContent } > { topContent } </ div > }
655702
656703 { this . renderAffixedHeader ( columns ) }
0 commit comments