swimlane / ngx-datatable

✨ A feature-rich yet lightweight data-table crafted for Angular
http://swimlane.github.io/ngx-datatable/
MIT License
4.63k stars 1.68k forks source link

Inline editing autofocus doesn't work #1887

Open ady-ghe opened 4 years ago

ady-ghe commented 4 years ago

I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, post on Stackoverflow or Gitter

Current behavior

I double clicked on a field, the edit inline appears but the autofocus isn't working, even if the "autofocus" attribute is there. You have to click again on the input to start editing value.

Expected behavior

After doubleclick, the inline input field should have the focus on, so you don't have to click again.

Reproduction of the problem

just use your online demo: https://swimlane.github.io/ngx-datatable/#inline-edit

What is the motivation / use case for changing the behavior?

Please tell us about your environment:

latest Google Chrome on Windows 10

nidhin038 commented 4 years ago

This seems to be open for 4 months. Is someone looking into this issue? This is creating a lot of other issues.

carrbrpoa commented 4 years ago

Not ideal, but did a workaround for this, with the `activate´ event of the table. Something like:

<ngx-datatable [rows]="rows" class="bootstrap"
    (activate)="onActivate($event)"
    ...
onActivate(event) {
    if (event.type = 'dblclick' && event.cellElement) {
        const input: HTMLInputElement = event.cellElement.childNodes[0].children[0] as HTMLInputElement;
        input.focus();
        // input.select();
    }
}

Reference for focus: https://stackoverflow.com/a/51324147/643416

topalavlad commented 3 years ago

autofocus is only applied once on page load. For auto focusing components that are shown/hidden, an explicit focus() call is required

The autofocus content attribute allows the author to indicate that a control is to be focused as soon as the page is loaded or as soon as the dialog within which it finds itself is shown, allowing the user to just start typing without having to manually focus the main control.

I already tried creating an autofocus directive and it works for both input field and select. Does anyone have any concerns about this approach?