Skip to content

Update keyboard navigation topic for React 19 #1515

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

Merged
merged 4 commits into from
May 30, 2025
Merged
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
36 changes: 22 additions & 14 deletions doc/en/components/grids/_shared/keyboard-navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,41 +197,46 @@ igRegisterScript("WebGridCustomKBNav", (evtArgs) => {
```

```tsx
<{ComponentSelector} id="grid1" primaryKey="ProductID" gridKeydown={customKeydown}>
<{ComponentSelector} id="grid1" primaryKey="ProductID" onGridKeydown={customKeydown}>
</{ComponentSelector}>
```

<!-- WebComponents -->
```ts
constructor() {
var grid = this.grid = document.getElementById('grid') as {ComponentName}Component;
const grid = this.grid = document.getElementById('grid1') as {ComponentName}Component;
grid.data = this.data
grid.addEventListener("gridKeydown", this.customKeydown);
}
```
<!-- end: WebComponents -->

```typescript
function customKeydown(s: IgrGridBaseDirective, e: IgrGridKeydownEventArgs) {
const detail = e.detail
const target= detail.target;
const evt = detail.event;
const type = detail.targetType;
<!-- React -->

```tsx
const customKeydown = (eventArgs: IgrGridKeydownEventArgs) => {
const args = eventArgs.detail;
const target= args.target;
const evt = args.event;
const type = args.targetType;

if (type === GridKeydownTargetType.DataCell && target.editMode && evt.key.toLowerCase() === 'tab') {
if (type === 'dataCell' && target.editMode && evt.key.toLowerCase() === 'tab') {
// 1. USER INPUT VALIDATION ON TAB

}
if (type === GridKeydownTargetType.DataCell && evt.key.toLowerCase() === 'enter') {
if (type === 'dataCell' && evt.key.toLowerCase() === 'enter') {
// 2. CUSTOM NAVIGATION ON ENTER KEY PRESS

}
}
```

<!-- end: React -->

<!-- WebComponents -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested this snippet in WC? I dont think this would work since you are casting the target to IgxGridCell


```typescript
public customKeydown(args: any) {
public customKeydown(args: : CustomEvent<IgcGridKeydownEventArgs>) {
const evt = args.detail;
const target: IgxGridCell = evt.target as IgxGridCell;
const target = evt.target as IgcCellType;
const evt: KeyboardEvent = evt.event as KeyboardEvent;
const type = evt.targetType;

Expand All @@ -243,6 +248,9 @@ public customKeydown(args: any) {
}
}
```

<!-- WebComponents -->

<!-- Angular, WebComponents, Blazor -->

Based on the event arg values we identified two cases, where to provide our own logic (see above). Now, using the methods from the API, let's perform the desired - if the user is pressing <kbd>Tab</kbd> key over a cell in edit mode, we will perform validation on the input. If the user is pressing <kbd>Enter</kbd> key over a cell, we will move focus to cell in the next row:
Expand Down