Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table : update edit mode tab to navigate #2870

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export class ModusTableCellEditor {
size="large"
show-calendar-icon="true"
value={this.value as string}
onBlur={this.handleBlur}
onValueChange={(e: CustomEvent<ModusDateInputEventDetails>) => {
this.editedValue = e.detail[valueKey];
}}></modus-date-input>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
KEYBOARD_ENTER,
KEYBOARD_ESCAPE,
COLUMN_DEF_DATATYPE_BADGE,
KEYBOARD_TAB,
} from '../../../modus-table.constants';
import NavigateTableCells from '../../../utilities/table-cell-navigation.utility';
import { CellFormatter } from '../../../utilities/table-cell-formatter.utility';
Expand Down Expand Up @@ -168,10 +169,29 @@

const key = event.key?.toLowerCase();
const isCellEditable = this.cell.column.columnDef[this.cellEditableKey];

if (isCellEditable && !this.editMode && key === KEYBOARD_ENTER) {
this.editMode = true;
event.stopPropagation();
} else if (isCellEditable && this.editMode && key === KEYBOARD_TAB) {
const isShiftPressed = event.shiftKey;
NavigateTableCells({
eventKey: isShiftPressed ? 'shift+tab' : event.key,
cellElement: this.cellEl,
isCellEditable: isCellEditable,
onNavigateComplete: (cellElement) => {
if (cellElement) {
cellElement.focus();
const cellComponent = cellElement;
if (cellComponent) {
(cellComponent as any).componentOnReady().then((componentInstance) => {

Check warning on line 186 in stencil-workspace/src/components/modus-table/parts/cell/modus-table-cell-main/modus-table-cell-main.tsx

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
const nextRowIndex = componentInstance.cell.row.index.toString();
const nextColumnId = componentInstance.cell.column.id;
componentInstance.handleCellEdit(nextRowIndex, nextColumnId);
});
}
}
},
});
} else {
NavigateTableCells({
eventKey: event.key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ import {
KEYBOARD_ESCAPE,
KEYBOARD_LEFT,
KEYBOARD_RIGHT,
KEYBOARD_TAB,
KEYBOARD_UP,
} from '../modus-table.constants';

interface NavigateTableCellsProps {
eventKey: string;
cellElement: HTMLElement;
isCellEditable?: boolean;
onNavigateComplete?: (cell: HTMLElement) => void;
}
export default function NavigateTableCells(props: NavigateTableCellsProps) {
const { eventKey: key, cellElement: cell } = props;
let nextCell: HTMLElement;

const { eventKey: key, cellElement: cell, onNavigateComplete, isCellEditable } = props;
let nextCell, prevCell: HTMLElement;
const row = cell.closest('tr') as HTMLTableRowElement;
const index = Array.prototype.indexOf.call(row.children, cell);

Expand All @@ -28,6 +30,20 @@ export default function NavigateTableCells(props: NavigateTableCellsProps) {
case KEYBOARD_ESCAPE: // Pressing Escape does nothing but to retain the focus
cell.focus();
break;
case 'shift+tab':
prevCell =
((cell.previousSibling as HTMLElement)?.querySelector('modus-table-cell-main') as HTMLElement) ||
((row.previousSibling?.lastChild as HTMLElement)?.querySelector('modus-table-cell-main') as HTMLElement);

if (prevCell && isCellEditable) onNavigateComplete(prevCell);
break;
case KEYBOARD_TAB:
nextCell =
((cell.nextSibling as HTMLElement)?.querySelector('modus-table-cell-main') as HTMLElement) ||
((row.nextSibling as HTMLElement)?.querySelector('modus-table-cell-main') as HTMLElement);

if (nextCell && isCellEditable) onNavigateComplete(nextCell);
break;
case KEYBOARD_RIGHT: // Moves to right cell
nextCell = cell.nextSibling as HTMLElement;
nextCell?.focus();
Expand Down
Loading