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

Dropdown: keyboard navigation doesn't scroll items list into view #6123

Closed
hitosu opened this issue Mar 9, 2024 · 4 comments · Fixed by #6452 or leoo1992/GeradorQRCode#23
Closed
Assignees
Labels
Component: Accessibility Issue or pull request is related to WCAG or ARIA Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@hitosu
Copy link

hitosu commented Mar 9, 2024

Describe the bug

When using keyboard navigation on Dropdown list with selectOnFocus prop set to false (default value, prop is missing from .d.ts BTW) - focused item is not scrolled into view.

Reproducer

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

PrimeReact version

10.5.1

React version

17.x

Language

TypeScript

Build / Runtime

Create React App (CRA)

Browser(s)

No response

Steps to reproduce the behavior

  1. Open Dropdown with scrollable items list.
  2. Press ArrowDown several times until focused item is hidden below.

Expected behavior

List should be scrolled into view when focused items changed.

This could be fixed with selecting data-p-focused="true" first:

        const scrollInView = () => {
            const focusedItem = DomHandler.findSingle(overlayRef.current, 'li[data-p-focused="true"]');

            if (focusedItem && focusedItem.scrollIntoView) {
                focusedItem.scrollIntoView({ block: 'nearest', inline: 'nearest' });
            } else {
                const highlightItem = DomHandler.findSingle(overlayRef.current, 'li[data-p-highlight="true"]');

                if (highlightItem && highlightItem.scrollIntoView) {
                    highlightItem.scrollIntoView({ block: 'nearest', inline: 'nearest' });
                }
            }
        };

And adding focusedOptionIndex into useUpdateEffect:

        useUpdateEffect(() => {
            if (overlayVisibleState && (props.value || -1 < focusedOptionIndex)) {
                scrollInView();
            }
        }, [overlayVisibleState, props.value, focusedOptionIndex]);
@hitosu hitosu 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 9, 2024
@melloware melloware added Component: Accessibility Issue or pull request is related to WCAG or ARIA and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Mar 9, 2024
@melloware
Copy link
Member

@hitosu can you submit a PR?

@hitosu
Copy link
Author

hitosu commented Mar 9, 2024

@melloware I would love to contribute directly, but I still checking if I'm able to (from the legal perspective). Commenting with code is ok.

@endygomez
Copy link

I have the same problem.

@melloware melloware self-assigned this Apr 23, 2024
@melloware melloware added this to the 10.6.4 milestone Apr 23, 2024
melloware added a commit to melloware/primereact that referenced this issue Apr 23, 2024
@melloware
Copy link
Member

PR submitted

nitrogenous added a commit that referenced this issue Apr 29, 2024
Fix #6123: Dropdown scroll into view on focus
@nitrogenous nitrogenous added the Type: Bug Issue contains a defect related to a specific component. label Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Accessibility Issue or pull request is related to WCAG or ARIA Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
4 participants