bem / bem/bem-components

select: Error in case of empty items array

Open
#1,457 3 comments 0 reactions 0 assignees View on GitHub
bug JS ready
Dominant language
JavaScript
Stars
330
Forks
88
PR merge metrics
No merged PRs in 30d

Description

Hello all. I found some strange code in select block which gives me error in case of empty select item array on select click.

``` js
_hoverCheckedOrFirstItem : function() { // NOTE: may be it should be moved to menu
(this._getCheckedItems()[0] || this._menu.getItems()[0])
.setMod('hovered');
},
```

It is simple to understand that in case of empty array this._menu.getItems()[0] will gives error with message: 'Uncaught TypeError: Cannot read property 'setMod' of undefined'

Contributor guide

Open the contributing guide

Research direction

Start in the select block at _hoverCheckedOrFirstItem and reproduce the error by clicking a select with an empty item array. Trace the item lookup and existing select behavior to determine the intended empty-state handling. Done means the click no longer throws the reported TypeError; the payload names no file or test to run.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.