primeng icon indicating copy to clipboard operation
primeng copied to clipboard

pSelectableRow blocks typing space on inputs in p-table

Open jone30rw opened this issue 5 years ago • 10 comments

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

[x] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

Current behavior a row with pSelectableRow (<tr [pSelectableRow]="...">) blocks inputs from typing whitespace.

Expected behavior We should be able to type whitespace in the inputs.

Minimal reproduction of the problem with instructions https://codesandbox.io/s/lucid-shirley-53rlx?file=/src/app/app.component.html:233-247

The textarea will ignore the whitespace typed by the keyboard.

  • Angular version: 11.2.0
  • PrimeNG version: 11.2.1
  • Browser: [Chrome 88.0.4324.150 | Firefox 85.0.2 | not tested others]

jone30rw avatar Feb 13 '21 14:02 jone30rw

I have reviewed the pSelectableRow directive. There is an event listener that cause this.

@HostListener('keydown.space', ['$event'])
onSpaceKeyDown(event: KeyboardEvent) {
    event.preventDefault();
}

can someone describe, why such a listener is needed?

jone30rw avatar Feb 13 '21 14:02 jone30rw

a temporary fix can be the using (keydown.space)="$event.stopPropagation();" on text inputs. but this is not feasible for inputs in 3rd party components (e.g: filter input on p-dropdown)

jone30rw avatar Feb 13 '21 14:02 jone30rw

for some one looking for quick way to fix this and add space to inputs u can override this with this snippet

    @HostListener('keydown.space', ['$event'])
    onSpaceKeyDown(event: KeyboardEvent) {
        event.stopPropagation();
        event.preventDefault();
        if (event.target) {
            event.target['value'] = event.target['value'] + ' ';
            (event.target as HTMLElement).focus();
        }
    }

parth181195 avatar Jul 23 '21 17:07 parth181195

#14127 re-introduces this bug with commit d6a22d6ce8f1100ec39cc0ba2c3375627f5177df

philipp-doblhofer avatar Dec 12 '23 19:12 philipp-doblhofer

Ran into this issue. Had to implement workaround provided above. Please reopen the issue.

NagornovAlex avatar Jan 05 '24 13:01 NagornovAlex

can confirm this is a big issue! setting [pSelectableRow]="rowData" and [pSelectableRowIndex]="rowIndex" also gives that faulty behavior

Logic-Bits avatar Jan 24 '24 19:01 Logic-Bits

I too, have the same issue I used parth181195 fix for now

"primeng": "^16.9.1", "@angular/core": "16.2.12", "@angular/forms": "16.2.12",

NexPlex avatar Mar 25 '24 17:03 NexPlex

This also seems to be an issue with a text area inside a Tree caused by this commit https://github.com/primefaces/primeng/issues/14123. Looks like arrow keys, space, numpad enter and enter will all trigger a prevent default that will all break nested input/textarea elements.

ABryantdev avatar May 22 '24 14:05 ABryantdev

for some one looking for quick way to fix this and add space to inputs u can override this with this snippet

    @HostListener('keydown.space', ['$event'])
    onSpaceKeyDown(event: KeyboardEvent) {
        event.stopPropagation();
        event.preventDefault();
        if (event.target) {
            event.target['value'] = event.target['value'] + ' ';
            (event.target as HTMLElement).focus();
        }
    }

This doesn't work when you type a space between characters, it keeps adding space at the end.

saidsoualhi avatar Oct 23 '24 12:10 saidsoualhi

I encountered the same problem where spaces were being added only to the end of the input field. Here's my updated version of the code to correctly insert a space at the current cursor position:

@HostListener('keydown.space', ['$event'])
onSpaceKeyDown(event: KeyboardEvent) {
     event.stopPropagation();
     event.preventDefault();

    if (event.target && event.target instanceof HTMLInputElement) {
        const inputElement = event.target as HTMLInputElement;
        const cursorPos = inputElement.selectionStart ?? 0;

        const beforeCursor = inputElement.value.substring(0, cursorPos);
        const afterCursor = inputElement.value.substring(cursorPos);
        inputElement.value = beforeCursor + ' ' + afterCursor;

        const newCursorPos = cursorPos + 1;
        inputElement.setSelectionRange(newCursorPos, newCursorPos);

        inputElement.focus();
    }
}

stephenkjensen avatar Nov 20 '24 21:11 stephenkjensen