pSelectableRow blocks typing space on inputs in p-table
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]
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?
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)
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();
}
}
#14127 re-introduces this bug with commit d6a22d6ce8f1100ec39cc0ba2c3375627f5177df
Ran into this issue. Had to implement workaround provided above. Please reopen the issue.
can confirm this is a big issue! setting [pSelectableRow]="rowData" and [pSelectableRowIndex]="rowIndex" also gives that faulty behavior
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",
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.
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.
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();
}
}