Skip to content

spaceCatcher causes null-access #49

@subITCSS

Description

@subITCSS

Describe the bug

We get the following error tracked via Sentry:
can't access property "getAttribute", this.shadowRoot.activeElement is null

which is caused by that code:

_spaceCatcher: function (e) {
    e.preventDefault();
    if (this.shadowRoot != null) {
      var nextPos = this.shadowRoot.activeElement.getAttribute('aria-posinset');
    } else {
      var nextPos = document.activeElement.getAttribute('aria-posinset');
    }
    if (!nextPos)
      return;
    this.movePos(nextPos);
  },

Expected behavior

The code should be able to handle such state.

_spaceCatcher: function (e) {
    e.preventDefault();

    const root = this.shadowRoot || document;
    const activeEl = root.activeElement;

    if (!activeEl) return;

    const nextPosAttr = activeEl.getAttribute('aria-posinset');
    if (!nextPosAttr) return;

    const nextPos = parseInt(nextPosAttr, 10);
    if (Number.isNaN(nextPos)) return;

    this.movePos(nextPos - 1);
  },

Minimal reproducible example

No response

Add-on Version

3.0.1

Vaadin Version

24.10.1

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    To Do

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions