Skip to content

Suggestion menu omits aria-activedescendant for the first item #2926

Description

@pproenca

Affected version

@blocknote/react@0.52.1 and current main at dee7880b89b1e9bc00b4f4481f32652c7a4b4408.

Problem

Both SuggestionMenuWrapper and GridSuggestionMenuWrapper conditionally set
aria-activedescendant using the truthiness of selectedIndex. The initial
selected index is numeric 0, so the editor contenteditable omits the
attribute even though the first suggestion is selected.

Affected sources:

  • packages/react/src/components/SuggestionMenu/SuggestionMenuWrapper.tsx
  • packages/react/src/components/SuggestionMenu/GridSuggestionMenu/GridSuggestionMenuWrapper.tsx

Reproduction

  1. Mount BlockNoteViewRaw with the public SuggestionMenuController.
  2. Open a standard slash suggestion menu with at least one item.
  3. Inspect the editor contenteditable while the first item is selected.
  4. Repeat with the grid suggestion-menu wrapper.

The first item is visibly selected, but aria-activedescendant is absent.
Moving to index 1 makes the attribute appear.

Expected

aria-activedescendant="bn-suggestion-menu-item-0"

No selection should continue to omit the attribute.

Cause and minimal fix

The wrappers currently use a truthy check:

"aria-activedescendant": selectedIndex
  ? "bn-suggestion-menu-item-" + selectedIndex
  : undefined,

Use an explicit undefined check:

"aria-activedescendant":
  selectedIndex !== undefined
    ? "bn-suggestion-menu-item-" + selectedIndex
    : undefined,

Tests should cover first, middle, last, and no-selection states for both the
standard and grid wrappers.

This affects assistive technology because the active-option relation is
missing until keyboard navigation reaches a nonzero index.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions