Skip to content

Commit ea03d52

Browse files
committed
Issue: #529
Fix: (shift) Enter/ Tab causes second focus rect. Fix: Enter, Tab and Escape are not working inside opened CellEditor.
1 parent ceb607e commit ea03d52

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

src/main/components/table/CellEditor.tsx

+9-6
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,14 @@ export const CellEditor: FC<ICellEditor> = (props) => {
206206
setEdit(false);
207207
stopEditing()
208208
if (event) {
209-
if (event.shiftKey) {
210-
focusTable = selectPrevious(event.key);
211-
}
212-
else {
213-
focusTable = selectNext(event.key);
209+
if (event.key !== 'Escape')
210+
{
211+
if (event.shiftKey) {
212+
focusTable = selectPrevious(event.key);
213+
}
214+
else {
215+
focusTable = selectNext(event.key);
216+
}
214217
}
215218
}
216219
else {
@@ -219,7 +222,7 @@ export const CellEditor: FC<ICellEditor> = (props) => {
219222
if (focusTable) {
220223
tableContainer.focus();
221224
}
222-
}, [setEdit, selectNext, selectPrevious]);
225+
}, [setEdit, selectNext, selectPrevious, tableContainer]);
223226

224227
/** Hook which detects if there was a click outside of the element (to close editor) */
225228
useOutsideClick(wrapperRef, () => {

src/main/components/table/UITable.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
width: 100%;
150150
}
151151

152-
&.p-selectable-row.p-highlight > td.p-selectable-cell.p-highlight, &.p-selectable-row.p-highlight > td.p-selectable-cell:focus {
152+
&.p-selectable-row.p-highlight > td.p-selectable-cell.p-highlight/*, &.p-selectable-row.p-highlight > td.p-selectable-cell:focus*/ {
153153
outline: none;
154154
outline-offset: 0;
155155
box-shadow: inset 0 0 0 2px #7f7f7f;

src/main/components/table/UITable.tsx

+22-9
Original file line numberDiff line numberDiff line change
@@ -957,11 +957,12 @@ const UITable: FC<TableProps & IExtendableTable & IComponentConstants> = (props)
957957
return selectNextCell(true);
958958
}
959959
else if (navigationMode === Navigation.NAVIGATION_ROW_AND_FOCUS) {
960-
selectNextRow(true);
960+
return selectNextRow(true);
961961
}
962962
else if (navigationMode === Navigation.NAVIGATION_CELL_AND_ROW_AND_FOCUS) {
963-
selectNextCellAndRow(true);
963+
return selectNextCellAndRow(true);
964964
}
965+
return true;
965966
}
966967
}, [selectNextCell, selectNextRow, selectNextCellAndRow]);
967968

@@ -972,20 +973,31 @@ const UITable: FC<TableProps & IExtendableTable & IComponentConstants> = (props)
972973
useEffect(() => {
973974
selectPrevious.current = (navigationMode:number, row?:any) => {
974975
if (navigationMode === Navigation.NAVIGATION_CELL_AND_FOCUS) {
975-
selectPreviousCell(true);
976+
return selectPreviousCell(true);
976977
}
977978
else if (navigationMode === Navigation.NAVIGATION_ROW_AND_FOCUS) {
978-
selectPreviousRow(true);
979+
return selectPreviousRow(true);
979980
}
980981
else if (navigationMode === Navigation.NAVIGATION_CELL_AND_ROW_AND_FOCUS) {
981-
selectPreviousCellAndRow(true)
982+
return selectPreviousCellAndRow(true);
982983
}
984+
return true;
983985
}
984986
}, [selectPreviousCell, selectPreviousRow, selectPreviousCellAndRow]);
985987

986-
const selectNextCallback = useCallback((key: string) => selectNext.current && selectNext.current(key === "Enter" ? props.enterNavigationMode : props.tabNavigationMode), [selectNext.current, props.enterNavigationMode, props.tabNavigationMode]);
988+
const selectNextCallback = useCallback((key: string) => {
989+
if (selectNext.current) {
990+
return selectNext.current(key === "Enter" ? enterNavigationMode : tabNavigationMode);
991+
}
992+
return true;
993+
}, [selectNext.current, enterNavigationMode, tabNavigationMode]);
987994

988-
const selectPreviousCallback = useCallback((key: string) => selectPrevious.current && selectPrevious.current(key === "Enter" ? props.enterNavigationMode : props.tabNavigationMode), [selectPrevious.current, props.enterNavigationMode, props.tabNavigationMode]);
995+
const selectPreviousCallback = useCallback((key: string) => {
996+
if (selectPrevious.current) {
997+
return selectPrevious.current(key === "Enter" ? enterNavigationMode : tabNavigationMode);
998+
}
999+
return true;
1000+
}, [selectPrevious.current, enterNavigationMode, tabNavigationMode]);
9891001

9901002
/** Building the columns */
9911003
const CellBody = useMemo(() => {
@@ -1040,7 +1052,7 @@ const UITable: FC<TableProps & IExtendableTable & IComponentConstants> = (props)
10401052
cellReadOnly={rowData.__recordReadOnly && rowData.__recordReadOnly}
10411053
resource={props.context.server.RESOURCE_URL}
10421054
cellId={props.id + "-" + tableInfo.rowIndex.toString() + "-" + colIndex.toString()}
1043-
tableContainer={props.forwardedRef.current ? props.forwardedRef.current : undefined}
1055+
tableContainer={props.forwardedRef.current}
10441056
selectNext={selectNextCallback}
10451057
selectPrevious={selectPreviousCallback}
10461058
className={className}
@@ -1106,7 +1118,8 @@ const UITable: FC<TableProps & IExtendableTable & IComponentConstants> = (props)
11061118
props.dataBook,
11071119
setMeasureFlag,
11081120
providerData,
1109-
props.startEditing
1121+
props.startEditing,
1122+
props.forwardedRef.current
11101123
])
11111124

11121125
const columns = useMemo(() => {

0 commit comments

Comments
 (0)