igniteui-angular icon indicating copy to clipboard operation
igniteui-angular copied to clipboard

igx-grid - can't handle keydown events for navigation keys when binding keydown to igx-grid level.

Open tkiryu opened this issue 7 years ago • 6 comments

Description

We can't handle keydown events for navigation keys when binding keydown to igx-grid level.

For example, we implement like this, we can handle keydown events for almost all the keys but we can't do for navigation keys like arrow up/right/down/left, tab, and so on.

<igx-grid (keydown)="handleKeydown()">
</igx-grid>
  • igniteui-angular version: 7.1.0
  • browser: all

Steps to reproduce

  1. Go to https://stackblitz.com/edit/angular-6xxpgn-q52ml6
  2. Open the console.
  3. Click a cell.
  4. Press navigation keys such as arrow up/right/down/left, tab, and so on.

Result

Console logs for navigation keys are not output.

Expected result

We should be able to handle keydown events for navigation keys as well.

Attachments

https://stackblitz.com/edit/angular-6xxpgn-q52ml6

tkiryu avatar Dec 20 '18 00:12 tkiryu

It seems that this issue is due to the following code. https://github.com/IgniteUI/igniteui-angular/blob/master/projects/igniteui-angular/src/lib/grids/grid-base.component.ts#L2229

    private keydownHandler(event) {
        const key = event.key.toLowerCase();
        if ((isNavigationKey(key) && event.keyCode !== 32) || key === 'tab' || key === 'pagedown' || key === 'pageup') {
            event.preventDefault();

Do you know why event.preventDefault(); is necessary?

tkiryu avatar Dec 20 '18 01:12 tkiryu

@tkiryu, thank you for reporting this issue. From what I see the preventing of the default behavior of these events is connected to the virtualization of the grid. @ddincheva could shed more light on this once she gets back after New Year.

tiliev avatar Dec 20 '18 13:12 tiliev

@tiliev , thank you for looking into it! OK, I'm waiting.

tkiryu avatar Dec 21 '18 03:12 tkiryu

Hello @tkiryu , actually you are experiencing this issue not because of the code snippet you mentioned above, but about the fact that the cell component handles the 'keydown' event and stop its propagation, so the event does not bubbles to the grid component. This is necessary due to the keyboard navigation functionality that the igx-grid provides, and the specifics of its implementation. So can you explain your use case in more details why it is necessary to handle this event and we will try to provide some sort of solution.

ddincheva avatar Jan 10 '19 09:01 ddincheva

@tkiryu, we do not consider this behavior as a bug in the igxGrid component, our keyboard navigation functionality depends on preventing some keydown bubbling events, and currently this is not something that is going to change. If we do not prevent the bubbling, a lot of issues will be exposed, for scenarios like - continues press scrolling, chunk loading, cell editing commits, and kb navigation through summary and tree grid elements. This should answer your question "Do you know why event.preventDefault(); is necessary?"

We plan to expose more rich API in the future that can cover customer needs like, custom keyboard navigation. This API will include more methods/events that could be used for different scenarios.

zdrawku avatar Feb 26 '19 15:02 zdrawku

Could it be possible though to include key modifiers in the check as to not intercept those event. Ie: My app uses the shortcut Ctrl + Alt + arrow for navigation and this no longer works as soon as the grid is focused.

Poseclop avatar May 27 '26 07:05 Poseclop