bem-components
bem-components copied to clipboard
select: Error in case of empty items array
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 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 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 can send a PR which will explicitly throw an error in such case?