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

TreeSelect: Can't use 'space' character in filter input #6749

Closed
InTheNooB opened this issue Jun 12, 2024 · 2 comments · Fixed by #6754 or leoo1992/GeradorQRCode#57 · May be fixed by nhattpn/BTL_LTNC#56
Closed

TreeSelect: Can't use 'space' character in filter input #6749

InTheNooB opened this issue Jun 12, 2024 · 2 comments · Fixed by #6754 or leoo1992/GeradorQRCode#57 · May be fixed by nhattpn/BTL_LTNC#56
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@InTheNooB
Copy link

InTheNooB commented Jun 12, 2024

Describe the bug

Pressing "space" in the filter input results in nothing happening.
This is because of the accessibility "feature" that calls event.preventDefault() on the onKeyDown if 'Space' is pressed, leading to the onChange that would update the input value not being triggered at all.

This wasn't an issue on the v8, but now is one (breaking change) in the latest v10.

Code responsible for this :

const onHeaderElementKeyDown = (event, isHideButton) => {
    switch (event.code) {
        case 'ArrowDown':
            event.preventDefault();
            setFocusToFocusableFirstNode();

            break;

        case 'ArrowUp':
            event.preventDefault();
            focusInputRef.current && DomHandler.focus(focusInputRef.current);

            break;

        case 'Space': // <----- Triggered before the onChange event
        case 'Enter':
        case 'NumpadEnter':
            event.preventDefault(); // <----- Prevents the onChange event from being triggered, prevent the usage of space char in the input field

            if (isHideButton) {
                hide();
            }

            break;

        case 'Escape':
            onEscapeKey(event);
            break;

        default:
            break;
    }
};

Link to this function :

const onHeaderElementKeyDown = (event, isHideButton) => {

This can be seen in the documentation itself, no need to create a project for this. In the example, there are options with spaces in them such as "Robert De Niro", but it is not possible to perform an exact search for them without spaces.
https://primereact.org/treeselect/#filter

Reproducer

https://primereact.org/treeselect/#filter

PrimeReact version

10.6.6

React version

18.x

Language

TypeScript

Build / Runtime

Vite

Browser(s)

No response

Steps to reproduce the behavior

  1. Create a <TreeSelect /> with options containing spaces and filtering enabled
  2. Try to type "space" character in the input field

Expected behavior

When pressing the spacebar, a space should be added in the filter input.
This would remove the usage of "space" as accessibility key, but "enter" would still do the same job and is usually more common to use than "space" to select anyway.

Allowing for spaces could also add the possibility of splicing words and perform searchs on all of them individually instead of looking for a perfect match with spaces, allowing for more flexibility in search results.

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

There's another 'Space' check on key down, and I don't know if this also has an impact on this issue.
Thought I would mention it here while you work on the issue @Rekl0w :

const onKeyDown = (event) => {

@Rekl0w
Copy link
Contributor

Rekl0w commented Jun 13, 2024

No, i tried it. It works now.

@melloware melloware added Type: Bug Issue contains a defect related to a specific component. and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Jun 13, 2024
@melloware melloware added this to the 10.7.0 milestone Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
3 participants