bem-components icon indicating copy to clipboard operation
bem-components copied to clipboard

select: Error in case of empty items array

Open tormozz48 opened this issue 9 years ago • 3 comments

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

_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'

tormozz48 avatar Apr 10 '15 19:04 tormozz48

@tormozz48 What do you expect when try to use select without options? HTML spec for native select tag says that it must contain at least one option element.

tadatuta avatar Apr 10 '15 20:04 tadatuta

@tadatuta I think that this should be a problem of my app business logic, but not a block. As for me, the piece of code which was given has not any validations for empty options set case.

tormozz48 avatar Apr 11 '15 09:04 tormozz48

@tormozz48 can send a PR which will explicitly throw an error in such case?

narqo avatar Apr 29 '15 13:04 narqo