Skip to content
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

pSelectableRow blocks typing space on inputs in p-table #15160

Closed
NexPlex opened this issue Mar 25, 2024 · 3 comments
Closed

pSelectableRow blocks typing space on inputs in p-table #15160

NexPlex opened this issue Mar 25, 2024 · 3 comments
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible

Comments

@NexPlex
Copy link

NexPlex commented Mar 25, 2024

Describe the bug

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

I used parth181195 fix for now

#9893

Environment

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

Reproducer

No response

Angular version

16.2.12

PrimeNG version

16.9.1

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

18.10.0

Browser(s)

No response

Steps to reproduce the behavior

Click on field will not take any spaces nor can I paste.

Expected behavior

Accept spaces and allow pasting

@NexPlex NexPlex added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Mar 25, 2024
@NexPlex
Copy link
Author

NexPlex commented Apr 15, 2024

I am using this code

@HostListener('keydown.space', ['$event'])
onSpaceKeyDown(event: KeyboardEvent & { target: HTMLInputElement}) {
// Prevent the default space key action

  const target = event.target;
  console.log('onSpaceKeyDown',  event, target);

  // Check if the target is an HTML input element and is inside a selectable row
  if (target.hasAttribute('pinputtext')) {
    console.log('Space key down inside pSelectableRow input');
    event.stopPropagation();
    event.preventDefault();
    const startPos = target.selectionStart;
    const endPos = target.selectionEnd;

     if (typeof startPos === 'number' && typeof endPos === 'number') {
       // Insert the space character at the current cursor position
       const originalText = target.value;
       const textBeforeCursor = originalText.substring(0, startPos);
       const textAfterCursor = originalText.substring(endPos, originalText.length);

       // Set the new value
       target.value = textBeforeCursor + ' ' + textAfterCursor;

       // Move the cursor position right after the inserted space
       const newCursorPos = startPos + 1;
       target.setSelectionRange(newCursorPos, newCursorPos);

       // Maintain focus on the input
       target.focus();

       // Append a space to the current value
       // target.value += ' ';
       // event.target['value'] = event.target['value'] + ' ';
       // (event.target as HTMLElement).focus();
     }
     } else {
    // If it's not the right type of element or not in the right context, stop the event propagation

  }
}

@LoganDupont
Copy link

This is also the case for a textarea in a tree. See #9893 (comment)

@mertsincan
Copy link
Member

Hi,

So sorry for the delayed response! Improvements have been made to many components recently, both in terms of performance and enhancement. Therefore, this improvement may have been developed in another issue ticket without realizing it. You can check this in the documentation and try the latest PrimeNG version(v19). If there is no improvement on this, can you open a new issue so we can include it in our roadmap?

Thanks a lot for your understanding!
Best Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible
Projects
None yet
Development

No branches or pull requests

3 participants