Skip to content

Conversation

HIRANO-Satoshi
Copy link

This fixes the following error when focusedIndex=-1 and the Enter key is pressed on a dropdown.

Cannot read properties of undefined (reading 'querySelector') TypeError: Cannot read properties of undefined (reading 'querySelector')
at HTMLUListElement._handleDropdownKeydown

Proposed changes

const focusedElement = this.dropdownEl.children[this.focusedIndex];
const activatableElement = focusedElement.querySelector('a, button');
->
const focusedElement = this.dropdownEl.children[this.focusedIndex];
const activatableElement = focusedElement?.querySelector('a, button');

activatableElement is null checked but focusedElement was not.

Types of changes

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to change).

Checklist:

  • I have read the CONTRIBUTING document.
  • My commit messages follows the conventional commit format
  • My change requires a change to the documentation, and updated it accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

wuda-io and others added 4 commits December 24, 2024 10:10
…=-1 and Enter key is pressed

This fixes "Cannot read properties of undefined error" when focusedIndex=-1 and the Enter key is pressed. Added the '?' operator .

Cannot read properties of undefined (reading 'querySelector')
TypeError: Cannot read properties of undefined (reading 'querySelector')
    at HTMLUListElement._handleDropdownKeydown
@wuda-io wuda-io self-requested a review February 24, 2025 09:33
wuda-io
wuda-io previously approved these changes Feb 24, 2025
@wuda-io wuda-io changed the base branch from main to v2-dev February 24, 2025 09:34
@wuda-io wuda-io dismissed their stale review February 24, 2025 09:34

The base branch was changed.

@wuda-io wuda-io merged commit b4173fc into materializecss:v2-dev Feb 24, 2025
1 check failed
@HIRANO-Satoshi HIRANO-Satoshi deleted the patch-2 branch February 24, 2025 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants